def record(cam, runtime, mat): vid = sl.ERROR_CODE.FAILURE out = False while vid != sl.ERROR_CODE.SUCCESS and not out: filepath = input("Enter filepath name: ") filepath = 'C:/Users/Zber/Desktop/SavedData/video.svo' record_param = sl.RecordingParameters(filepath) vid = cam.enable_recording(record_param) print(repr(vid)) if vid == sl.ERROR_CODE.SUCCESS: print("Recording started...") out = True print("Hit spacebar to stop recording: ") key = False while key != 32: # for spacebar err = cam.grab(runtime) if err == sl.ERROR_CODE.SUCCESS: cam.retrieve_image(mat) cv2.imshow("ZED", mat.get_data()) key = cv2.waitKey(5) else: print( "Help: you must enter the filepath + filename + SVO extension." ) print("Recording not started.") cam.disable_recording() print("Recording finished.") cv2.destroyAllWindows()
def main(): if not sys.argv or len(sys.argv) != 2: exit(1) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD720 init.camera_fps = 30 init.depth_mode = sl.DEPTH_MODE.ULTRA # Use ULTRA depth mode init.coordinate_units = sl.UNIT.METER init.depth_minimum_distance = 0.15 status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) path_output = sys.argv[1] recording_param = sl.RecordingParameters(path_output, sl.SVO_COMPRESSION_MODE.LOSSLESS) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) runtime = sl.RuntimeParameters() print("SVO is Recording, use Ctrl-C to stop.") frames_recorded = 0 while True: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS: frames_recorded += 1 print("Frame count: " + str(frames_recorded), end="\r")
def main(): signal.signal(signal.SIGINT, interrupt_handler) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.VGA init.camera_fps = 100 init.depth_mode = sl.DEPTH_MODE.ULTRA init.coordinate_units = sl.UNIT.METER init.coordinate_system = sl.COORDINATE_SYSTEM.RIGHT_HANDED_Y_UP status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print('Camera.open failed') print(repr(status)) exit(1) path_output = "Datalog/Receiver/RXDATA/{0}.svo".format( datetime.now().strftime('%m-%d-%Y_%H:%M:%S')) recording_param = sl.RecordingParameters(path_output, sl.SVO_COMPRESSION_MODE.H264) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print('Enable Recording failed') print(repr(err)) exit(1) runtime = sl.RuntimeParameters() while True: cam.grab(runtime)
def main(): if not sys.argv or len(sys.argv) != 2: print( "Only the path of the output SVO file should be passed as argument." ) exit(1) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD720 init.depth_mode = sl.DEPTH_MODE.NONE status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) path_output = sys.argv[1] recording_param = sl.RecordingParameters(path_output, sl.SVO_COMPRESSION_MODE.H264) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) runtime = sl.RuntimeParameters() print("SVO is Recording, use Ctrl-C to stop.") frames_recorded = 0 while True: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS: frames_recorded += 1 print("Frame count: " + str(frames_recorded), end="\r")
def main(): if not sys.argv or len(sys.argv) != 2: exit(1) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD720 init.camera_fps = 30 init.depth_mode = sl.DEPTH_MODE.ULTRA # Use ULTRA depth mode init.coordinate_units = sl.UNIT.METER init.depth_minimum_distance = 0.15 gpsd.connect() packet = gpsd.get_current() print(" Mode: " + str(packet.mode)) cont = 0 status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) ######## while True: t = 0 t0 = time.time() name = datetime.datetime.now() path_output = name.strftime("%d_%m_%Y__%H_%M_") + str(cont) + ".svo" path_output = sys.argv[1] + path_output recording_param = sl.RecordingParameters( path_output, sl.SVO_COMPRESSION_MODE.LOSSLESS) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) file = open(path_output.split('.')[0] + ".txt", 'w') runtime = sl.RuntimeParameters() while t < 60: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS: file.write( str(packet.lat) + " " + str(packet.lon) + " " + str(packet.track) + "\n") print( str(packet.lat) + " " + str(packet.lon) + " " + str(packet.track) + "\n") t = time.time() - t0 print(str(t)) file.close() cont = cont + 1
def main(): if not sys.argv or len(sys.argv) != 2: print( "Only the path of the output SVO file should be passed as argument." ) exit(1) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD1080 # max fps 30 # init.camera_resolution = sl.RESOLUTION.HD720 # max fps 60 # init.camera_resolution = sl.RESOLUTION.VGA # max fps 100 init.depth_stabilization = False # to improve computational performance init.depth_mode = sl.DEPTH_MODE.ULTRA # Use ULTRA depth mode init.coordinate_units = sl.UNIT.MILLIMETER # Use millimeter units (for depth measurements) runtime = sl.RuntimeParameters() runtime.sensing_mode = sl.SENSING_MODE.FILL img = sl.Mat() status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) print('If you want to Recording, press "r"') while True: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS: cam.retrieve_image(img, sl.VIEW.LEFT) cv2.imshow('result', img.get_data()) key = cv2.waitKey(20) if key == 114: break if key == 114: path_output = sys.argv[1] # filename.svo 형식으로 작성 recording_param = sl.RecordingParameters( path_output, sl.SVO_COMPRESSION_MODE.LOSSLESS) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(err)) exit(1) print('SVO file is Recording, use Ctrl-C to stop') frames_recorded = 0 while True: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS: cam.retrieve_image(img, sl.VIEW.LEFT) cv2.imshow('result', img.get_data()) key_video = cv2.waitKey(20) frames_recorded += 1 print("Frame count: " + str(frames_recorded), end="\r")
def main(): if not sys.argv or len(sys.argv) != 2: exit(1) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD720 init.camera_fps = 30 init.depth_mode = sl.DEPTH_MODE.ULTRA # Use ULTRA depth mode init.coordinate_units = sl.UNIT.METER init.depth_minimum_distance = 0.15 gpsd.connect() packet = gpsd.get_current() print(" Mode: " + str(packet.mode)) cont = 0 status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) path_output = sys.argv[1] recording_param = sl.RecordingParameters(path_output, sl.SVO_COMPRESSION_MODE.LOSSLESS) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) file = open(path_output.split('.')[0] + ".txt", 'w') runtime = sl.RuntimeParameters() print("SVO is Recording, use q to stop.") frames_recorded = 0 while True: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS: frames_recorded += 1 file.write( str(packet.lat) + " " + str(packet.lon) + " " + str(packet.track) + "\n") # print("Frame count: " + str(frames_recorded), end="\r") print( str(packet.lat) + " " + str(packet.lon) + " " + str(packet.track) + "\n") if cv2.waitKey(20) & 0xFF == ord('q'): break file.close()
def startRecording(self): if self.recordEvent.is_set() == False: self.recordEvent.set() self.startTime = datetime.datetime.now() self.startUnixTime = time.time() startTimeString = self.startTime.strftime("ZED_%Y-%m-%d-%H-%M-%S") self.filename = startTimeString + ".svo" filepath = os.path.join(self.dir, self.filename) print("ZED Camera - recording to " + filepath) recording_param = sl.RecordingParameters( filepath, sl.SVO_COMPRESSION_MODE.H264) self.cam.enable_recording(recording_param)
def main(): if not sys.argv or len(sys.argv) != 1: exit(1) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD720 init.camera_fps = 30 init.depth_mode = sl.DEPTH_MODE.ULTRA # Use ULTRA depth mode init.coordinate_units = sl.UNIT.METER init.depth_minimum_distance = 0.15 cont = 0 if not cam.is_opened(): print("Opening ZED Camera...") status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status) + 'Camara no inicializada') #exit(1) GPIO.setmode(GPIO.BCM) GPIO.setup(input_pin, GPIO.IN) value = GPIO.input(input_pin) while value: t = 0 t0 = time.time() name = datetime.datetime.now() path_output = name.strftime("%d_%m_%Y__%H_%M_") + ".svo" recording_param = sl.RecordingParameters( path_output, sl.SVO_COMPRESSION_MODE.LOSSLESS) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(status) + 'Error al crear el archivo') #exit(1) runtime = sl.RuntimeParameters() while (t < 180) and (value): if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS: print("grabando \n") t = time.time() - t0 #print(str(t)) value = GPIO.input(input_pin) print(value) cont = cont + 1 if not value: cmd = shlex.split("shutdown -h now") subprocess.call(cmd)
def main(): print("Running...") init = sl.InitParameters() cam = sl.Camera() if not cam.is_opened(): print("Opening ZED Camera...") status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit() runtime = sl.RuntimeParameters() mat = sl.Mat() print_camera_information(cam) print_help() key = '' while key != 113: # for 'q' key err = cam.grab(runtime) if err == sl.ERROR_CODE.SUCCESS: # cam.retrieve_image(mat, sl.VIEW.LEFT) cam.retrieve_image(mat, sl.VIEW.LEFT) cv2.imshow("ZED", mat.get_data()) filepath = 'C:/Users/Zber/Desktop/SavedData/video.svo' record_param = sl.RecordingParameters(filepath) vid = cam.enable_recording(record_param) while key != 32: # for spacebar err = cam.grab(runtime) if err == sl.ERROR_CODE.SUCCESS: cam.retrieve_image(mat) cv2.imshow("ZED", mat.get_data()) key = cv2.waitKey(5) # tt = cam.get_timestamp(sl.TIME_REFERENCE.IMAGE).get_microseconds() tt = cam.get_timestamp(sl.TIME_REFERENCE.IMAGE).get_microseconds() print(tt) cam.disable_recording() print("Recording finished.") # key = cv2.waitKey(5) # settings(key, cam, runtime, mat) else: key = cv2.waitKey(5) cv2.destroyAllWindows() cam.close() print("\nFINISH")
def main(): if not sys.argv or len(sys.argv) != 2: exit(1) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD720 init.camera_fps = 30 init.depth_mode = sl.DEPTH_MODE.ULTRA # Use ULTRA depth mode init.coordinate_units = sl.UNIT.METER init.depth_minimum_distance = 0.15 cont = 0 status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) while True: t = 0 t0 = time.time() name = datetime.datetime.now() path_output = name.strftime("%d_%m_%Y__%H_%M_") + str(cont) + ".svo" path_output = sys.argv[1] + path_output recording_param = sl.RecordingParameters( path_output, sl.SVO_COMPRESSION_MODE.LOSSLESS) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) runtime = sl.RuntimeParameters() while t < 180: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS: print("grabando \n") t = time.time() - t0 print(str(t)) cont = cont + 1
def main(): if not sys.argv or len(sys.argv) != 2: print("Only the path of the output SVO file should be passed as argument.") exit(1) init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD720 init.camera_resolution = sl.RESOLUTION.HD1080 # init.depth_mode = sl.DEPTH_MODE.NONE status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) path_output = sys.argv[1] + "/" + get_last_file_index(sys.argv[1]) +".svo" # 檔案大小差距很大 # recording_param = sl.RecordingParameters(path_output, sl.SVO_COMPRESSION_MODE.LOSSLESS) # 影像損失程度不高 recording_param = sl.RecordingParameters(path_output, sl.SVO_COMPRESSION_MODE.H264) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) runtime = sl.RuntimeParameters() mat = sl.Mat() print("SVO is Recording, use Ctrl-C to stop.") frames_recorded = 0 while True: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS : frames_recorded += 1 cam.retrieve_image(mat) cv2.imshow("RGB", mat.get_data()) cam.retrieve_image(mat, sl.VIEW.DEPTH) cv2.imshow("Dep", mat.get_data()) key = cv2.waitKey(1) print("Frame count: " + str(frames_recorded), end="\r")
WindowName = "ZED Camera" view_window = cv2.namedWindow(WindowName, cv2.WINDOW_KEEPRATIO) cv2.moveWindow(WindowName, 300, 150) # cv2.setWindowProperty(WindowName, cv2.WND_PROP_TOPMOST, 1) for i in range(start_record_index, end_record_index): # time_start = time.time() # preparing data config json file file_prefix = prefix.format(i) update_data_config(datacard_config, file_prefix, file_basepath) cv2.waitKey(20) # camera record setting video_filepath = os.path.join(file_basepath, file_prefix + '.svo') record_param = sl.RecordingParameters(video_filepath) # preparing mmwave sensor CLIport, Dataport = send_cli() status = cam.open(init) # sensor start CLIport.write(('sensorStart' + '\n').encode()) # cv2.waitKey(5) sensor_start = time.time() # camera recording cam.enable_recording(record_param) video_start = time.time() while time.time() - video_start <= record_time: err = cam.grab(runtime)
def main(): if not sys.argv or len(sys.argv) != 2: print("Only the path of the output SVO file should be passed as argument.") exit(1) path = 'svo_recordings/' try: os.makedirs(path) except FileExistsError: # directory already exists pass init = sl.InitParameters() init.camera_resolution = sl.RESOLUTION.HD720 init.depth_mode = sl.DEPTH_MODE.PERFORMANCE init.coordinate_units = sl.UNIT.MILLIMETER status = cam.open(init) if status != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) path_output = path + sys.argv[1] recording_param = sl.RecordingParameters(path_output, sl.SVO_COMPRESSION_MODE.H264) err = cam.enable_recording(recording_param) if err != sl.ERROR_CODE.SUCCESS: print(repr(status)) exit(1) runtime = sl.RuntimeParameters() runtime.sensing_mode = sl.SENSING_MODE.FILL print("SVO is Recording, use Ctrl-C to stop.") frames_recorded = 0 # Declare your sl.Mat matrices image_size = cam.get_camera_information().camera_resolution image_size.width = image_size.width /2 image_size.height = image_size.height /2 image_zed = sl.Mat(image_size.width, image_size.height, sl.MAT_TYPE.U8_C4) depth_image_zed = sl.Mat(image_size.width, image_size.height, sl.MAT_TYPE.U8_C4) # Used to store the sensors timestamp to know if the sensors_data is a new one or not ts_handler = TimestampHandler() sensors_data = sl.SensorsData() rows_list = [] key = ' ' while key != 113: if cam.grab(runtime) == sl.ERROR_CODE.SUCCESS : frames_recorded += 1 # retrieve the current sensors sensors_data # Depending on your Camera model or its firmware, differents sensors are presents. # They do not run at the same rate: Therefore, to do not miss samples we iterate as fast as we can and compare timestamp to know when a sensors_data is a new one # NOTE: There is no need to acquire images with grab() function. Sensors sensors_data are running in a separated internal capture thread. if cam.get_sensors_data(sensors_data, sl.TIME_REFERENCE.CURRENT) == sl.ERROR_CODE.SUCCESS : # Check if the data has been updated since the last time # IMU is the sensor with the highest rate if ts_handler.is_new(sensors_data.get_imu_data()): print("Sample " + str(frames_recorded)) print(" - IMU:") # Filtered orientation quaternion quaternion = sensors_data.get_imu_data().get_pose().get_orientation().get() print(" \t Orientation: [ Ox: {0}, Oy: {1}, Oz {2}, Ow: {3} ]".format(quaternion[0], quaternion[1], quaternion[2], quaternion[3])) # linear acceleration linear_acceleration = sensors_data.get_imu_data().get_linear_acceleration() print(" \t Acceleration: [ {0} {1} {2} ] [m/sec^2]".format(linear_acceleration[0], linear_acceleration[1], linear_acceleration[2])) # angular velocities angular_velocity = sensors_data.get_imu_data().get_angular_velocity() print(" \t Angular Velocities: [ {0} {1} {2} ] [deg/sec]".format(angular_velocity[0], angular_velocity[1], angular_velocity[2])) dict1 = {'frame':frames_recorded, 'time':sensors_data.get_imu_data().timestamp.get_microseconds(), 'Ox':quaternion[0] ,'Oy':quaternion[1], 'Oz':quaternion[2], 'Ow':quaternion[3], 'Ax':linear_acceleration[0], 'Ay':linear_acceleration[1], 'Az':linear_acceleration[2], 'AVx':angular_velocity[0], 'AVy':angular_velocity[1], 'AVz':angular_velocity[2]} rows_list.append(dict1) cam.retrieve_image(image_zed, sl.VIEW.LEFT, sl.MEM.CPU, image_size) cam.retrieve_image(depth_image_zed, sl.VIEW.DEPTH, sl.MEM.CPU, image_size) # To recover data from sl.Mat to use it with opencv, use the get_data() method # It returns a numpy array that can be used as a matrix with opencv image_ocv = image_zed.get_data() depth_image_ocv = depth_image_zed.get_data() cv2.imshow("Image", image_ocv) cv2.imshow("Depth", depth_image_ocv) key = cv2.waitKey(1) print("Frame count: " + str(frames_recorded), end="\r") df = pd.DataFrame(rows_list) df.to_csv(path_output[:-4]+'.csv') cv2.destroyAllWindows() cam.disable_recording() cam.close() print("\nFINISH")