Result of cvtColor not displaying correctly for Lepoard Imaging USB 3.0 camera
Using the code below, I am getting images from a Leopard Imaging USB 3.0 camera. When I first tested the camera, the images were green. I looked on several forums and found that I needed to convert from Bayer images to BGR images. Now, I get what is in the attached image. Does anyone know what I can do to fix this?
cv::VideoCapture (cam1);
cam1.grab();
cam1.read(data);
....
cv::Mat changed;
cv::Mat bayer16(data.rows, data.cols, CV_16UC1,data.data,data.step);
cv::Mat bayer8 = bayer16.clone();
bayer8.convertTo(bayer8, CV_8UC1, 0.0625);
cv::cvtColor(bayer8, changed, CV_BayerGB2BGR);
imshow("", changed);
An image of what gets displayed image
it is because of the channels, the interpretation of the bits... do you have also some gray part in your displayed image, or is it all?
Yes, there is some gray but, the colors look more washed out. I added a link to the image so that you can see what I mean Image
I suggest you to review the bayer16; data is a Mat with the right nb of channels, and you are forcing it to a CV_16UC1 ... Are you sure that it is OK? Transforming from CV_32FC1 to CV_16UC1 should be a problem... More, then you convert it to CV_8UC1 with a resize factor...
No, I am not sure that this is correct. I found an example where I need to convert from a Bayer image to an RGB or BGR image. With no processing, the images coming from the camera look like this. When I cut down all of that code and just use cv::cvtColor(bayer8, changed, CV_BayerGB2BGR);
I get an error that says: OpenCV Error: Asserion failed (scn == 1 && (dcn == 3 || dcn ==4))
I need to convert that image to BGR. Do you have any suggestions about how to do that?
Verify the channels of received image:
std::cout << data.channels() << std::endl;
(or in debug) what is the number of channels data has?Data has 3 channels
To correct the previous comment: When I cut down all of that code and just use cv::cvtColor(data, changed, CV_BayerGB2BGR); I get the Assertion failed error..Thanks for your help BTW
An update from the vendor: The V034 camera outputs RAW data encapsulated in YUY2 format. Since UVC standard has no RAW image format, we use YUY2 as the wrapper.
Have you seen this? It is a little bit outdated, but that is the idea: use the flag, see if it works.
Yes, I've seen this and it doesn't work either. I've spent the last few days trying everything I can think of. I may have to 1) go back and try everything again 2) try something other than opencv