先前经常去网上找,现在干脆放博客了,这样我以后测试直接进入我的博客copy即可
摄像头的代码:
import cv2 cap = cv2.VideoCapture(0) while True: ret,frame = cap.read() cv2.imshow('frame',frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
视频文件的代码:
import cv2 video_file="your file" cap = cv2.VideoCapture(video_file) while True: ret,frame = cap.read() cv2.imshow('frame',frame) if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()