简体   繁体   English

捕获图片的cv2分辨率

[英]cv2 resolution of captured picture

Hello I have this simple code: 您好,我有这个简单的代码:

from cv2 import *
import time
# initialize the camera


for x in range (10):
    cam = VideoCapture(0)   # 0 -> index of camera
    s,img = cam.read()
    imwrite(str(x) + ".jpg",img) #save image
    time.sleep(3)
    print(x)
    cam.release()

I wonder about two things: - the default resolution of my webcam is higher than resolution that script is saving my picture with? 我想知道以下两件事:-我的网络摄像头的默认分辨率是否高于脚本用来保存图片的分辨率? - is there any command to check max resolution of webcam (I would like to set this res as default output)? -是否有任何命令来检查摄像头的最大分辨率(我想将此分辨率设置为默认输出)?

Actually there is way to check the default resolution of your webcam. 实际上,有一种方法可以检查网络摄像头的默认分辨率。

  • First initiate the webcam using cap = cv2.VideoCapture(0) . 首先使用cap = cv2.VideoCapture(0)启动网络摄像头。
  • Then using the get() method, enter the following and on printing w and h you will get the width and height of your webcam: 然后使用get()方法,输入以下内容,并在打印wh时获得网络摄像头的宽度和高度:

     w = cap.get(cv2.CAP_PROP_FRAME_WIDTH) h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) 

This is in response to your second question. 这是对您的第二个问题的答复。 Yes, you can alter the resolution of your webcam by choosing a width and height of your choice using the following set() method: 是的,您可以使用以下set()方法选择宽度和高度来更改网络摄像头的分辨率:

cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)

Even though you change the width and height, the camera driver maintains an aspect ratio. 即使更改宽度和高度,相机驱动程序仍会保持宽高比。 So you may not always get the exact height/width you expect. 因此,您不一定总能获得所需的确切高度/宽度。

Example: when I set the width and height to be 80 each. 示例:当我将宽度和高度分别设置为80时。 It did not set it. 它没有设置。 It rather set width = 320 and height = 180. Also when I set both to 800 it returned width = 848 and height = 480. 而是将宽度设置为320,高度设置为180。同样,当我将其都设置为800时,它返回的宽度为848,高度为480。

The camera driver this maintains an aspect ratio. 相机驱动程序可保持宽高比。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM