官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 垦利县| 凤阳县| 广州市| 丹寨县| 星子县| 奎屯市| 海阳市| 南川市| 新宾| 宁明县| 手游| 扶绥县| 平乡县| 翁源县| 宕昌县| 会理县| 娱乐| 吉林省| 建宁县| 龙泉市| 哈尔滨市| 苍溪县| 吉木乃县| 抚顺县| 安吉县| 黔南| 苍梧县| 姚安县| 盈江县| 涿州市| 东丽区| 开鲁县| 古交市| 凤阳县| 昌吉市| 锡林浩特市| 连平县| 邯郸市| 肥城市| 鄂托克前旗| 永安市|