-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update saving to svo file using video converter
- Loading branch information
Alex Overbeek
committed
Jan 31, 2025
1 parent
963c6e4
commit b9ba05e
Showing
12 changed files
with
129 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
from utils.logger import Log | ||
import os,sys | ||
import torch | ||
import numpy as np | ||
import random | ||
import cv2 | ||
import time | ||
from hydra import initialize, compose | ||
from hydra.core.global_hydra import GlobalHydra | ||
import imageio | ||
|
||
import threading | ||
import queue | ||
from utils.sam2prty import Sam2PromptType | ||
sys.path.insert(0, os.getcwd()) | ||
|
||
|
||
# Initialize GPU settings | ||
if torch.cuda.get_device_properties(0).major >= 8: | ||
torch.backends.cuda.matmul.allow_tf32 = True | ||
torch.backends.cudnn.allow_tf32 = True | ||
torch.backends.cudnn.benchmark = True | ||
torch.autocast(device_type="cuda", dtype=torch.bfloat16).__enter__() | ||
|
||
|
||
from wrappers.pyzed_wrapper import pyzed_wrapper as pw | ||
from utils.utils import * | ||
from scripts.utils.depth_utils import ( | ||
depth_refinement_RANSAC_plane_fitting, | ||
) | ||
|
||
|
||
def run(cfg, sam2_prompt: Sam2PromptType, record: bool = False, svo_file: str = None) -> None: | ||
depth_refinement_enabled = cfg.depth.refine_depth | ||
caption_queue = queue.Queue() | ||
|
||
Log.info("Initializing the pipeline...", tag="pipeline_init") | ||
|
||
# Build needed models | ||
Log.info("Building models...", tag="building_models") | ||
# try: | ||
# sam2_predictor, grounding_dino_model = build_models(cfg) | ||
# Log.info("Models successfully built and loaded.", tag="model_building") | ||
# except Exception as e: | ||
# Log.error(f"Failed to build models: {e}", tag="model_build_error") | ||
# return | ||
|
||
# Initialize ZED camera: Live Mode or SVO Playback Mode | ||
Log.info("Initializing ZED camera...", tag="zed_camera_init") | ||
wrapper = pw.Wrapper("svo" if svo_file else cfg.camera.connection_type) | ||
|
||
# If using playback, set SVO file path | ||
if svo_file: | ||
wrapper.input_parameters.svo_input_filename = svo_file | ||
|
||
try: | ||
wrapper.open_input_source() | ||
Log.info("ZED camera initialized.", tag="camera_init") | ||
except Exception as e: | ||
Log.error(f"Failed to initialize ZED camera: {e}", tag="camera_init_error") | ||
return | ||
|
||
# Start recording if enabled | ||
if record: | ||
wrapper.start_recording("./output/output.svo") | ||
Log.info("Recording started.", tag="recording") | ||
|
||
wrapper.start_stream() | ||
Log.info('Camera stream started.', tag = "camera_stream") | ||
|
||
framecount = 0 | ||
|
||
try: | ||
while True: | ||
ts = time.time() | ||
|
||
if wrapper.retrieve(is_image=True, is_measure=True): | ||
# Extract images | ||
left_image = wrapper.output_image | ||
depth_map = wrapper.output_measure | ||
|
||
norm_depth_map = cv2.normalize(depth_map, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8) | ||
left_image_rgb = cv2.cvtColor(left_image, cv2.COLOR_RGBA2RGB) | ||
|
||
# # Display and save | ||
# cv2.imshow("ZED Left", left_image_rgb) | ||
# cv2.imshow("Depth Map", norm_depth_map) | ||
|
||
# cv2.imwrite(f"output/frame_{framecount}.png", left_image_rgb) | ||
# cv2.imwrite(f"output/depth_{framecount}.png", norm_depth_map) | ||
|
||
if framecount > 100: | ||
break | ||
|
||
framecount += 1 | ||
|
||
except Exception as e: | ||
Log.error(f"An error occurred: {e}", tag="runtime_error") | ||
|
||
finally: | ||
# Stop recording if enabled | ||
if record: | ||
wrapper.stop_recording() | ||
Log.info("Recording stopped.", tag="recording_stop") | ||
|
||
Log.info("Shutting down and closing stream...", tag='Close_stream') | ||
wrapper.stop_stream() | ||
wrapper.close_input_source() | ||
cv2.destroyAllWindows() | ||
|
||
if __name__ == "__main__": | ||
# Ensure GlobalHydra is properly cleared before initializing | ||
if GlobalHydra.instance().is_initialized(): | ||
GlobalHydra.instance().clear() | ||
|
||
with initialize(config_path="../configurations"): | ||
cfg = compose(config_name="sam2_zed_small") | ||
sam2_prompt = Sam2PromptType('g_dino_bbox', user_caption='keyboard') | ||
|
||
# Run after Hydra is fully initialized | ||
run(cfg, sam2_prompt, record=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters