將資料夾內的圖片變成影片讀取 - jenhaoyang/ml_blog GitHub Wiki

import cv2
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')

video = cv2.VideoCapture("path/to/image/%06d.jpg",cv2.CAP_IMAGES) #%06d 代表每一張圖片的名稱都是六位數字(左邊補0到六位數)


plt.ion()
fig = plt.figure()
ax1 = fig.add_subplot(111, aspect='equal')

while True:
    success, frame = video.read()
    print("try")
    if success:   
        print("good")
        ax1.imshow(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
        fig.canvas.flush_events()
        plt.draw()

參考:
https://stackoverflow.com/a/49119696