Fixed too many windows
This commit is contained in:
Binary file not shown.
Binary file not shown.
+15
-8
@@ -3,7 +3,7 @@ import sys
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import imutils as im
|
import imutils as im
|
||||||
|
|
||||||
IMG_SCALE_UP = 4
|
IMG_SCALE_UP = 1
|
||||||
TEMPLATE_MATCH_OVERLAP = 0.5
|
TEMPLATE_MATCH_OVERLAP = 0.5
|
||||||
|
|
||||||
(major_ver, minor_ver, subminor_ver) = cv2.__version__.split('.')
|
(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
|
break
|
||||||
|
|
||||||
angle += best_angle
|
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):
|
def match(source, template, angle, center):
|
||||||
@@ -95,6 +97,7 @@ class Reference:
|
|||||||
break
|
break
|
||||||
elif key == 27:
|
elif key == 27:
|
||||||
break
|
break
|
||||||
|
cv2.destroyWindow("Ref")
|
||||||
return self.center
|
return self.center
|
||||||
|
|
||||||
def extract_coordinates(self, event, x, y, flags, parameters):
|
def extract_coordinates(self, event, x, y, flags, parameters):
|
||||||
@@ -121,7 +124,7 @@ trackers = {
|
|||||||
tracker_type = 'KCF'
|
tracker_type = 'KCF'
|
||||||
tracker = trackers[tracker_type].create()
|
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
|
# Exit if video not open
|
||||||
# d.
|
# d.
|
||||||
@@ -147,8 +150,10 @@ tracker.create()
|
|||||||
tracker.init(frame_init, bbox_init)
|
tracker.init(frame_init, bbox_init)
|
||||||
|
|
||||||
current_angle = 0
|
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:
|
while True:
|
||||||
# Read a new frame
|
# Read a new frame
|
||||||
@@ -185,9 +190,13 @@ while True:
|
|||||||
|
|
||||||
# Draw path
|
# Draw path
|
||||||
line_to = (round(startX + bbox[0]), round(startY + bbox[1]))
|
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
|
line_from = line_to
|
||||||
|
|
||||||
|
for p in path:
|
||||||
|
cv2.line(frame, p['from'], p['to'], (0, 0, 255), 2)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Tracking failure
|
# Tracking failure
|
||||||
cv2.putText(frame, "Tracking failure detected", (100, 80), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2)
|
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)
|
cv2.putText(frame, "FPS : " + str(int(fps)), (100, 50), cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50, 170, 50), 2)
|
||||||
|
|
||||||
# Display result
|
# Display result
|
||||||
cv2.imshow("Path", frame_init)
|
cv2.imshow("Frame", frame)
|
||||||
cv2.imshow("Tracking", frame)
|
|
||||||
cv2.imshow("image_bbox", image_template_rotated)
|
|
||||||
|
|
||||||
# Exit if ESC pressed
|
# Exit if ESC pressed
|
||||||
k = cv2.waitKey(1) & 0xff
|
k = cv2.waitKey(1) & 0xff
|
||||||
|
|||||||
Reference in New Issue
Block a user