Ask Your Question

Usb camera resolution problem

asked 2014-11-22 10:47:45 -0500

I'm using logitech c270 cam with opencv 3.0.

The aim is to capture a frame and save it as jpg. It works great, but i can't change frame width/height. It's always 640x480 (tried bigger and smaller sizes). Function VideoCapture.set(CAP_PROP_FRAME_WIDTH, val) always returns false.

Some steps:

  1. Changed the resolution with v4l2-ctl --set-fmt-video, but after launching my program, all settings are gone back to 640x480.
  2. Test the same thing via fswebcam --save -r 1280x960 and finally got image with needed sizes
  3. Checked v4l2-ctl --get-fmt-video. There are correct values

It looks like opencv always sets default resolution and not provides opportunity to change it.

edit retag flag offensive close merge delete


OpenCV only returns false if the used backend lib is not supported/allowed by your camera to change the resolution of the camera. Basically go into debug and report back which cap mechanism is used by OpenCV internally (look for the cap_ something file and gives us the something). Also make sure that you change these settings before grabbing frames or opening the camera.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-11-26 08:09:48 -0500 )edit

Thank you or your answer. Could you please provide a bit more details? What you mean 'go into debug'? Are there any opencv logs or smting like that?

alex-dev gravatar imagealex-dev ( 2014-11-29 02:54:02 -0500 )edit

If you build OpenCV yourself in debug mode and not in release, then you can use the debug files to use your debugger to step into the OpenCV source code. This allows you to see what backend of the VideoCapture is used on your system.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-12-01 02:14:22 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-11-25 04:31:19 -0500

kbarni gravatar image

This might be a problem with OpenCV handling your webcam.

Some hints to solve it:

  • Did you have the dev package of V4L2 installed when you compiled OpenCV? Try to recompile OpenCV from source after installing this package. This should solve the problem
  • OpenCV of V4L2 might not be able to handle resolution changing on your device. This is a much less probable cause, but some time ago there still were some incompatible cameras. In this case you can change the resolution, but it will be hard-coded. Look for the definition of the default resolution in the highgui folder of the sources (DEFAULT_V4L_HEIGHT/WIDTH in cap-v4l.cpp).
edit flag offensive delete link more

Question Tools


Asked: 2014-11-22 10:47:45 -0500

Seen: 2,041 times

Last updated: Nov 25 '14