Ask Your Question

OpenCV On Raspberry Pi2: Camera Resolution

asked 2016-03-30 12:46:15 -0500

djme gravatar image

Hi Folks, I asked this question a few days ago on the Raspberry Pi forums but have yet to receive a reply so I am hoping that there might be more expertise on the OpenCV forums to help.

I recently compiled/installed opencv 3.1 on my RPi2 and it works just fine. I had to do a bit of searching to find out how to activate the pi camera to get OpenCV to see it (by basically entering "sudo modprobe bcm2835-v4l2" into the terminal) but the only limitation I now have is that OpenCV commands to modify the camera resolution do not work. The camera is works perfectly fine with OpenCV but the resolution remains fixed at 640x480 despite attempts to change it with OpenCV code (the resolution can not be increased or even decreased).

For example:

std::cout<<cap.get(cv::CAP_PROP_FRAME_WIDTH)<<std::endl; //output: 640
cap.set(cv::CAP_PROP_FRAME_WIDTH, 1080); //does not work
std::cout<<cap.get(cv::CAP_PROP_FRAME_WIDTH)<<std::endl; //output is still 640

Does anyone know how to get the camera/V4L driver to respond to OpenCV calls to change the camera resolution? The camera has a "CSi" interface and can be viewed on Amazon:

Thanks, Djme.

edit retag flag offensive close merge delete


Hi Djme, If possible can you please share how did you enable pi cam to be used inside opencv, I know about raspicam and all but wanted to know is there a direct way. Thanks a lot for your answer :)

abhi0329 gravatar imageabhi0329 ( 2016-10-11 02:59:52 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2016-03-31 07:17:42 -0500

kbarni gravatar image

First, 1080 pixel wide image isn't standard, maybe that causes problems. Try 1280 or 1920 (and set both width and height).

Do you have libv4l-dev installed? Without this library I had problems changing camera resolution in OpenCV.

If this doesn't help, you can try the Raspicam library (, it provides an OpenCV interface using the native mmal library. I tested it and it supports setting resolutions

edit flag offensive delete link more



Thanks kbami. I set the image width as 1920 and the image height as 1080 and this worked fine!

djme gravatar imagedjme ( 2016-04-03 08:55:12 -0500 )edit

answered 2018-07-08 22:49:25 -0500

jordan314 gravatar image

For me, I had to hard-code DEFAULT_V4L_WIDTH and DEFAULT_V4L_HEIGHT and recompile OpenCV to get higher resolutions due to a bug in OpenCV.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2016-03-30 12:46:15 -0500

Seen: 1,274 times

Last updated: Jul 08 '18