- fixed accessing variable outside function
- refactored
This commit is contained in:
+18
-13
@@ -1,6 +1,7 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from util import image_crop, to_rect, bbox_add_position, bbox_center, bbox_round
|
||||
|
||||
@@ -143,8 +144,8 @@ class CornerTracker:
|
||||
|
||||
def init_reference_frame(self, _image: np.array):
|
||||
# Draw mask
|
||||
_mask = CornerTracker.mask_init(image)
|
||||
CornerTracker.mask_draw(image, _mask)
|
||||
_mask = CornerTracker.mask_init(_image)
|
||||
CornerTracker.mask_draw(_image, _mask)
|
||||
|
||||
# Select search area
|
||||
print(f"Select tracking object")
|
||||
@@ -299,6 +300,7 @@ if __name__ == '__main__':
|
||||
parser.add_argument("--scale", default=1.0)
|
||||
parser.add_argument("--track", action="store_true")
|
||||
parser.add_argument("--path", action="store_true")
|
||||
parser.add_argument("--loop", action="store_true")
|
||||
args = parser.parse_args()
|
||||
video = cv2.VideoCapture(args.filename)
|
||||
|
||||
@@ -309,10 +311,15 @@ if __name__ == '__main__':
|
||||
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 0, 255), (0, 255, 255), (255, 255, 255)]
|
||||
tracker_count = 0
|
||||
tracker_list = []
|
||||
if video.isOpened():
|
||||
if not video.isOpened():
|
||||
print('Cannot open video file')
|
||||
sys.exit(1)
|
||||
# Read first frame.
|
||||
ok, image = video.read()
|
||||
if ok:
|
||||
if not ok:
|
||||
print('Cannot read video file')
|
||||
sys.exit(1)
|
||||
|
||||
for tracker_count in range(0, 6):
|
||||
select_window = image.copy()
|
||||
print(f"Draw tracker #{tracker_count}")
|
||||
@@ -324,9 +331,6 @@ if __name__ == '__main__':
|
||||
else:
|
||||
break
|
||||
|
||||
else:
|
||||
print('Cannot read video file')
|
||||
|
||||
# rewind to frame 0
|
||||
video.set(cv2.CAP_PROP_POS_FRAMES, 0)
|
||||
|
||||
@@ -338,7 +342,13 @@ if __name__ == '__main__':
|
||||
timer = cv2.getTickCount()
|
||||
# Read a new frame
|
||||
ok, image = video.read()
|
||||
if ok:
|
||||
if not ok:
|
||||
if args.loop:
|
||||
video.set(cv2.CAP_PROP_POS_FRAMES, 0)
|
||||
continue
|
||||
else:
|
||||
break
|
||||
|
||||
image_anno = image.copy()
|
||||
i = 0
|
||||
cv2.rectangle(image_anno, (25, 0), (int(image_anno.shape[1]), 25*(1+len(tracker_list))), (0, 0, 0), -1)
|
||||
@@ -362,9 +372,6 @@ if __name__ == '__main__':
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (50, 170, 50), 1)
|
||||
|
||||
cv2.imshow(f"Image Anno", image_anno)
|
||||
else:
|
||||
video.set(cv2.CAP_PROP_POS_FRAMES, 0)
|
||||
continue
|
||||
|
||||
# Exit if ESC pressed
|
||||
k = cv2.waitKey(key_wait) & 0xff
|
||||
@@ -376,5 +383,3 @@ if __name__ == '__main__':
|
||||
else:
|
||||
key_wait = -1
|
||||
|
||||
else:
|
||||
print('Cannot open video file')
|
||||
|
||||
Reference in New Issue
Block a user