- Mastering OpenCV 4 with Python
- Alberto Fernández Villán
- 209字
- 2021-07-02 12:07:18
Using the properties – playing a video backwards
To see how we can use the aforementioned properties, we are going to understand the read_video_file_backwards.py script, which uses some of these properties to load a video and output it backwards, showing the last frame of the video first and so on. We are going to use the following properties:
- cv2.CAP_PROP_FRAME_COUNT: This property provides the total number of frames
- cv2.CAP_PROP_POS_FRAMES: This property provides the current frame
The first step is to get the index of the last frame:
# We get the index of the last frame of the video file
frame_index = capture.get(cv2.CAP_PROP_FRAME_COUNT) - 1
Therefore, we set the current frame to read to this position:
# We set the current frame position
capture.set(cv2.CAP_PROP_POS_FRAMES, frame_index)
This way, we can read this frame as usual:
# Capture frame-by-frame from the video file
ret, frame = capture.read()
Finally, we decrement the index in order to read the next frame from the video file:
# Decrement the index to read next frame
frame_index = frame_index - 1
The full code is provided in the read_video_file_backwards.py script. This script can be easily modified to save the resulting video playing backwards (not only showing it). This script is proposed in the Question section.
- Deploying Node.js
- Learning Docker
- Serverless架構
- Swift細致入門與最佳實踐
- Swift Playgrounds少兒趣編程
- Learning OpenStack Networking(Neutron)(Second Edition)
- 西門子S7-200 SMART PLC編程從入門到實踐
- 編程與類型系統
- 響應式Web設計:HTML5和CSS3實戰(第2版)
- Illustrator CS6設計與應用任務教程
- Go語言入門經典
- HTML5移動Web開發
- Offer來了:Java面試核心知識點精講(框架篇)
- Learning Apache Thrift
- Hands-On Game Development Patterns with Unity 2019