stereo first commit

This commit is contained in:
unknown
2026-01-03 11:13:44 +08:00
parent a3cd52a301
commit d5c73670fe
7 changed files with 214 additions and 14 deletions
+1 -1
View File
@@ -111,7 +111,7 @@ class Stitcher:
img_corr = self.__correct_edge_bloom(img_src)
self.__detect_nonblack_regions(img_corr,show = show)
return len(self.boxes)
return len(self.boxes), self.boxes
# return self.boxes
+15 -13
View File
@@ -131,7 +131,7 @@ class Sensor:
# Initialize components
self.__stitcher = Stitcher(isstitch=isstitch, config_stitcher=self.__config_stitcher, verbose=self.verbose)
self.stitcher = Stitcher(isstitch=isstitch, config_stitcher=self.__config_stitcher, verbose=self.verbose)
self.__tracker = Tracker(adaptive=True, cuda=cuda, verbose=self.verbose, dis_preset=self._config_dis_preset)
self.__contact3d = Contact3D(config_contact=self.__config_contact, verbose=self.verbose)
self.__hhd = None
@@ -168,17 +168,18 @@ class Sensor:
# Convert to grayscale
if log_timing: t0 = time.perf_counter()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = frame
if log_timing: timings['cvt_color'] = (time.perf_counter() - t0) * 1000
# Extract and stitch tiles
if log_timing: t0 = time.perf_counter()
self.__stitcher.get_stitch_unit(gray)
self.stitcher.get_stitch_unit(gray)
self._extract_tiles(gray)
if log_timing: timings['get_tiles'] = (time.perf_counter() - t0) * 1000
if log_timing: t0 = time.perf_counter()
img = np.ascontiguousarray(self.__stitcher.stitch_rt_optimized())
img = np.ascontiguousarray(self.stitcher.stitch_rt_optimized())
if log_timing: timings['stitch'] = (time.perf_counter() - t0) * 1000
self.__img_size_raw = img.shape
@@ -379,12 +380,12 @@ class Sensor:
if self.verbose:
print("Loading calibration from", self.cal_path)
self.stitch_calibration = np.load(self.cal_path, allow_pickle=True)
self.__stitcher.stitch_calibration = self.stitch_calibration
return self.__stitcher.stitch_rt_optimized()
self.stitcher.stitch_calibration = self.stitch_calibration
return self.stitcher.stitch_rt_optimized()
else:
if self.verbose:
print("Creating new calibration...")
img, self.stitch_calibration = self.__stitcher.stitch_cal()
img, self.stitch_calibration = self.stitcher.stitch_cal()
os.makedirs("./config", exist_ok=True)
np.save(self.cal_path, self.stitch_calibration)
if self.verbose:
@@ -448,8 +449,8 @@ class Sensor:
if override:
if box is not None:
self.__stitcher.isstitch = self.isstitch = False
self.__stitcher.boxes = box
self.stitcher.isstitch = self.isstitch = False
self.stitcher.boxes = box
else:
print("Override=True but no box provided.")
else:
@@ -467,15 +468,16 @@ class Sensor:
v_mean = np.sum(cv2.mean(frame))
if abs(v_mean - v_mean0) < 5:
n_boxes = self.__stitcher.find_stitch_boxes(frame, show=show)
n_boxes, boxes = self.stitcher.find_stitch_boxes(frame, show=show)
if (cv2.getTickCount() - start_time) / cv2.getTickFrequency() > timeout:
print("Timeout finding vision units.")
self.__stitcher.isstitch = self.isstitch = False
self.stitcher.isstitch = self.isstitch = False
break
v_mean0 = v_mean
self.__n_boxes = n_boxes
self.boxes = boxes
self.stitch_valid = self.isstitch and n_boxes == self._config_units
status = "valid for stitching" if self.stitch_valid else "non-stitch mode"
@@ -484,8 +486,8 @@ class Sensor:
def _extract_tiles(self, img_src):
"""Extract tiles from source image."""
self.__stitcher.get_stitch_unit(img_src)
self.__stitcher.extract_tiles()
self.stitcher.get_stitch_unit(img_src)
self.stitcher.extract_tiles()
return True