March 2019
Intermediate to advanced
532 pages
13h 2m
English
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 ...