我在 Python3 和 OpenCV 3.1 中为 Odroid C1 上的延时照片编写了一个脚本:
不幸的是,有时来自网络摄像头的图像会混乱:这是一些示例照片。
这是源代码:
import numpy as np
import cv2
import time
import datetime
import sys
cap = cv2.VideoCapture(0) # USB webcam
cap.set(3,2304.0) # Resolution: Width
cap.set(4,1296.0) # Resolution: Height
cap.set(5, 6) #webcam capture FPS
print(str(cap.get(3)),str(cap.get(4)),str(cap.get(5)))
def captureImage():
ret, frame = cap.read()
curr_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
filename = 'littleGarden_'+curr_time +'.jpg'
file_to_save = folder_to_save + filename
cv2.imwrite(file_to_save,frame)
print("File saved ", file_to_save)
ret, frame = cap.read()
while(True):
# Capture frame-by-frame
if cv2.waitKey(1) & 0xFF == ord('q'):
break
captureImage()
time.sleep(delay)
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
作为参考,cap.set() 命令中的第一个参数指的是相机属性的枚举,如下所示:
0. CV_CAP_PROP_POS_MSEC Current position of the video file in milliseconds.
1. CV_CAP_PROP_POS_FRAMES 0-based index of the frame to be decoded/captured next.
2. CV_CAP_PROP_POS_AVI_RATIO Relative position of the video file
3. CV_CAP_PROP_FRAME_WIDTH Width of the frames in the video stream.
4. CV_CAP_PROP_FRAME_HEIGHT Height of the frames in the video stream.
5. CV_CAP_PROP_FPS Frame rate.
有什么办法可以解决吗?