Ask Your Question
-1

How to capture in GRAYSCALE directly from source

asked 2016-03-11 02:21:05 -0500

inckka gravatar image

updated 2016-03-11 02:46:35 -0500

I'm capturing web cam using open cv and I'd like to get direct Grayscale image from source. Below shows a sample code that I'm using for capturing video feed. Found this reference however cant see any gray scale codes. http://docs.opencv.org/2.4/modules/hi...

capture = cvCreateCameraCapture(0);
if(!capture)
    printf("Video Load Error\n");

cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 640.00);
cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 480.00);

Secondly if anyone knows how to use "CV_CAP_PROP_CONVERT_RGB" with C-API. Please let me.

p.s: I'm aware that C - API is deprecated. However I'm maintaining an old project, so need to deal with it.

edit retag flag offensive close merge delete

Comments

setting CV_CAP_PROP_CONVERT_RGB to false won't give you a grayscale image (misassumption), but whatever native format the cam delivers (probably some sort of yuv)

also, please do not try to repair your c-legacy, or build something on top of that. you''re only producing more technical debt

berak gravatar imageberak ( 2016-03-11 02:37:08 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-03-11 22:41:00 -0500

gseif gravatar image

It's actually not possible to read in directly grayscale from a webcam. Most webcams will read in by default either YUV or YCrCb. As berak mentioned, 'CV_CAP_PROP_CONVERT_RGB' allows you to set whether or not you want this to be converted to RGB right away. So to get grayscale from a webcam, you'll have to use the 'cvtColor' function like so:


cvtColor(original, gray, CV_BGR2GRAY);


You'll have to do this for every incoming frame. Hope this helps!

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-03-11 02:21:05 -0500

Seen: 4,583 times

Last updated: Mar 11 '16