为什么框架的宽度/高度不总是固定的? [英] Why does the frame width / height not always get set?

查看:83
本文介绍了为什么框架的宽度/高度不总是固定的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们问如何设置框架的高度/宽度有很多问题和相应的答案.下面是一个小样本:

There is a huge number of questions and corresponding answers of people asking how to set the frame height / width. A small sample below:

  • Unable to change frame height, width in OpenCV
  • OpenCV (via python) on Linux: Set frame width/height?
  • Setting frame size of QuickCam Pro 3000 with OpenCV?
  • Increasing camera capture resolution in OpenCV

我知道OpenCV有时会在设置框架高度/宽度时遇到问题.就我而言,我可以将宽度/高度的范围设置为最大640 x512.相机的驱动程序由制造商提供(即不是v4l2或类似的东西).我可以提供什么调试信息,或者如何帮助他们理解为什么不能设置更高的宽度/框架.驱动程序和OpenCV都存在问题吗?

I get it OpenCV has issues sometimes with setting frame height / width. In my case I can set a range of widths/heights up to 640 x 512. The drivers for the camera are provided by the manufacturer (i.e. not v4l2 or something similar). What debugging information can I provide or how can I help them understand why I can't set higher widths / frames. Is it a problem with the drivers, with OpenCV with both?

import cv2
c = cv2.VideoCapture(1)
c.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1280)
c.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 1024)

我正在使用Ubuntu 14.04,并在Python中使用OpenCV 2.4.8.

I'm using Ubuntu 14.04 and using OpenCV 2.4.8 in Python.

我发现了此问题,其中包含一个已接受的 answer 建议我应该能够使其正常运行.我不知道该怎么做:

I found this question which has an accepted answer suggesting that I should be able to make it work. I don't know how to do this part:

您可以做的是研究相机驱动程序,打补丁给OpenCV,然后将其发送到code.opencv.org.这样,别人就会喜欢您的工作,就像您喜欢别人的工作一样.

What you can do is to investigate your camera driver, make a patch to OpenCV and send it to code.opencv.org. This way others will enjoy your work, the same way you enjoy other's.

推荐答案

您可以在显示前尝试调整每个框架的大小,请参见下面的代码.

You could try resizing each frame before displaying, please see code below.

确定缩放比例


scale_percent = 40 # percent of original size
width = int(img.shape[1] * scale_percent / 100) 
height = int(img.shape[0] * scale_percent / 100) 
dim = (width, height) 

在显示之前,请使用cv2.resize应用所需的缩放比例.

Apply desired scaling using the cv2.resize, before displaying.


# resize output window
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) 

#show resized frame
cv2.imshow("base_img", resized)

希望这会有所帮助. :)

Hope this helps. :)

这篇关于为什么框架的宽度/高度不总是固定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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