简体   繁体   English

无法使用opencv获得我想要的分辨率

[英]Can't get the resolution I want with opencv

import cv2
import numpy as np
cap = cv2.VideoCapture(1)
cap.set(3,1920)
cap.set(4,1080)

while(1):
    _,frame = cap.read()
    cv2.imshow("capture", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        cv2.imwrite("save.jpg", frame)
        break
cap.release()
cv2.destroyAllWindows()

When I set the resolution to 1920*1080, I get the save.jpg with 1920*1080. 当我将分辨率设置为1920 * 1080时,将获得1920 * 1080的save.jpg。 But I get save .jpg with 1280*720 when I set the resolution to 1280*1024. 但是当我将分辨率设置为1280 * 1024时,我得到的jpg为1280 * 720。 Is this the problem with opencv or the camera? 这是opencv或相机的问题吗? Any suggestions? Thanks very much! 有什么建议吗?非常感谢!

1920x1080 has aspect ratio of 16:9, when you change the resolution OpenCV preserved the aspect ratio, hence 1280x720, which also has aspect ratio 16:9. 1920x1080的纵横比为16:9,当您更改分辨率时,OpenCV保留了纵横比,因此1280x720的纵横比也为16:9。

If you are desperate to get 1280x1024, I'd recommend you capture 1920x1080 and then crop the necessary part from the middle. 如果您急于获得1280x1024,我建议您捕获1920x1080,然后从中间裁剪出必要的部分。

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

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