def findTarget(self):
result = cv2.matchTemplate(self.current_frame, self.root_patch.patch, self.match_method)
_, _, _, max_loc = cv2.minMaxLoc(result)
# Select found target
target_top_left = max_loc
target_bottom_right = (
target_top_left[0] + self.patch_w,
target_top_left[1] + self.patch_h)
# Update Patch with current info
patch = self.root_patch.copy()
patch.patch = self.current_frame[
target_top_left[1]: target_bottom_right[1] + 1,
target_top_left[0]: target_bottom_right[0] + 1, :]
patch.p1 = Point(x=target_top_left, y=target_bottom_right)
self.assignRootPatch(patch)
self.tracker = KCFTracker(True, True, True)
self.tracker.init(
[target_top_left[0], target_top_left[1], self.patch_w, self.patch_h],
self.current_frame)
return (target_top_left, target_bottom_right)
评论列表
文章目录