思路:手動設(shè)置cap的寬高栗弟,然后保存的時候設(shè)置圖片質(zhì)量即可
import cv2
import time
if __name__ == '__main__':
#2代表的是攝像頭設(shè)備號,可以通過ls -al /dev/ | grep video 進(jìn)行查看,可能多個攝像頭需要哪個自行選擇
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()