- fixed matcher_start_y

- added spindle test images
This commit is contained in:
2024-07-03 17:21:02 +02:00
parent b5b566e307
commit 1dac2e7ade
962 changed files with 7 additions and 4 deletions
+7 -4
View File
@@ -11,7 +11,8 @@ COLOR_TEMPLATE = (255, 0, 0)
IMG_SCALE_UP = 1
TEMPLATE_MATCH_OVERLAP = 0
video = cv2.VideoCapture("./data/IMG_1730.MP4")
#video = cv2.VideoCapture("./data/IMG_1730.MP4")
video = cv2.VideoCapture('./data/spindle/%04d.png')
# Exit if video not open
# d.
@@ -29,7 +30,7 @@ bb_crop = bbox_extend(cv2.selectROI("Image", image, False), TEMPLATE_MATCH_OVERL
crop = image_crop(image.copy(), bb_crop)
bb_template = cv2.selectROI("Image", crop, fromCenter=True, showCrosshair=True)
template = image_crop(crop.copy(), bb_template)
template = cv2.cvtColor(image_crop(crop.copy(), bb_template), cv2.COLOR_BGR2GRAY)
# Initialize tracker with first frame and bounding box
tracker = cv2.TrackerKCF().create()
@@ -53,13 +54,15 @@ while True:
# Update tracker
ok, bb_crop = tracker.update(image)
crop = image_crop(image.copy(), bb_crop)
crop = cv2.cvtColor(crop, cv2.COLOR_BGR2GRAY)
crop = cv2.GaussianBlur(crop, (15, 15), 0)
image_anno = image.copy()
if ok:
# Perform template match operations
crop_scaled = im.resize(crop.copy(), IMG_SCALE_UP * crop.shape[1], IMG_SCALE_UP * crop.shape[0])
template_scaled = im.resize(template, IMG_SCALE_UP * template.shape[0], IMG_SCALE_UP * template.shape[1])
res = cv2.matchTemplate(cv2.cvtColor(crop_scaled, cv2.COLOR_BGR2GRAY), cv2.cvtColor(template_scaled, cv2.COLOR_BGR2GRAY), cv2.TM_CCOEFF_NORMED)
res = cv2.matchTemplate(crop_scaled, template_scaled, cv2.TM_CCOEFF_NORMED)
(min_val, max_val, min_loc, max_loc) = cv2.minMaxLoc(res)
print(f"(min_val, max_val, min_loc, max_loc): {(min_val, max_val, min_loc, max_loc)}")
print(f"matcher_res : {res.shape}")
@@ -69,7 +72,7 @@ while True:
print(f"template_scaled : {template_scaled.shape}")
matcher_start_x = max_loc[0]/IMG_SCALE_UP
matcher_start_y = max_loc[0]/IMG_SCALE_UP
matcher_start_y = max_loc[1]/IMG_SCALE_UP
if is_startup:
is_startup = False
offset_x = matcher_start_x - bb_template[0]