From 2c5c86149cc1f5866d30b905ec5bcd483f5c783d Mon Sep 17 00:00:00 2001 From: Joe Dong Date: Fri, 17 May 2024 16:32:05 +0800 Subject: [PATCH] Remove unused file --- examples/plot_imu_and_image_ts.py | 73 ----------- examples/save_imu_and_image_ts.py | 193 ------------------------------ 2 files changed, 266 deletions(-) delete mode 100644 examples/plot_imu_and_image_ts.py delete mode 100644 examples/save_imu_and_image_ts.py diff --git a/examples/plot_imu_and_image_ts.py b/examples/plot_imu_and_image_ts.py deleted file mode 100644 index b65d34c..0000000 --- a/examples/plot_imu_and_image_ts.py +++ /dev/null @@ -1,73 +0,0 @@ -import pandas as pd -import matplotlib.pyplot as plt - -def plot_data(gyro_csv, accel_csv, rgb_csv, depth_csv, sensor_type): - # Load the CSV data into DataFrames - gyro_data = pd.read_csv(gyro_csv) - accel_data = pd.read_csv(accel_csv) - rgb_data = pd.read_csv(rgb_csv) - depth_data = pd.read_csv(depth_csv) - - # Set up the plot with six subplots: timestamps, timestamp differences, global timestamps for all sensors - fig, ax = plt.subplots(5, 1, figsize=(12, 24), sharex=True) - - # Plot timestamps for gyro and accelerometer - ax[0].plot(gyro_data['Index'], gyro_data['Timestamp'], label='Gyro Timestamp', color='blue') - ax[0].plot(accel_data['Index'], accel_data['Timestamp'], label='Accelerometer Timestamp', color='orange') - ax[0].set_title('IMU Timestamps') - ax[0].set_ylabel('Timestamp (us)') - ax[0].legend() - - # Plot timestamps for RGB and depth sensors - ax[1].plot(rgb_data['Index'], rgb_data['Timestamp'], label='RGB Timestamp', color='red') - ax[1].plot(depth_data['Index'], depth_data['Timestamp'], label='Depth Timestamp', color='green') - ax[1].set_title('Camera Timestamps') - ax[1].set_ylabel('Timestamp (us)') - ax[1].legend() - - # Plot timestamp differences for all sensors if the column exists - if 'Timestamp Difference' in gyro_data.columns: - ax[2].plot(gyro_data['Index'], gyro_data['Timestamp Difference'], label='Gyro Timestamp Difference', color='purple') - ax[2].plot(accel_data['Index'], accel_data['Timestamp Difference'], label='Accelerometer Timestamp Difference', color='magenta') - ax[2].plot(rgb_data['Index'], rgb_data['Timestamp Difference'], label='RGB Timestamp Difference', color='black') - ax[2].plot(depth_data['Index'], depth_data['Timestamp Difference'], label='Depth Timestamp Difference', color='grey') - ax[2].set_title('Timestamp Differences') - ax[2].set_ylabel('Timestamp Difference (us)') - ax[2].legend() - - # Plot global timestamps for all sensors if the column exists - if 'Global Timestamp' in gyro_data.columns: - ax[3].plot(gyro_data['Index'], gyro_data['Global Timestamp'], label='Gyro Global Timestamp', color='cyan') - ax[3].plot(accel_data['Index'], accel_data['Global Timestamp'], label='Accelerometer Global Timestamp', color='yellow') - ax[3].plot(rgb_data['Index'], rgb_data['Global Timestamp'], label='RGB Global Timestamp', color='brown') - ax[3].plot(depth_data['Index'], depth_data['Global Timestamp'], label='Depth Global Timestamp', color='orange') - ax[3].set_title('Global Timestamps') - ax[3].set_ylabel('Global Timestamp (us)') - ax[3].legend() - - # Plot global timestamp differences for all sensors if the column exists - if 'Global Timestamp Difference' in gyro_data.columns: - ax[4].plot(gyro_data['Index'], gyro_data['Global Timestamp Difference'], label='Gyro Global Timestamp Difference', color='orange') - ax[4].plot(accel_data['Index'], accel_data['Global Timestamp Difference'], label='Accelerometer Global Timestamp Difference', color='brown') - ax[4].plot(rgb_data['Index'], rgb_data['Global Timestamp Difference'], label='RGB Global Timestamp Difference', color='purple') - ax[4].plot(depth_data['Index'], depth_data['Global Timestamp Difference'], label='Depth Global Timestamp Difference', color='magenta') - ax[4].set_title('Global Timestamp Differences') - ax[4].set_ylabel('Global Timestamp Difference (us)') - ax[4].legend() - - # Adjust layout and show plot - plt.tight_layout() - plt.show() - -def main(): - # Path to the gyro, accel, RGB, and depth CSV files - gyro_csv = 'gyro_data.csv' - accel_csv = 'accel_data.csv' - rgb_csv = 'color_data.csv' - depth_csv = 'depth_data.csv' - - # Plot all sensor data - plot_data(gyro_csv, accel_csv, rgb_csv, depth_csv, 'Sensor Data') - -if __name__ == "__main__": - main() diff --git a/examples/save_imu_and_image_ts.py b/examples/save_imu_and_image_ts.py deleted file mode 100644 index 5258f96..0000000 --- a/examples/save_imu_and_image_ts.py +++ /dev/null @@ -1,193 +0,0 @@ -# ****************************************************************************** -# Copyright (c) 2023 Orbbec 3D Technology, Inc -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http:# www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ****************************************************************************** -from pyorbbecsdk import * -import time -from threading import Lock -import csv - -console_lock = Lock() -stop_gyro = False -stop_accel = False -last_gyro_ts = 0 -last_gyro_global_ts = 0 - -last_accel_ts = 0 -last_accel_global_ts = 0 - -gyro_csv_file = open('gyro_data.csv', 'w', newline='') -gyro_writer = csv.writer(gyro_csv_file) -gyro_writer.writerow(['Index', 'Timestamp','Global Timestamp', 'Timestamp Difference', 'Global Timestamp Difference']) - -accel_csv_file = open('accel_data.csv', 'w', newline='') -accel_writer = csv.writer(accel_csv_file) -accel_writer.writerow(['Index', 'Timestamp', 'Global Timestamp','Timestamp Difference', 'Global Timestamp Difference']) - -color_csv_file = open('color_data.csv', 'w', newline='') -color_writer = csv.writer(color_csv_file) -color_writer.writerow(['Index', 'Timestamp', 'Global Timestamp', 'Timestamp Difference', 'Global Timestamp Difference']) - -depth_csv_file = open('depth_data.csv', 'w', newline='') -depth_writer = csv.writer(depth_csv_file) -depth_writer.writerow(['Index', 'Timestamp', 'Global Timestamp', 'Timestamp Difference', 'Global Timestamp Difference']) -last_color_ts = 0 -last_depth_ts = 0 -last_color_global_ts = 0 -last_depth_global_ts = 0 - -def on_new_frame_set_callback(frame: FrameSet): - global last_color_ts, last_depth_ts, last_color_global_ts, last_depth_global_ts - if frame is None: - return - color_frame = frame.get_color_frame() - depth_frame = frame.get_depth_frame() - if color_frame is not None: - timestamp = color_frame.get_timestamp_us() - global_timestamp = color_frame.get_global_timestamp_us() - index = color_frame.get_index() - timestamp_diff = timestamp - last_color_ts if last_color_ts != 0 else 0 - global_timestamp_diff = global_timestamp - last_color_global_ts if last_color_global_ts != 0 else 0 - color_writer.writerow([index, timestamp, global_timestamp, timestamp_diff, global_timestamp_diff]) - last_color_ts = timestamp - last_color_global_ts = global_timestamp - if depth_frame is not None: - timestamp = depth_frame.get_timestamp_us() - global_timestamp = depth_frame.get_global_timestamp_us() - index = depth_frame.get_index() - timestamp_diff = timestamp - last_depth_ts if last_depth_ts != 0 else 0 - global_timestamp_diff = global_timestamp - last_depth_global_ts if last_depth_global_ts != 0 else 0 - depth_writer.writerow([index, timestamp, global_timestamp, timestamp_diff, global_timestamp_diff]) - last_depth_ts = timestamp - last_depth_global_ts = global_timestamp - -def on_gyro_frame_callback(frame: Frame): - if frame is None: - return - global stop_gyro, last_gyro_ts, last_gyro_global_ts - if stop_gyro: - return - gyro_frame: GyroFrame = frame.as_gyro_frame() - if gyro_frame is not None: - timestamp = gyro_frame.get_timestamp_us() - global_timestamp = gyro_frame.get_global_timestamp_us() - index = gyro_frame.get_index() - timestamp_diff = timestamp - last_gyro_ts if last_gyro_ts != 0 else 0 - global_timestamp_diff = global_timestamp - last_gyro_global_ts if last_gyro_global_ts != 0 else 0 - gyro_writer.writerow([index, timestamp, global_timestamp, timestamp_diff, global_timestamp_diff]) - last_gyro_ts = timestamp - last_gyro_global_ts = global_timestamp - -def on_accel_frame_callback(frame: Frame): - if frame is None: - return - global stop_accel, last_accel_ts, last_accel_global_ts - if stop_accel: - return - accel_frame: AccelFrame = frame.as_accel_frame() - if accel_frame is not None: - timestamp = accel_frame.get_timestamp_us() - global_timestamp = accel_frame.get_global_timestamp_us() - index = accel_frame.get_index() - timestamp_diff = timestamp - last_accel_ts if last_accel_ts != 0 else 0 - global_timestamp_diff = global_timestamp - last_accel_global_ts if last_accel_global_ts != 0 else 0 - accel_writer.writerow([index, timestamp,global_timestamp, timestamp_diff, global_timestamp_diff]) - last_accel_ts = timestamp - last_accel_global_ts = global_timestamp - -def main(): - ctx: Context = Context() - device_list: DeviceList = ctx.query_devices() - if device_list.get_count() == 0: - print("No device connected") - gyro_csv_file.close() - accel_csv_file.close() - return - device: Device = device_list.get_device_by_index(0) - sensor_list: SensorList = device.get_sensor_list() - try: - gyro_senor = sensor_list.get_sensor_by_type(OBSensorType.GYRO_SENSOR) - if gyro_senor is None: - print("No gyro sensor") - gyro_csv_file.close() - accel_csv_file.close() - return - gyro_profile_list: StreamProfileList = gyro_senor.get_stream_profile_list() - gyro_profile: StreamProfile = gyro_profile_list.get_stream_profile_by_index(0) - assert gyro_profile is not None - gyro_senor.start(gyro_profile, on_gyro_frame_callback) - gyro_profile = gyro_profile.as_gyro_stream_profile() - print("Gyro profile: sample rate: ", gyro_profile.get_sample_rate()) - print("Gyro profile: full scale range: ", gyro_profile.get_full_scale_range()) - except OBError as e: - print(e) - gyro_csv_file.close() - accel_csv_file.close() - return - try: - accel_sensor = sensor_list.get_sensor_by_type(OBSensorType.ACCEL_SENSOR) - if accel_sensor is None: - print("No accel sensor") - gyro_csv_file.close() - accel_csv_file.close() - return - accel_profile_list: StreamProfileList = accel_sensor.get_stream_profile_list() - accel_profile: StreamProfile = accel_profile_list.get_stream_profile_by_index(0) - assert accel_profile is not None - accel_sensor.start(accel_profile, on_accel_frame_callback) - accel_profile = accel_profile.as_accel_stream_profile() - print("Accel profile: sample rate: ", accel_profile.get_sample_rate()) - print("Accel profile: full scale range: ", accel_profile.get_full_scale_range()) - except OBError as e: - print(e) - gyro_csv_file.close() - accel_csv_file.close() - return - pipeline = Pipeline(device) - config = Config() - - try: - profile_list = pipeline.get_stream_profile_list(OBSensorType.COLOR_SENSOR) - color_profile = profile_list.get_default_video_stream_profile() - config.enable_stream(color_profile) - profile_list = pipeline.get_stream_profile_list(OBSensorType.DEPTH_SENSOR) - depth_profile = profile_list.get_default_video_stream_profile() - config.enable_stream(depth_profile) - except Exception as e: - print(e) - return - - pipeline.start(config, lambda frames: on_new_frame_set_callback(frames)) - pipeline.enable_frame_sync() - - while True: - try: - time.sleep(1.0) - - except KeyboardInterrupt: - # Don't forget to stop the sensor - global stop_accel, stop_gyro - stop_accel = True - stop_gyro = True - time.sleep(0.01) - if gyro_senor is not None: - gyro_senor.stop() - if accel_sensor is not None: - accel_sensor.stop() - gyro_csv_file.close() - accel_csv_file.close() - break - -if __name__ == "__main__": - main()