OpenCV2
https://www.geeksforgeeks.org/opencv-python-tutorial/文章来源地址https://www.toymoban.com/news/detail-855726.html
- 视频采集
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()
- 视频处理(处理帧+加文字)
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()
文章来源:https://www.toymoban.com/news/detail-855726.html
到了这里,关于OpenCV2之简单处理视频的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!