understood templae searchh area
This commit is contained in:
+10
-11
@@ -3,8 +3,8 @@ import sys
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import imutils as im
|
import imutils as im
|
||||||
|
|
||||||
IMG_SCALE_UP = 1
|
IMG_SCALE_UP = 2
|
||||||
SEARCH_AREA = 0
|
TEMPLATE_SEARCH_AREA = 0.5
|
||||||
|
|
||||||
(major_ver, minor_ver, subminor_ver) = cv2.__version__.split('.')
|
(major_ver, minor_ver, subminor_ver) = cv2.__version__.split('.')
|
||||||
print(cv2.__version__)
|
print(cv2.__version__)
|
||||||
@@ -39,21 +39,21 @@ def process_image_bbox(src):
|
|||||||
return gray
|
return gray
|
||||||
|
|
||||||
|
|
||||||
def match(image_bbox, image_template, current_angle):
|
def match(source, template, current_angle):
|
||||||
best_angle = 0
|
best_angle = 0
|
||||||
best_r = 0
|
best_r = 0
|
||||||
best_maxLoc = 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):
|
for dangle in np.linspace(-1.0, +1.0, 10):
|
||||||
# scale up to IMG_SCALE_UP-size
|
# 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
|
# rotated
|
||||||
image_template_rotated = im.rotate(image_template_rotated, current_angle + dangle)
|
image_template = im.rotate(image_template, current_angle + dangle)
|
||||||
# scale to original-size
|
|
||||||
image_template_rotated = im.resize(image_template_rotated, w, h)
|
|
||||||
|
|
||||||
# Perform template match operations
|
# 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)
|
(minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(res)
|
||||||
|
|
||||||
r = maxVal
|
r = maxVal
|
||||||
@@ -97,8 +97,7 @@ if not ok:
|
|||||||
|
|
||||||
# Uncomment the line below to select a different bounding box
|
# Uncomment the line below to select a different bounding box
|
||||||
bbox = cv2.selectROI("Frame", frame, False)
|
bbox = cv2.selectROI("Frame", frame, False)
|
||||||
image_template = process_image_bbox(image_crop(frame, bbox, 0.5))
|
image_template = process_image_bbox(image_crop(frame, bbox, TEMPLATE_SEARCH_AREA))
|
||||||
w, h = image_template.shape[::-1]
|
|
||||||
|
|
||||||
# Initialize tracker with first frame and bounding box
|
# Initialize tracker with first frame and bounding box
|
||||||
tracker.create()
|
tracker.create()
|
||||||
@@ -117,7 +116,7 @@ while True:
|
|||||||
# Update tracker
|
# Update tracker
|
||||||
ok, bbox = tracker.update(frame)
|
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
|
image_template_rotated = image_template
|
||||||
|
|
||||||
if ok:
|
if ok:
|
||||||
|
|||||||
Reference in New Issue
Block a user