|
|
|
@ -1,3 +1,24 @@ |
|
|
|
|
''' |
|
|
|
|
Multitarget planar tracking |
|
|
|
|
================== |
|
|
|
|
|
|
|
|
|
Example of using features2d framework for interactive video homography matching. |
|
|
|
|
ORB features and FLANN matcher are used. This sample provides PlaneTracker class |
|
|
|
|
and an example of its usage. |
|
|
|
|
|
|
|
|
|
video: http://www.youtube.com/watch?v=pzVbhxx6aog |
|
|
|
|
|
|
|
|
|
Usage |
|
|
|
|
----- |
|
|
|
|
plane_tracker.py [<video source>] |
|
|
|
|
|
|
|
|
|
Keys: |
|
|
|
|
SPACE - pause video |
|
|
|
|
c - clear targets |
|
|
|
|
|
|
|
|
|
Select a textured planar object to track by drawing a box with a mouse. |
|
|
|
|
''' |
|
|
|
|
|
|
|
|
|
import numpy as np |
|
|
|
|
import cv2 |
|
|
|
|
from collections import namedtuple |
|
|
|
@ -14,8 +35,22 @@ flann_params= dict(algorithm = FLANN_INDEX_LSH, |
|
|
|
|
|
|
|
|
|
MIN_MATCH_COUNT = 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
''' |
|
|
|
|
image - image to track |
|
|
|
|
rect - tracked rectangle (x1, y1, x2, y2) |
|
|
|
|
keypoints - keypoints detected inside rect |
|
|
|
|
descrs - their descriptors |
|
|
|
|
data - some user-provided data |
|
|
|
|
''' |
|
|
|
|
PlanarTarget = namedtuple('PlaneTarget', 'image, rect, keypoints, descrs, data') |
|
|
|
|
|
|
|
|
|
''' |
|
|
|
|
target - reference to PlanarTarget |
|
|
|
|
p0 - matched points coords in target image |
|
|
|
|
p1 - matched points coords in input frame |
|
|
|
|
H - homography matrix from p0 to p1 |
|
|
|
|
quad - target bounary quad in input frame |
|
|
|
|
''' |
|
|
|
|
TrackedTarget = namedtuple('TrackedTarget', 'target, p0, p1, H, quad') |
|
|
|
|
|
|
|
|
|
class PlaneTracker: |
|
|
|
|