diff --git a/data/IMG_1728.MP4 b/data/IMG_1728.MP4 new file mode 100644 index 0000000..e7ebeba Binary files /dev/null and b/data/IMG_1728.MP4 differ diff --git a/data/IMG_1728.qt b/data/IMG_1728.qt new file mode 100644 index 0000000..0c14787 Binary files /dev/null and b/data/IMG_1728.qt differ diff --git a/ocv_track.py b/ocv_track.py index 443834f..16fcbcd 100644 --- a/ocv_track.py +++ b/ocv_track.py @@ -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