update dd02 3d viewer v1
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
class CompoundEyeFrameProcessor:
|
||||
"""Convert a raw compound-eye frame into one stitched BGR tactile image."""
|
||||
|
||||
def __init__(self, stitcher):
|
||||
self.stitcher = stitcher
|
||||
|
||||
def process(self, frame):
|
||||
self.stitcher.get_stitch_unit(frame)
|
||||
self.stitcher.extract_tiles()
|
||||
return self.stitcher.stitch_rt_optimized(blend=False)
|
||||
|
||||
|
||||
class SingleCameraFrameProcessor:
|
||||
"""Convert a normal camera frame into one BGR tactile image."""
|
||||
|
||||
def process(self, frame):
|
||||
if frame.ndim == 2:
|
||||
return cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR)
|
||||
if frame.shape[2] == 1:
|
||||
return cv2.cvtColor(frame[:, :, 0], cv2.COLOR_GRAY2BGR)
|
||||
return frame
|
||||
|
||||
|
||||
def create_frame_processor(sensor_type, stitcher=None):
|
||||
sensor_type = (sensor_type or "compound_eye").lower()
|
||||
if sensor_type in ("compound_eye", "compound-eye", "compound"):
|
||||
if stitcher is None:
|
||||
raise ValueError("Compound-eye sensor requires a Stitcher instance.")
|
||||
return CompoundEyeFrameProcessor(stitcher)
|
||||
if sensor_type in ("single_camera", "camera", "mono"):
|
||||
return SingleCameraFrameProcessor()
|
||||
raise ValueError(f"Unsupported sensor type: {sensor_type}")
|
||||
Reference in New Issue
Block a user