From 4ba56d593d28e44b26418b79e23df5f3669ce59e Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Thu, 4 Jul 2024 21:51:27 +0200 Subject: [PATCH] - added bbox_int() - use bbox_int() - changed colors of tracks --- ocv_corner_tracker.py | 15 +++++++++------ util.py | 8 ++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/ocv_corner_tracker.py b/ocv_corner_tracker.py index 68a6257..58c29f0 100644 --- a/ocv_corner_tracker.py +++ b/ocv_corner_tracker.py @@ -2,7 +2,7 @@ import cv2 import numpy as np import imutils as im -from util import bbox_round, image_crop, to_rect, bbox_add_position, bbox_center +from util import image_crop, to_rect, bbox_add_position, bbox_center, bbox_int IMG_SCALE_UP = 1 IMG_ROTATE = 0 @@ -11,6 +11,9 @@ COLOR_TRACKER = (0, 255, 0) COLOR_TRACKER_EXT = (0, 255, 255) COLOR_MATCHER = (0, 0, 255) COLOR_TEMPLATE = (255, 0, 0) +COLOR_TRACK = (255, 255, 0) +COLOR_CIRCLE = (0, 255, 0) + TEMPLATE_MATCH_OVERLAP = 0 CONSOLE_DEBUG = False @@ -113,18 +116,18 @@ class CornerTracker: print(f"{self.name}: {s}") def _debug(self, _image_anno, tracking_anno, matcher_bbox_local): - matcher_bbox = bbox_round(bbox_add_position(matcher_bbox_local, self.tracking_bb)) + matcher_bbox = bbox_int(bbox_add_position(matcher_bbox_local, self.tracking_bb)) template_top_left, template_bottom_right = to_rect(self.matching_tpl_bb) cv2.rectangle(tracking_anno, template_top_left, template_bottom_right, COLOR_TEMPLATE, 1) - matcher_top_left_local, matcher_bottom_right_local = to_rect(bbox_round(matcher_bbox_local)) + matcher_top_left_local, matcher_bottom_right_local = to_rect(bbox_int(matcher_bbox_local)) cv2.rectangle(tracking_anno, matcher_top_left_local, matcher_bottom_right_local, COLOR_MATCHER, 1) matcher_rect = to_rect(matcher_bbox) cv2.rectangle(_image_anno, matcher_rect[0], matcher_rect[1], COLOR_MATCHER, 1) - tracker_rect = to_rect(bbox_round(self.tracking_bb)) + tracker_rect = to_rect(bbox_int(self.tracking_bb)) cv2.rectangle(_image_anno, tracker_rect[0], tracker_rect[1], self.color, 1) def init_reference_frame(self, _image: np.array): @@ -212,7 +215,7 @@ class CornerTracker: # draw path for _ct in self.corner_matcher_list: for p in _ct.path: - cv2.line(_image_anno, bbox_round(p['from']), bbox_round(p['to']), (0, 0, 255), 1) + cv2.line(_image_anno, bbox_int(p['from']), bbox_int(p['to']), COLOR_TRACK, 1) distances = [] for _i in range(0, corners_refined.shape[0]): @@ -226,7 +229,7 @@ class CornerTracker: self._print(f" -- Corner coarse [{i}] {corners_raw[_i]}") self._print(f" -- Corner fine [{i}] {corners_refined[_i]}") self._print(f" -- Corner distance [{i}] {corners_refined[_i] - self.corner_ref[_i]}") - cv2.circle(_image_anno, (int(corners_refined[_i, 0]), int(corners_refined[_i, 1])), 4, (0, 255, 0)) + cv2.circle(_image_anno, (int(corners_refined[_i, 0]), int(corners_refined[_i, 1])), 4, COLOR_CIRCLE) if IMAGE_DEBUG: cv2.imshow(f"{self.name}: Tracker: ", self.tracking_img) diff --git a/util.py b/util.py index d5147b8..89933b5 100644 --- a/util.py +++ b/util.py @@ -25,6 +25,14 @@ def bbox_round(src): return res +def bbox_int(src): + res = () + for s in src: + res += (int(s),) + + return res + + def bbox_center(bbox): x = bbox[0] + bbox[2]/2 y = bbox[1] + bbox[3]/2