Fixed too many windows

This commit is contained in:
2024-06-30 14:47:41 +02:00
parent 56ba394a00
commit 7463d46c24
3 changed files with 15 additions and 8 deletions
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+15 -8
View File
@@ -3,7 +3,7 @@ import sys
import numpy as np
import imutils as im
IMG_SCALE_UP = 4
IMG_SCALE_UP = 1
TEMPLATE_MATCH_OVERLAP = 0.5
(major_ver, minor_ver, subminor_ver) = cv2.__version__.split('.')
@@ -66,8 +66,10 @@ def template_match_rotation(source, template, angle, center, rot_min=-1.0, rot_m
break
angle += best_angle
loc_x = best_max_loc[0] + source.shape[0]/2 - 1
loc_y = best_max_loc[1] + source.shape[0]/2 - 1
return angle, best_max_loc
return angle, (loc_x, loc_y)
def match(source, template, angle, center):
@@ -95,6 +97,7 @@ class Reference:
break
elif key == 27:
break
cv2.destroyWindow("Ref")
return self.center
def extract_coordinates(self, event, x, y, flags, parameters):
@@ -121,7 +124,7 @@ trackers = {
tracker_type = 'KCF'
tracker = trackers[tracker_type].create()
video = cv2.VideoCapture("./data/production_id 4525346 (1080p).mp4")
video = cv2.VideoCapture("./data/IMG_1728.qt")
# Exit if video not open
# d.
@@ -147,8 +150,10 @@ tracker.create()
tracker.init(frame_init, bbox_init)
current_angle = 0
line_from = (ref_center[0] + bbox_template[0], ref_center[1] + bbox_template[1])
#line_from = (ref_center[0] + bbox_template[0], ref_center[1] + bbox_template[1])
line_from = None
path = []
while True:
# Read a new frame
@@ -185,9 +190,13 @@ while True:
# Draw path
line_to = (round(startX + bbox[0]), round(startY + bbox[1]))
cv2.line(frame_init, line_from, line_to, (0, 0, 255), 2)
if line_from is not None:
path.append({'from': line_from, 'to': line_to})
line_from = line_to
for p in path:
cv2.line(frame, p['from'], p['to'], (0, 0, 255), 2)
else:
# Tracking failure
cv2.putText(frame, "Tracking failure detected", (100, 80), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2)
@@ -199,9 +208,7 @@ while True:
cv2.putText(frame, "FPS : " + str(int(fps)), (100, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50, 170, 50), 2)
# Display result
cv2.imshow("Path", frame_init)
cv2.imshow("Tracking", frame)
cv2.imshow("image_bbox", image_template_rotated)
cv2.imshow("Frame", frame)
# Exit if ESC pressed
k = cv2.waitKey(1) & 0xff