|
39 | 39 | (frame.shape[1], frame.shape[0])) |
40 | 40 | else: |
41 | 41 | output = None |
42 | | - |
| 42 | + |
43 | 43 | track_window = (options.col, options.row, options.width, options.height) |
44 | 44 | hsv_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) |
45 | 45 | mask = cv2.inRange(hsv_frame, |
|
52 | 52 | nr_frames = 1 |
53 | 53 | while True: |
54 | 54 | status, frame = capture.read() |
55 | | - if status == True: |
56 | | - nr_frames += 1 |
57 | | - hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) |
58 | | - dst = cv2.calcBackProject([hsv], [0], roi_hist, [0, 50], 1) |
59 | | - status, track_window = cv2.meanShift(dst, track_window, |
60 | | - termination_cond) |
61 | | - if not status: |
62 | | - continue |
63 | | - x, y, w, h = track_window |
64 | | - img = cv2.rectangle(frame, (x, y), (x + w, y + h), 255, 2) |
65 | | - cv2.imshow('image', img) |
66 | | - if output: |
67 | | - output.write(img) |
68 | | - if cv2.waitKey(1) % 0xFF == ord('q'): |
69 | | - break |
70 | | - else: |
| 55 | + if status != True: |
71 | 56 | break |
72 | 57 |
|
| 58 | + nr_frames += 1 |
| 59 | + hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV) |
| 60 | + dst = cv2.calcBackProject([hsv], [0], roi_hist, [0, 50], 1) |
| 61 | + status, track_window = cv2.meanShift(dst, track_window, |
| 62 | + termination_cond) |
| 63 | + if not status: |
| 64 | + continue |
| 65 | + x, y, w, h = track_window |
| 66 | + img = cv2.rectangle(frame, (x, y), (x + w, y + h), 255, 2) |
| 67 | + cv2.imshow('image', img) |
| 68 | + if output: |
| 69 | + output.write(img) |
| 70 | + if cv2.waitKey(1) % 0xFF == ord('q'): |
| 71 | + break |
73 | 72 | print(f'{nr_frames} frames processed') |
74 | 73 | cv2.destroyAllWindows() |
75 | 74 | if output: |
|
0 commit comments