39 lines
808 B
Python
39 lines
808 B
Python
import cv2
|
|
# import numpy as np
|
|
import time
|
|
|
|
cap = cv2.VideoCapture(6)
|
|
|
|
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280) # 宽
|
|
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720) # 高
|
|
|
|
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
|
|
|
fourcc = cv2.VideoWriter_fourcc(*'MP4V') # 'XVID', 'MJPG', 'MP4V' 等
|
|
out = cv2.VideoWriter('video/output_720p.mp4', fourcc, 20.0, (frame_width, frame_height))
|
|
|
|
i = 0
|
|
|
|
time.sleep(1)
|
|
|
|
while True:
|
|
# 逐帧捕获
|
|
ret, frame = cap.read()
|
|
|
|
if not ret:
|
|
print("读取摄像头画面失败")
|
|
break
|
|
|
|
if i <= 5:
|
|
i = i+1
|
|
continue
|
|
|
|
cv2.imshow('camera', frame)
|
|
out.write(frame)
|
|
if cv2.waitKey(5) & 0xFF == ord('q'):
|
|
break
|
|
|
|
cap.release()
|
|
out.release()
|
|
cv2.destroyAllWindows() |