dq6a reach 18 ms per frame
This commit is contained in:
+28
-18
@@ -114,6 +114,8 @@ class Sensor:
|
||||
# self.stitch_calibration = []
|
||||
self.frame = self.img = None
|
||||
self.initial_img = None
|
||||
self._img_bgr_raw = None
|
||||
self._img_gray_buf = None
|
||||
shape = (self.__config_cam["resolution_stitch"][1], self.__config_cam["resolution_stitch"][0])
|
||||
self.img_size_raw = None
|
||||
self.img_filtered = None
|
||||
@@ -212,35 +214,33 @@ class Sensor:
|
||||
# Start processing timing
|
||||
t_processing_start = time.perf_counter()
|
||||
|
||||
# self.frame = frame.copy()
|
||||
self.frame = frame
|
||||
# Extract and stitch tiles
|
||||
# self.stitcher.get_stitch_unit(frame)
|
||||
self._extract_tiles(frame)
|
||||
t_after_extract = time.perf_counter()
|
||||
|
||||
img = np.ascontiguousarray(self.stitcher.stitch_rt_optimized(blend=True))
|
||||
img_bgr = self.stitcher.stitch_rt_optimized(blend=False)
|
||||
t_after_stitch = time.perf_counter()
|
||||
|
||||
self.img_size_raw = img.shape
|
||||
# Resize
|
||||
img = cv2.resize(img, tuple(self._config_resolution_stitch), interpolation=cv2.INTER_LINEAR)
|
||||
t_after_resize = time.perf_counter()
|
||||
|
||||
if self.mirror:
|
||||
img = cv2.flip(img, 1)
|
||||
t_after_mirror = time.perf_counter()
|
||||
self.img_size_raw = img_bgr.shape
|
||||
self._img_bgr_raw = img_bgr
|
||||
|
||||
self.img = img.astype(np.uint8)
|
||||
t_after_astype = time.perf_counter()
|
||||
gray = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2GRAY)
|
||||
res = tuple(self._config_resolution_stitch)
|
||||
if self._img_gray_buf is None or self._img_gray_buf.shape != (res[1], res[0]):
|
||||
self._img_gray_buf = np.empty((res[1], res[0]), dtype=np.uint8)
|
||||
cv2.resize(gray, res, dst=self._img_gray_buf, interpolation=cv2.INTER_LINEAR)
|
||||
t_after_resize = time.perf_counter()
|
||||
|
||||
if self.mirror:
|
||||
cv2.flip(self._img_gray_buf, 1, dst=self._img_gray_buf)
|
||||
|
||||
self.img = self._img_gray_buf
|
||||
|
||||
t_processing_end = time.perf_counter()
|
||||
self._last_processing_time = t_processing_end - t_processing_start
|
||||
self._last_stage_times["extract_tiles"] = t_after_extract - t_processing_start
|
||||
self._last_stage_times["stitch"] = t_after_stitch - t_after_extract
|
||||
self._last_stage_times["resize"] = t_after_resize - t_after_stitch
|
||||
self._last_stage_times["mirror"] = t_after_mirror - t_after_resize
|
||||
self._last_stage_times["astype"] = t_after_astype - t_after_mirror
|
||||
self._last_stage_times["resize"] = t_processing_end - t_after_stitch
|
||||
|
||||
# FPS calculation
|
||||
self._fps = 1.0 / (time.perf_counter() - self.last_log_time)
|
||||
@@ -248,6 +248,16 @@ class Sensor:
|
||||
|
||||
return self.img.copy()
|
||||
|
||||
def _get_img_bgr(self):
|
||||
"""Produce a resized+mirrored BGR image on demand (for display)."""
|
||||
if self._img_bgr_raw is None:
|
||||
return None
|
||||
res = tuple(self._config_resolution_stitch)
|
||||
bgr = cv2.resize(self._img_bgr_raw, res, interpolation=cv2.INTER_LINEAR)
|
||||
if self.mirror:
|
||||
cv2.flip(bgr, 1, dst=bgr)
|
||||
return bgr
|
||||
|
||||
def detect_motion(self, threshold=6):
|
||||
|
||||
# detect motion by optical flow magnitude
|
||||
@@ -410,7 +420,7 @@ class Sensor:
|
||||
else None
|
||||
),
|
||||
self.info.CONTOUR: lambda: self.contour.copy() if self.contour is not None else np.array([]),
|
||||
self.info.IMG: lambda: self.img.copy() if self.img is not None else np.array([]),
|
||||
self.info.IMG: lambda: self._get_img_bgr() if self._img_bgr_raw is not None else np.array([]),
|
||||
}
|
||||
|
||||
return tuple(mapping.get(arg, lambda: None)() for arg in args if isinstance(arg, self.info))
|
||||
|
||||
Reference in New Issue
Block a user