2017-08-05 97 views
1

當我嘗試使用cv2.imwrite()方法保存圖像時,它將以640x480像素大小保存文件。我的網絡攝像頭是FUll HD(1920×1080像素)。我怎樣才能保存在這個FHD大小的圖片。使用OpenCv保存全高清尺寸的圖像Python

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() 

回答

2
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()