Result of cvtColor not displaying correctly for Lepoard Imaging USB 3.0 camera

asked 2015-07-23 13:52:42 -0600

jnj11 gravatar image

updated 2015-07-24 10:47:12 -0600

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

edit retag flag offensive close merge delete

Comments

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?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-24 04:37:41 -0600 )edit

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

jnj11 gravatar imagejnj11 ( 2015-07-24 10:16:02 -0600 )edit

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...

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-27 02:46:36 -0600 )edit

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?

jnj11 gravatar imagejnj11 ( 2015-07-27 08:18:54 -0600 )edit

Verify the channels of received image: std::cout << data.channels() << std::endl; (or in debug) what is the number of channels data has?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-27 09:21:06 -0600 )edit

Data has 3 channels

jnj11 gravatar imagejnj11 ( 2015-07-27 09:41:30 -0600 )edit

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

jnj11 gravatar imagejnj11 ( 2015-07-27 09:44:14 -0600 )edit
1

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.

jnj11 gravatar imagejnj11 ( 2015-07-27 11:48:12 -0600 )edit

Have you seen this? It is a little bit outdated, but that is the idea: use the flag, see if it works.

thdrksdfthmn gravatar imagethdrksdfthmn ( 2015-07-28 02:21:33 -0600 )edit

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

jnj11 gravatar imagejnj11 ( 2015-07-31 15:28:20 -0600 )edit