讀取影片
import cv2
capture = cv2.VideoCapture("test.avi")
if capture.isOpened():
while True:
ret, prev = capture.read()
if ret==True:
cv2.imshow('video', prev)
else:
break
if 0xFF & cv2.waitKey(5) == 27:
break
cv2.destroyAllWindows()
讀取多個影片(Multi Video)
import cv2
import os
def multi_video(path):
vpath = os.listdir(path)
videoName = [path + i for i in vpath]
videoNum = len(videoName)
print(videoName)
print(videoNum)
cap1 = cv2.VideoCapture(videoName[0])
cap2 = cv2.VideoCapture(videoName[1])
cap3 = cv2.VideoCapture(videoName[2])
while True:
_, frame1 = cap1.read()
_, frame2 = cap2.read()
_, frame3 = cap3.read()
reframe1 = cv2.resize(frame1, (360, 240))
reframe2 = cv2.resize(frame2, (360, 240))
reframe3 = cv2.resize(frame3, (360, 240))
cv2.imshow("video1", reframe1)
cv2.imshow("video2", reframe2)
cv2.imshow("video3", reframe3)
k = cv2.waitKey(30)
if k == 27:
break
cap1.release()
cap2.release()
cap3.release()
cv2.destroyAllWindows()
multi_video('./video/')
※查詢其他OpenCV用法如下※
OpenCV應用總整理: 點擊我
留言列表