From 19d5aedf22431acebb0b027f8f4ba79ff36a985d Mon Sep 17 00:00:00 2001 From: Jens Ahrensfeld Date: Wed, 3 Jul 2024 22:03:59 +0200 Subject: [PATCH] not round too early --- ocv_corner_tracker.py | 2 +- ocv_template_matching.py | 11 ++++++----- util.py | 13 ++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/ocv_corner_tracker.py b/ocv_corner_tracker.py index 40a18f9..4164c31 100644 --- a/ocv_corner_tracker.py +++ b/ocv_corner_tracker.py @@ -48,7 +48,7 @@ class CornerTracker: matcher_start_y -= self.ref['offset'][1] self._print(f"matcher_start : {(matcher_start_x, matcher_start_y)}") - matcher_bbox_local = (round(matcher_start_x), round(matcher_start_y), template.shape[1], template.shape[0]) + matcher_bbox_local = (matcher_start_x, matcher_start_y, template.shape[1], template.shape[0]) cv2.imshow(f"{self.name}: Matcher res", matcher_res) # cv2.imshow("{self.name}: Matcher view", matcher_crop) diff --git a/ocv_template_matching.py b/ocv_template_matching.py index 155d59b..a4ea409 100644 --- a/ocv_template_matching.py +++ b/ocv_template_matching.py @@ -119,7 +119,7 @@ while True: ct.path_add(line_to) for p in ct.path: - cv2.line(image_anno, p['from'], p['to'], (0, 0, 255), 2) + cv2.line(image_anno, bbox_round(p['from']), bbox_round(p['to']), (0, 0, 255), 2) refine_corner(cv2.cvtColor(image, cv2.COLOR_BGR2GRAY), np.array(corners, dtype=np.float32)) @@ -182,7 +182,8 @@ while True: k = cv2.waitKey(key_wait) & 0xff if k == 27: break - if k == ord('g'): - key_wait = 30 - if k == ord('s'): - key_wait = -1 + if k == ord(' '): + if key_wait == -1: + key_wait = 30 + else: + key_wait = -1 diff --git a/util.py b/util.py index dcbca45..452cc21 100644 --- a/util.py +++ b/util.py @@ -20,17 +20,16 @@ def bbox_add_position(bbox, bbox_add): def bbox_round(src): - x = int(round(src[0])) - y = int(round(src[1])) - w = int(round(src[2])) - h = int(round(src[3])) + res = () + for s in src: + res += (int(round(s)),) - return x, y, w, h + return res def bbox_center(bbox): - x = round(bbox[0] + bbox[2]/2) - y = round(bbox[1] + bbox[3]/2) + x = bbox[0] + bbox[2]/2 + y = bbox[1] + bbox[3]/2 return x, y