Source code for rofunc.devices.zed.playback

import os.path
import cv2
import rofunc as rf

saving_cnt = 0


[docs]def playback(filepath): import pyzed.sl as sl global saving_cnt print("Reading SVO file: {0}".format(filepath)) root_path = filepath.split('.')[0] input_type = sl.InputType() input_type.set_from_svo_file(filepath) init = sl.InitParameters(input_t=input_type, svo_real_time_mode=False) cam = sl.Camera() status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit() runtime = sl.RuntimeParameters() mat = sl.Mat() key = '' print(" Save the current image: s") print(" Quit the video reading: q\n") while key != 113: # for 'q' key err = cam.grab(runtime) if err == sl.ERROR_CODE.SUCCESS: cam.retrieve_image(mat) cv2.imshow("ZED", mat.get_data()) key = cv2.waitKey(1) saving_image(root_path, key, mat) else: key = cv2.waitKey(1) cv2.destroyAllWindows() print_camera_information(cam) cam.close() print("\nFINISH")
[docs]def saving_image(root_path, key, mat): import pyzed.sl as sl global saving_cnt if key == 115: img = sl.ERROR_CODE.FAILURE while img != sl.ERROR_CODE.SUCCESS: saving_img_dir = root_path + '_saving_img' rf.oslab.create_dir(saving_img_dir) filepath = os.path.join(saving_img_dir, '{}.png'.format(saving_cnt)) img = mat.write(filepath) print("Saving image {}.png : {}".format(saving_cnt, repr(img))) if img == sl.ERROR_CODE.SUCCESS: saving_cnt += 1 break else: print("Help: you must enter the filepath + filename + PNG extension.")