Python OpenCV访问网络摄像头的最大分辨率 [英] Python OpenCV access webcam maximum resolution

查看:545
本文介绍了Python OpenCV访问网络摄像头的最大分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用导入OpenCV的python代码从网络摄像头获取图像.代码如下:

I am trying to acquire images from my webcam using a python code that imports OpenCV. The code is the following:

import sys
sys.path.append("C:\\opencv\\build\\python\\2.7")
import cv2
import cv2.cv as cv
import time

# Set resolution
cap = cv2.VideoCapture(0)
print "Frame default resolution: (" + str(cap.get(cv.CV_CAP_PROP_FRAME_WIDTH)) + "; " + str(cap.get(cv.CV_CAP_PROP_FRAME_HEIGHT)) + ")"
cap.set(cv.CV_CAP_PROP_FRAME_WIDTH, 800)
cap.set(cv.CV_CAP_PROP_FRAME_HEIGHT, 600)
print "Frame resolution set to: (" + str(cap.get(cv.CV_CAP_PROP_FRAME_WIDTH)) + "; " + str(cap.get(cv.CV_CAP_PROP_FRAME_HEIGHT)) + ")"

# Acquire frame
capture = cv.CreateCameraCapture(0)
img = cv.QueryFrame(capture)

该代码工作正常,但相机"的默认分辨率为640x480,而我的代码似乎只能设置低于该分辨率的值.例如,我可以将图像大小设置为320x240,但不能将其更改为800x600.我没有出现任何错误:当我尝试将分辨率设置为更高的值时,只需将分辨率设置为默认值(640x480).

The code works fine, except that the Camera default resolution is 640x480, and my code seems to be able to set only resolution values lower than that. For example, I can set the image size to 320x240, but I can't change it to 800x600. I have no error appearing: simply the resolution is set to the default one (640x480) as I try to set it to higher values.

我正在使用的相机(没有其他网络摄像头连接到计算机)是QuickCam V-UBK45:使用Logitech提供的软件,我能够以全分辨率(1280x960)和所有中间分辨率拍照(例如800x600).

The camera I am using (no other webcam is connected to the computer) is the QuickCam V-UBK45: with the software provided by Logitech, I am able to take pictures at full resolution (1280x960) and at all intermediate ones (e.g. 800x600).

因此,硬件支持这些帧大小,但是我的代码无法访问它们.

Therefore, those frame sizes are supported from the hardware, but my code can't access them.

有人知道我能做什么吗?

Does anyone know what I can do?

推荐答案

我使用了不同的分辨率来设置

I used the different resolutions to set image resolution from List of common resolutions by looping over

def set_res(cap, x,y):
    cap.set(cv.CV_CAP_PROP_FRAME_WIDTH, int(x))
    cap.set(cv.CV_CAP_PROP_FRAME_HEIGHT, int(y))
    return str(cap.get(cv.CV_CAP_PROP_FRAME_WIDTH)),str(cap.get(cv.CV_CAP_PROP_FRAME_HEIGHT))

似乎OpenCV或我的相机仅允许某些分辨率.

It seems that OpenCV or my camera allows only certain resolutions.

  • 160.0 x 120.0

  • 160.0 x 120.0

176.0 x 144.0

176.0 x 144.0

320.0 x 240.0

320.0 x 240.0

352.0 x 288.0

352.0 x 288.0

640.0 x 480.0

640.0 x 480.0

1024.0 x 768.0

1024.0 x 768.0

1280.0 x 1024.0

1280.0 x 1024.0

这篇关于Python OpenCV访问网络摄像头的最大分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆