Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

opencv VideoCapture.set greyscale?

Tags:

opencv

I would avoid to convert each frame taken by video camera with cvtColor(frame, image, CV_RGB2GRAY);
Is there anyway to set VideoCapture to get directly in greyscale?

Example:

VideoCapture cap(0);

cap.set(CV_CAP_PROP_FRAME_WIDTH,420);
cap.set(CV_CAP_PROP_FRAME_HEIGHT,340);
cap.set(CV_CAP_GREYSCALE,1); //< ???
like image 632
dynamic Avatar asked Jun 22 '12 15:06

dynamic


1 Answers

If your camera supports YUV420 then you could just take the Y channel: http://en.wikipedia.org/wiki/YUV

How to do that is well explained here: Access to each separate channel in OpenCV

Warning: the Y channel might not be the first Mat you get with split() so you should do an imshow() of all of them separately and chose the one that looks like the "real" gray image. The others will just be waaaay out of contrast so it'll be obvious. For me it was the second mat.

Usually, any camera should be able to do YUV420 since sending frames directly in RGB is slower so YUV is pretty much used by nearly every camera. :)

like image 116
Void Avatar answered Jan 02 '23 16:01

Void