add script and data for debug speed

This commit is contained in:
bluepulsar
2026-02-01 10:46:21 +08:00
parent 29e10c7f94
commit 8b64b730a9
2 changed files with 134 additions and 3 deletions
+21 -3
View File
@@ -121,6 +121,8 @@ class Sensor:
# Timing
self.last_log_time = time.perf_counter()
self._fps = 0
self._last_capture_time = 0.0
self._last_processing_time = 0.0
# Async pipeline state
# self._async_enabled = False
@@ -161,10 +163,20 @@ class Sensor:
Returns:
np.ndarray: Processed grayscale image
"""
# Simple direct read - buffer size of 1 should minimize frame accumulation
# Timing measurement helps identify if capture or processing is the bottleneck
t_capture_start = time.perf_counter()
ret, frame = self.cap.read()
t_capture_end = time.perf_counter()
self._last_capture_time = t_capture_end - t_capture_start
if not ret:
print("Failed to get_img from video source.")
return None
# Start processing timing
t_processing_start = time.perf_counter()
self.frame = frame.copy()
# Extract and stitch tiles
@@ -181,7 +193,9 @@ class Sensor:
img = cv2.flip(img, 1)
self.img = img.astype(np.uint8)
t_processing_end = time.perf_counter()
self._last_processing_time = t_processing_end - t_processing_start
# FPS calculation
self._fps = 1.0 / (time.perf_counter() - self.last_log_time)
@@ -414,9 +428,13 @@ class Sensor:
self.cap = cv2.VideoCapture(self.vid_src)
# Set buffer size to 1 to reduce latency and avoid frame accumulation
self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
# Note: Not all backends support this, but it helps when available
try:
self.cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
except:
pass # Some backends don't support this property
self.cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('M', 'J', 'P', 'G'))
self.cap.set(cv2.CAP_PROP_FPS, self._config_fps)
# self.cap.set(cv2.CAP_PROP_FPS, self._config_fps)
self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, self._config_resolution_raw[0])
self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, self._config_resolution_raw[1])