- util: image_crop no round

- construct tracker object in constructor
This commit is contained in:
2024-07-04 18:55:46 +02:00
parent e2ff72a457
commit e1c28a874a
2 changed files with 7 additions and 10 deletions
+1 -2
View File
@@ -106,7 +106,7 @@ class CornerTracker:
self.matching_tpl_img = None
self.tracking_bb = None
self.tracking_img = None
self.tracker = None
self.tracker = cv2.TrackerKCF.create()
self.corner_ref = None
self.corner_matcher_list = []
@@ -166,7 +166,6 @@ class CornerTracker:
return False
# Initialize tracker with first frame and bounding box
self.tracker = cv2.TrackerKCF().create()
self.tracker.init(_image, self.tracking_ref_bb)
# Refine initial corners and store them as reference
+6 -8
View File
@@ -1,5 +1,4 @@
import cv2
import sys
import numpy as np
import imutils as im
@@ -34,19 +33,18 @@ def bbox_center(bbox):
return x, y
def bbox_extend(bbox: cv2.typing.Rect, factor: float = 0):
def bbox_extend(bbox: np.array, factor: float = 0):
we2 = bbox[2]*factor/2
he2 = bbox[3]*factor/2
return bbox_round((bbox[0]-we2, bbox[1]-he2, bbox[2]+2*we2, bbox[3]+2*he2))
def image_crop(src, bbox: cv2.typing.Rect):
bb = bbox_round(bbox)
x = bb[0]
y = bb[1]
w = bb[2]
h = bb[3]
def image_crop(src, bbox: np.array):
x = int(bbox[0])
y = int(bbox[1])
w = int(bbox[2])
h = int(bbox[3])
dst = src[y:y+h, x:x+w]
return dst