Ask Your Question
0

VideoCapture with grayscale camera

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

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

2 answers

Sort by » oldest newest most voted
0

answered 2019-10-06 16:35:57 -0600

I'm also using ELP bw camera and setting the fourcc "MJPG" was the key for me, before that I could not set the fps. An addition to achieve high fps at higher resolutions, one may use: camera.set(cv2.CAP_PROP_CONVERT_RGB, 0) which will cause the v4l2 backend (be sure to compile opencv with v4l2 support enable and libv4l disabled) to skip the conversion from mjpeg to RGB. This will leave you with an unnusable buffer but now you can do: frame = cv2.imdecode(frame, cv2.IMREAD_GRAYSCALE); opposite to imdecode(frame, cv2.IMREAD_COLOR); that happens inside v4l2 and cv2.IMREAD_GRAYSCALE is twice as fast.

edit flag offensive delete link more

Comments

Forgot to mention two things:

  • With imdecode being done outside the VideoCapture one can now multithread it
  • I'm using opencv 3.4.7
interlandi gravatar imageinterlandi ( 2019-10-12 10:38:44 -0600 )edit
0

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

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

Question Tools

2 followers

Stats

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

Seen: 6,768 times

Last updated: May 05 '18