思路:手动设置cap的宽高,然后保存的时候设置图片质量即可
import cv2
import time
if __name__ == '__main__':
#2代表的是摄像头设备号,可以通过ls -al /dev/ | grep video 进行查看,可能多个摄像头需要哪个自行选择
cap = cv2.VideoCapture(2)
# cap.open(0, cv2.CAP_DSHOW);
r1 = cap.set(3, 3264)#2592
print('r1 = ', r1)
r2 = cap.set(4, 2448)#1944
print('r2 = ', r2)
print(cap.get(cv2.CAP_PROP_FPS))
cv2.namedWindow('img', 0)
while True:
ret, img = cap.read()
print(img.shape)
cv2.imshow('img', img)
if cv2.waitKey(0) == ord('s'):
#IMWRITE_JPEG_QUALITY 0-100 IMWRITE_PNG_COMPRESSION 0-9
cv2.imwrite(str(time.time()) + '.jpg', img, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
cv2.destroyAllWindows()
cap.release()
网友评论