- Mastering OpenCV 4 with Python
- Alberto Fernández Villán
- 203字
- 2021-07-02 12:07:17
Saving camera frames
This previous example can be easily modified to add a useful functionality. Imagine that you want to save some frames to disk when something interesting happens. In the following example, read_camera_capture.py, we are going to add this functionality. When the C key is pressed on the keyboard, we save the current frame to disk. We save both the BGR and the grayscale frames. The code that performs this functionality is shown here:
# Press c on keyboard to save current frame
if cv2.waitKey(20) & 0xFF == ord('c'):
frame_name = "camera_frame_{}.png".format(frame_index)
gray_frame_name = "grayscale_camera_frame_{}.png".format(frame_index)
cv2.imwrite(frame_name, frame)
cv2.imwrite(gray_frame_name, gray_frame)
frame_index += 1
ord('c') returns the value representing the c character using eight bits. Additionally, the cv2.waitKey() value is bitwise AND using the & operator with 0xFF to get only its last eight bits. Therefore, we can perform a comparison between these two 8-bit values. When the C key is pressed, we build the names for both frames. Then, we save the two images to disk. Finally, frame_index is incremented so that it's ready for the next frame to be saved. Check out read_camera_capture.py to see the full code of this script.
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- Building Mapping Applications with QGIS
- PHP+MySQL+Dreamweaver動態網站開發實例教程
- Learning Network Forensics
- 高級語言程序設計(C語言版):基于計算思維能力培養
- 基于Struts、Hibernate、Spring架構的Web應用開發
- Keras深度學習實戰
- Instant Lucene.NET
- Swift 4從零到精通iOS開發
- OpenCV 3 Blueprints
- App Inventor 2 Essentials
- UI設計基礎培訓教程(全彩版)
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動化處理
- Python繪圖指南:分形與數據可視化(全彩)
- Raspberry Pi開發實戰