diff --git a/dvr_scan/overlays.py b/dvr_scan/overlays.py index 8bfcb5f..6af7efa 100644 --- a/dvr_scan/overlays.py +++ b/dvr_scan/overlays.py @@ -195,7 +195,7 @@ def update(self, motion_mask: numpy.ndarray): self._smoothing_window = self._smoothing_window[-smoothing_amount:] return self._get_smoothed_window() - def draw(self, frame: numpy.ndarray, bounding_box: Tuple[int, int, int, int]): + def draw(self, frame: numpy.ndarray, bounding_box: Tuple[int, int, int, int], use_shift: bool): """Draw a bounding box onto a target frame using the provided ROI and downscale factor.""" # Correct for downscale factor bounding_box = [side_len * self._downscale_factor for side_len in bounding_box] @@ -210,7 +210,7 @@ def draw(self, frame: numpy.ndarray, bounding_box: Tuple[int, int, int, int]): top_left = (top_left[0] - correction_x // 2, top_left[1] - correction_y // 2) bottom_right = (bottom_right[0] + correction_x // 2, bottom_right[1] + correction_y // 2) # Shift bounding box if ROI was set - if self._shift: + if self._shift and use_shift: top_left = (top_left[0] + self._shift[0], top_left[1] + self._shift[1]) bottom_right = (bottom_right[0] + self._shift[0], bottom_right[1] + self._shift[1]) # Ensure coordinates are positive. Values greater than frame size are okay, and should be diff --git a/dvr_scan/scanner.py b/dvr_scan/scanner.py index d2a4509..acfa076 100644 --- a/dvr_scan/scanner.py +++ b/dvr_scan/scanner.py @@ -590,7 +590,7 @@ def scan(self) -> Optional[DetectionResult]: # Length of buffer we require in memory to keep track of all frames required for -l and -tb. buff_len = pre_event_len + min_event_len - event_end = FrameTimecode(timecode=0, fps=self._input.framerate) + event_end = self._input.position last_frame_above_threshold = 0 if self._bounding_box: @@ -847,6 +847,7 @@ def _draw_overlays( timecode: FrameTimecode, frame_score: float, bounding_box: Optional[Tuple[int, int, int, int]], + use_shift=True, ): if not self._timecode_overlay is None: self._timecode_overlay.draw(frame, text=timecode.get_timecode()) @@ -854,7 +855,7 @@ def _draw_overlays( to_display = "Frame: %04d\nScore: %3.2f" % (timecode.get_frames(), frame_score) self._metrics_overlay.draw(frame, text=to_display) if not self._bounding_box is None and not bounding_box is None: - self._bounding_box.draw(frame, bounding_box) + self._bounding_box.draw(frame, bounding_box, use_shift) def _on_mask_event(self, event: MotionMaskEvent): # Initialize the VideoWriter used for mask output. @@ -863,7 +864,8 @@ def _on_mask_event(self, event: MotionMaskEvent): self._mask_writer = self._init_video_writer(self._mask_file, resolution) # Write the motion mask to the output file. out_frame = cv2.cvtColor(event.motion_mask, cv2.COLOR_GRAY2BGR) - self._draw_overlays(out_frame, event.timecode, event.score, event.bounding_box) + self._draw_overlays( + out_frame, event.timecode, event.score, event.bounding_box, use_shift=False) self._mask_writer.write(out_frame) def _on_motion_event(self, event: MotionEvent):