Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV (via python) on Linux: Set frame width/height?

I'm using openCV via python on linux (ubuntu 12.04), and I have a logitech c920 from which I'd like to grab images. Cheese is able to grab frames up to really high resolutions, but whenever I try to use openCV, I only get 640x480 images. I have tried:

import cv
cam = cv.CaptureFromCAM(-1)
cv.SetCaptureProperty(cam,cv.CV_CAP_PROP_FRAME_WIDTH,1920)
cv.SetCaptureProperty(cam,cv.CV_CAP_PROP_FRAME_WIDTH,1080)

but this yields output of "0" after each of the last two lines, and when I subsequently grab a frame via:

image = cv.QueryFrame(cam)

The resulting image is still 640x480.

I've tried installing what seemed to be related tools via (outside of python):

sudo apt-get install libv4l-dev v4l-utils qv4l2 v4l2ucp

and I can indeed apparently manipulate the camera's settings (again, outside of python) via:

v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=1
v4l2-ctl --set-parm=30

and observe that:

v4l2-ctl -V

indeed suggests that something has been changed:

Format Video Capture:
    Width/Height   : 1920/1080
    Pixel Format   : 'H264'
    Field          : None
    Bytes per Line : 3840
    Size Image     : 4147200
    Colorspace     : sRGB

But when I pop into the python shell, the above code behaves exactly the same as before (printing zeros when trying to set the properties and obtaining an image that is 640x480).

Being able to bump up the resolution of the capture is pretty mission critical for me, so I'd greatly appreciate any pointers anyone can provide.

like image 737
Mike Lawrence Avatar asked Jul 17 '12 12:07

Mike Lawrence


Video Answer


1 Answers

From the docs,

The function cvSetCaptureProperty sets the specified property of video capturing. Currently the function supports only video files: CV_CAP_PROP_POS_MSEC, CV_CAP_PROP_POS_FRAMES, CV_CAP_PROP_POS_AVI_RATIO .

NB This function currently does nothing when using the latest CVS download on linux with FFMPEG (the function contents are hidden if 0 is used and returned).

like image 199
Babu Avatar answered Oct 24 '22 08:10

Babu