本文介绍了Linux上的OpenCV(通过python):设置框架的宽度/高度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在linux(ubuntu 12.04)上通过python使用openCV,我有一个logitech c920,我想从中获取图像. Cheese可以抓取高达真正高分辨率的帧,但是每当我尝试使用openCV时,我只会得到640x480的图像.我已经尝试过:

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)

但是在最后两行中的每一行之后,当我随后通过以下方式抓取一帧时,输出为"0":

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)

生成的图像仍为640x480.

The resulting image is still 640x480.

我尝试通过(在python之外)安装似乎相关的工具:

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

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

而且我确实可以通过以下方式操纵相机的设置(同样,在python之外):

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

并注意:

v4l2-ctl -V

确实暗示某些更改:

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

但是当我跳入python shell时,以上代码的行为与以前完全相同(尝试设置属性并获取640x480的图像时打印零).

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.

推荐答案

我遇到了与您相同的问题.最终进入OpenCV源,并更改了modules/highgui/src/cap_v4l.cpp行245-246中的默认参数,并重建了项目.

I had the same problem as you. Ended up going into the OpenCV source and changing the default parameters in modules/highgui/src/cap_v4l.cpp, lines 245-246 and rebuilding the project.

#define DEFAULT_V4L_WIDTH  1920
#define DEFAULT_V4L_HEIGHT 1080

这是针对OpenCV 2.4.8

This is for OpenCV 2.4.8

这篇关于Linux上的OpenCV(通过python):设置框架的宽度/高度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 04:31