OpenCV2
https://www.geeksforgeeks.org/opencv-python-tutorial/
- 视频采集
python
import cv2
currentframe = 0
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
cv2.imshow('frame', frame)
# 隔多少帧保存一张图片
if currentframe % 10 == 0:
cv2.imwrite(f'{TEMP_PATH}/cap/{int(time.time() * 1000)}.png', frame)
currentframe += 1
# 退出
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
- 视频处理(处理帧+加文字)
pthon
import cv2
currentframe = 0
cap = cv2.VideoCapture(0)
while cap.isOpened():
ret, frame = cap.read()
frame = cv2.rectangle(frame, (frame.size, frame.size), (frame.size - 80, frame.size - 30), (246, 64, 65), 1)
cv2.putText(frame,
'this is a demo test',
(50, 50),
cv2.FONT_HERSHEY_PLAIN, 1,
(0, 255, 255),
2,
cv2.LINE_4)
cv2.imshow('frame', frame)
# 隔多少帧保存一张图片
if currentframe % 101 == 0:
cv2.imwrite(f'{TEMP_PATH}/cap/{int(time.time() * 1000)}.png', frame)
currentframe += 1
# 退出
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()