Ask Your Question
0

VideoCapture with grayscale camera

asked 2018-05-05 14:15:21 -0500

Hello I´m begginer on OpenCv I have a grayscale video camera ELP-USBFHD01M-SFV B/W, 120fps at 480 pixels with picture format MJPEG and YUY2 I need to capture an image almost at 60 FPS. One of my jobs is detect circles using HougCircles, using cvtColor(frame, edges, COLOR_BGR2GRAY) to convert the image to grayscale. I´m loosing a lot of time adquiring and suposed RGB image and converting it to grayscale. Anybody knows how to adquire the image directly in grayscale?

Thanks for your answers

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2018-05-11 14:33:58 -0500

tooFar gravatar image

Some of the ELP cameras that are b/w are not true B/W (monochrome) and have Bayer sensors still and are, as you've noticed, sending in RGB. I'm curious if the camera is actually in the proper FPS/Mode. Have you verified that it is? The "get" functions report some incorrect information sometimes it seems. I have noticed that my ELP camera refuses to change to MJPG with 640x480. As a result I am unable to set my FPS to the 120fps needed for my application and it was defaulting to the 30fps for YUY2 at that resolution. I can however set the stream to MJPG when using the resolution 320x240, and setting the Frames Per Second to 120. Have you tried that resolution yet? 800x600 lets me get mjpg @ 60fps After I set the values and the camera actual comes online I've printed the "fourcc" to see if it is in YUY2 or MJPG. (Opencv 3 and Python 3 on windows)

camera = cv2.VideoCapture(cv2.CAP_DSHOW + 0)
camera.set(cv2.CAP_PROP_FPS, 120)
camera.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M','J','P','G'))
camera.set(cv2.CAP_PROP_SETTINGS, 1)
camera.set(cv2.CAP_PROP_EXPOSURE, -12)
camera.set(cv2.CAP_PROP_FRAME_WIDTH, 320)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
return_value, image = camera.read()
cv2.imshow('Camera View',image)
print(decode_fourcc(camera.get(6)))

   while True:
       return_value, image = camera.read()
       cv2.imshow('Camera View',image)

        if cv2.waitKey(1) == 27:
            break

For me this shows mjpg for 320x240 @ 120fps but YUY2 for 640x480, even though in AMCAP MJPG w/ 640x480@120 works and the specs state it should as well. I've tried moving declaration orders in the code, initializing the camera up before setting properties, setting properties before initialization, setting before&after, setting multiple times after other properties, and every other strange thing as a "just in case." I can't get 640x480 to work no matter what.

I've also found that camera.get(cv2.CAP_PROP_FPS) shows the 120 fps when the camera is in YUY2 at 640x480 (an impossible FPS for the camera in that mode), but I'm using a PWM light and can very much tell the difference in 120fps, 60fps and 30fps that the camera is actually running.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

2 followers

Stats

Asked: 2018-05-05 14:15:21 -0500

Seen: 581 times

Last updated: May 05 '18