Use cv_image: http://dlib.net/imaging.html#cv_image
@davisking Does not work.
../../src/Detector.cpp:266:59: required from here
../../src/dlib/dnn/core.h:2277:65: error: ‘const class dlib::cv_image<dlib::rgb_pixel>’ has no member named ‘begin’
std::vector<output_label_type> results(std::distance(data.begin(), data.end()));
^
../../src/dlib/dnn/core.h:2277:65: error: ‘const class dlib::cv_image<dlib::rgb_pixel>’ has no member named ‘end’
../../src/dlib/dnn/core.h:2279:33: error: ‘const class dlib::cv_image<dlib::rgb_pixel>’ has no member named ‘begin’
auto i = data.begin();
^
dlib::matrix<dlib::rgb_pixel> img(dlib::mat(dlib::cv_image<dlib::rgb_pixel>(cvRgbImage)));
works but it is long way to go.
cv_image<bgr_pixel> image(mat);
matrix<rgb_pixel> matrix;
assign_image(matrix, image);
******** FATAL ERROR DETECTED ********
Error detected at line 36.
Error detected in file /home/server/dlib/dlib/../dlib/opencv/cv_image.h.
Error detected in function dlib::cv_image
Failing expression was img.depth() == cv::DataType
The pixel type you gave doesn't match pixel used by the open cv Mat object.
img.depth(): 0
img.cv::DataType
img.channels(): 1
img.pixel_traits
Aborted (core dumped)
There is a double copy in the following code mentioned above. Can we form a matrix object from open cv mat(in rgb already) to dlib matrix without incurring the memory copy here in assign_image?
This situation is similar to the way CV Mat objects can be created by setting the data pointer and the row & col detalils directly without incurring data copy.
cv_image
matrix
assign_image(matrix, image);
There is only one memory copy in this code:
cv_image<bgr_pixel> image(open_cv_mat);
matrix<rgb_pixel> matrix;
assign_image(matrix, image); // memory copy happens here and only here
If you want to make a matrix that aliases the memory of mat then do this:
cv_image<bgr_pixel> image(open_cv_mat);
some_function_that_takes_dlib_matrix(mat(image))
dlib::mat() converts basically anything into a dlib matrix expression that aliases the memory of whatever you pass it. It does not copy anything.
Yo're correct about one memory copy. I didnt post our code where there is a copy from our data structur to cv::mat first and then an assign_image as indicated above.
I will check your suggestion and post the results.
Thanks.
It gives error dlib::cv_image not a member of dlib
Most helpful comment