understood templae searchh area

This commit is contained in:
2024-06-29 14:06:46 +02:00
parent ece2900002
commit e00b9fad4e
+10 -11
View File
@@ -3,8 +3,8 @@ import sys
import numpy as np
import imutils as im
IMG_SCALE_UP = 1
SEARCH_AREA = 0
IMG_SCALE_UP = 2
TEMPLATE_SEARCH_AREA = 0.5
(major_ver, minor_ver, subminor_ver) = cv2.__version__.split('.')
print(cv2.__version__)
@@ -39,21 +39,21 @@ def process_image_bbox(src):
return gray
def match(image_bbox, image_template, current_angle):
def match(source, template, current_angle):
best_angle = 0
best_r = 0
best_maxLoc = 0
image_source = im.resize(source, IMG_SCALE_UP * source.shape[0], IMG_SCALE_UP * source.shape[1])
for dangle in np.linspace(-1.0, +1.0, 10):
# scale up to IMG_SCALE_UP-size
image_template_rotated = im.resize(image_template, IMG_SCALE_UP*w, IMG_SCALE_UP*h)
image_template = im.resize(template, IMG_SCALE_UP * template.shape[0], IMG_SCALE_UP * template.shape[1])
# rotated
image_template_rotated = im.rotate(image_template_rotated, current_angle + dangle)
# scale to original-size
image_template_rotated = im.resize(image_template_rotated, w, h)
image_template = im.rotate(image_template, current_angle + dangle)
# Perform template match operations
res = cv2.matchTemplate(image_bbox, image_template_rotated, cv2.TM_CCOEFF_NORMED)
res = cv2.matchTemplate(image_source, image_template, cv2.TM_CCOEFF_NORMED)
(minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(res)
r = maxVal
@@ -97,8 +97,7 @@ if not ok:
# Uncomment the line below to select a different bounding box
bbox = cv2.selectROI("Frame", frame, False)
image_template = process_image_bbox(image_crop(frame, bbox, 0.5))
w, h = image_template.shape[::-1]
image_template = process_image_bbox(image_crop(frame, bbox, TEMPLATE_SEARCH_AREA))
# Initialize tracker with first frame and bounding box
tracker.create()
@@ -117,7 +116,7 @@ while True:
# Update tracker
ok, bbox = tracker.update(frame)
image_bbox = process_image_bbox(image_crop(frame, bbox, SEARCH_AREA))
image_bbox = process_image_bbox(image_crop(frame, bbox))
image_template_rotated = image_template
if ok: