draw path
This commit is contained in:
@@ -2,13 +2,13 @@ import cv2
|
||||
import sys
|
||||
import imutils as im
|
||||
|
||||
from util import bbox_extend, bbox_round, image_crop, to_rect, bbox_add_position
|
||||
from util import bbox_extend, bbox_round, image_crop, to_rect, bbox_add_position, bbox_center
|
||||
|
||||
COLOR_TRACKER = (0, 255, 0)
|
||||
COLOR_TRACKER_EXT = (0, 255, 255)
|
||||
COLOR_MATCHER = (0, 0, 255)
|
||||
COLOR_TEMPLATE = (255, 0, 0)
|
||||
IMG_SCALE_UP = 2
|
||||
IMG_SCALE_UP = 1
|
||||
TEMPLATE_MATCH_OVERLAP = 0
|
||||
|
||||
video = cv2.VideoCapture("./data/IMG_1730.MP4")
|
||||
@@ -28,13 +28,16 @@ if not ok:
|
||||
bb_crop = bbox_extend(cv2.selectROI("Image", image, False), TEMPLATE_MATCH_OVERLAP)
|
||||
crop = image_crop(image.copy(), bb_crop)
|
||||
|
||||
bb_template = cv2.selectROI("Image", crop, False)
|
||||
bb_template = cv2.selectROI("Image", crop, fromCenter=True, showCrosshair=True)
|
||||
template = image_crop(crop.copy(), bb_template)
|
||||
|
||||
# Initialize tracker with first frame and bounding box
|
||||
tracker = cv2.TrackerKCF().create()
|
||||
tracker.init(image, bb_crop)
|
||||
|
||||
path = []
|
||||
line_from = None
|
||||
|
||||
while True:
|
||||
# Read a new frame
|
||||
ok, image = video.read()
|
||||
@@ -77,6 +80,15 @@ while True:
|
||||
cv2.rectangle(image_anno, tracker_rect[0], tracker_rect[1], COLOR_TRACKER, 1)
|
||||
matcher_crop = image_crop(image, matcher_bbox)
|
||||
|
||||
# Draw path
|
||||
line_to = bbox_center(matcher_bbox)
|
||||
if line_from is not None:
|
||||
path.append({'from': line_from, 'to': line_to})
|
||||
line_from = line_to
|
||||
|
||||
for p in path:
|
||||
cv2.line(image_anno, p['from'], p['to'], (0, 0, 255), 2)
|
||||
|
||||
cv2.imshow("Crop", crop)
|
||||
cv2.imshow("Image", image_anno)
|
||||
cv2.imshow("Matcher res", res)
|
||||
|
||||
Reference in New Issue
Block a user