hi, I am new to dlib and so when load image didn't worked out for other than .bmp image so I have tried to use OpenCV to read that and then convert it back to the matrix as well as array2d format of dlib but it throws an exception saying "The pixel type you gave doesn't match pixel used by the open cv Mat object."
I have written the code as:
Mat src = imread(argv[1],CV_LOAD_IMAGE_COLOR);
cv_image<rgb_pixel> img(src);
save_bmp(img,"input.bmp");
and similarly I have tried after reading an bmp image read from dlib and then do some binarisation operations in opencv using toMat but same problem faced when I am converting it back to dlib format..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You probably need to use bgr_pixel instead of rgb_pixel. Also, if you use
cmake to compile (as shown here http://dlib.net/compile.html) your project
it will automatically link in libjpeg and libpng which will allow you to
load and save jpeg and png files with dlib.
Cheers,
Davis
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks Davis , but it didn't worked with bgr_pixel also and then I tried the other way which works for me. Which is I have changed the line 3 of my code as :
assign_image(img, cv_image<bgr_pixel>(src));
Now I am getting into another problem of grayscale conversion using same assign_image.
The code I have tried is:
I have checked the rot_img is good but assign_pixel line is giving some kind of compile time errors which I am not getting is what for. and the compile time errors are:
Error 1 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi&&dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 2 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi&&dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 3 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi&&dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 4 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const unsigned char &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 5 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha&&dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 6 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha&&dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 7 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha&&dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 8 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const unsigned char &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 9 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb&&dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 10 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb&&dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 11 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb&&dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 12 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const unsigned char &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 13 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::grayscale&&dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 14 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::grayscale&&dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 15 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::grayscale&&dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 16 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi&&dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 17 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha&&dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 18 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb&&dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 19 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::grayscale&&dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 20 error C2782: 'enable_if_c<dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P &,const P &)' : template parameter 'P' is ambiguous d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
One more help I need from you I want to try for morphological operations but I am not been able to define a structuring element for the operation. If possible give me an example for a simple morphological operation in dlib.
And when I have given a image for the auto_threshold_image but its giving error:
And when I have given same image for the equalize_histogram it worked out good. I didn't underatnd why is it so?.... The code I have used this:
You just do it like this:
unsigned char structuring_element[3][3];
// then assign each part of structuring_element to either 0 or 255 (i.e.
on_pixel or off_pixel) depending on the kind of morphology operation you
want to do.
I worked it out. I changed the edge_image Pixel type to unsigned char and then it worked out ,i.e., build successfully with intellisense error like png attached before). But I didn't understand why edge_image was failed to be recognised as an binary image when in is_binary_image() of binary_dilation. I obtained the edge_image as a result from edge finding of an binarised Image.
One more thing the one I have posted before for cv_image that thing I have solved like this:
assign_image(img, cv_image<bgr_pixel>(src));
as bgr_pixel also didn't worked for me.
And now I am getting error in rgb to grayscale conversion using same.
hi,I can't figure out how to convert my OpenCV image into dlib-processable img.
http://dlib.net/face_landmark_detection_ex.cpp.html sp(img,dets[j])
Cheers
Last edit: tjusxh 2014-10-20
You can convert an OpenCV image into a dlib compatible image by doing
something like this:
cv_image<bgr_pixel> img(your_opencv_image);
Then you use img in dlib functions. See also:
http://dlib.net/imaging.html#cv_image
Cheers,
Davis
it done!
Thanks
hi, I am new to dlib and so when load image didn't worked out for other than .bmp image so I have tried to use OpenCV to read that and then convert it back to the matrix as well as array2d format of dlib but it throws an exception saying "The pixel type you gave doesn't match pixel used by the open cv Mat object."
I have written the code as:
Mat src = imread(argv[1],CV_LOAD_IMAGE_COLOR);
cv_image<rgb_pixel> img(src);
save_bmp(img,"input.bmp");
and similarly I have tried after reading an bmp image read from dlib and then do some binarisation operations in opencv using toMat but same problem faced when I am converting it back to dlib format..
You probably need to use bgr_pixel instead of rgb_pixel. Also, if you use
cmake to compile (as shown here http://dlib.net/compile.html) your project
it will automatically link in libjpeg and libpng which will allow you to
load and save jpeg and png files with dlib.
Cheers,
Davis
Thanks Davis , but it didn't worked with bgr_pixel also and then I tried the other way which works for me. Which is I have changed the line 3 of my code as :
assign_image(img, cv_image<bgr_pixel>(src));
Now I am getting into another problem of grayscale conversion using same assign_image.
The code I have tried is:
I have checked the rot_img is good but assign_pixel line is giving some kind of compile time errors which I am not getting is what for. and the compile time errors are:
Error 1 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi&&dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 2 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi&&dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 3 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi&&dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 4 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const unsigned char &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 5 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha&&dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 6 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha&&dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 7 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha&&dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 8 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const unsigned char &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 9 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb&&dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 10 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb&&dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 11 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb&&dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 12 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const unsigned char &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 13 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::grayscale&&dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 14 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::grayscale&&dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 15 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::grayscale&&dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 16 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::hsi&&dlib::pixel_traits<P>::hsi>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 17 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb_alpha&&dlib::pixel_traits<P>::rgb_alpha>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 18 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::rgb&&dlib::pixel_traits<P>::rgb>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 19 error C2893: Failed to specialize function template 'enable_if_c<dlib::pixel_traits<P>::grayscale&&dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P1 &,const P2 &)' d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
Error 20 error C2782: 'enable_if_c<dlib::pixel_traits<P>::grayscale>::type dlib::assign_pixel_helpers::assign(P &,const P &)' : template parameter 'P' is ambiguous d:\dlib\dlib-18.11\dlib\pixel.h 966 1 DLib_check
One more help I need from you I want to try for morphological operations but I am not been able to define a structuring element for the operation. If possible give me an example for a simple morphological operation in dlib.
And when I have given a image for the auto_threshold_image but its giving error:
And when I have given same image for the equalize_histogram it worked out good. I didn't underatnd why is it so?.... The code I have used this:
You just do it like this:
unsigned char structuring_element[3][3];
// then assign each part of structuring_element to either 0 or 255 (i.e.
on_pixel or off_pixel) depending on the kind of morphology operation you
want to do.
Yeah, there is a bug in the auto_threshold_image() function. It's fixed in
the source repository though so if you grab a new copy of the file (
https://github.com/davisking/dlib/blob/master/dlib/image_transforms/thresholding.h)
it will work fine.
Cheers,
Davis
Last edit: Davis 2014-11-26
Thanks Davis, auto_thresold_image worked like a charm but I am still facing the issue in morphological operations. I tried this :
where edge_image is of
and still I am getting some kind of error. Have a look and tell me if I am doing wrong anywhere.
That should work fine. What error do you get when you try it?
Thanks for the quick reply, Davis.
I worked it out. I changed the edge_image Pixel type to unsigned char and then it worked out ,i.e., build successfully with intellisense error like png attached before). But I didn't understand why edge_image was failed to be recognised as an binary image when in is_binary_image() of binary_dilation. I obtained the edge_image as a result from edge finding of an binarised Image.
One more thing the one I have posted before for cv_image that thing I have solved like this:
as bgr_pixel also didn't worked for me.
And now I am getting error in rgb to grayscale conversion using same.
What is rot_img?
Last edit: Davis 2014-11-27
It should work then. That is, if you have this in your code:
Then there should be no problem. What is the smallest program you can write that reproduces the error?
Last edit: Davis 2014-11-27
I have checked it same way but still I am getting error check the .png I have attached with post before for more details.
The .png isn't very useful. I need to see the exact code you are compiling.
ok... then Check Test.cpp attached document file for example code where I am getting error.
Ah, sorry, I wasn't paying enough attention. You need to call assign_image(), not assign_pixel(). assign_pixel is for assigning pixels, not images.
Ah, what a stupidity... Well thanks for help...
No problem :)