add script and data for debug speed
This commit is contained in:
+21
-3
@@ -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])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user