使用 Python OpenCv 逆向播放视频
OpenCv 全稱是開源電腦視覺,使用此程式庫,我們可以在圖像和視訊上執行不同的操作。
OpenCV 的應用領域
- 臉部辨識系統
- 動作追蹤
- 人工神經網路
- 深度神經網路
- 視訊串流等。
在 Windows 上進行安裝,我們可以使用此命令列
pip install opencv-python
在 Linux 上 −
sudo apt-get install python-opencv
為了完成我們的任務,我們必須遵循以下步驟 −
Step 1: We import OpenCv library named cv2. Step 2: Take a video as input data. Step 3: First we break the video into a number of frames and store all these frames in a list. Step 4: When we are getting all the frames then we shall apply iteration method. Step 5: Here we apply iteration for reversing the list. Step 6: Use the reverse() method for reversing the order of the frames in the list.
範例程式碼
import cv2 # Grab the current frame. my_check , vid = cap.read() # use counter variable for # Counting frames counter = 0 check = True frame_list = [] while(check == True): cv2.imwrite("frame%d.jpg" %counter , vid) check , vid = cap.read() frame_list.append(vid) # increment the counter by 1 counter += 1 frame_list.pop() # looping in the List of frames. for frame in frame_list: # show the frame. cv2.imshow("Frame" , frame) if cv2.waitKey(25) and 0xFF == ord("q"): break cap.release() # close any open windows cv2.destroyAllWindows() frame_list.reverse() for frame in frame_list: cv2.imshow("Frame" , frame) if cv2.waitKey(25) and 0xFF == ord("q"): break cap.release() cv2.destroyAllWindows()
輸出
广告