calculate initial offset from template to correct matcher coord

This commit is contained in:
2024-07-02 20:19:58 +02:00
parent f4d8c80ede
commit b5b566e307
+16 -1
View File
@@ -38,6 +38,9 @@ tracker.init(image, bb_crop)
path = []
line_from = None
is_startup = True
offset_x = 0
offset_y = 1
while True:
# Read a new frame
ok, image = video.read()
@@ -64,7 +67,19 @@ while True:
print(f"crop_scaled : {crop_scaled.shape}")
print(f"template : {template.shape}")
print(f"template_scaled : {template_scaled.shape}")
matcher_bbox_local = (max_loc[0]/IMG_SCALE_UP, max_loc[1]/IMG_SCALE_UP, template.shape[1], template.shape[0])
matcher_start_x = max_loc[0]/IMG_SCALE_UP
matcher_start_y = max_loc[0]/IMG_SCALE_UP
if is_startup:
is_startup = False
offset_x = matcher_start_x - bb_template[0]
offset_y = matcher_start_y - bb_template[1]
print(f"offset : {(offset_x, offset_y)}")
matcher_start_x -= offset_x
matcher_start_y -= offset_y
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_top_left_local, matcher_bottom_right_local = to_rect(bbox_round(matcher_bbox_local))
matcher_bbox = bbox_round(bbox_add_position(matcher_bbox_local, bb_crop))