gpt4 book ai didi

python-3.x - 使用 OpenCv Python 以全高清大小保存图像

转载 作者:太空宇宙 更新时间:2023-11-03 22:09:24 24 4
gpt4 key购买 nike

当我尝试使用 cv2.imwrite() 方法保存图像时,它保存了一个 640x480 像素大小的文件。我的网络摄像头是全高清(1920×1080 像素)。如何以这种全高清尺寸保存图片。

import numpy as np
import cv2

cap = cv2.VideoCapture(0)

while(True):
# Capture frame-by-frame
ret, frame = cap.read()

# Our operations on the frame come here
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Display the resulting frame
cv2.imshow('frame', frame)
cv2.imwrite('a.jpg',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

最佳答案

import numpy as np
import cv2

cap = cv2.VideoCapture(0)
cap.set(3, 1920)
cap.set(4, 1080)
cap.set(6, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))

while(True):
# Capture frame-by-frame
ret, frame = cap.read()

# Our operations on the frame come here
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Display the resulting frame
cv2.imshow('frame', frame)
cv2.imwrite('a.jpg',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

关于python-3.x - 使用 OpenCv Python 以全高清大小保存图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45523990/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com