(self, frame)
return tracked
Returns a list of detected TrackedTarget objects
Returns a list of detected TrackedTarget objects
Returns a list of detected TrackedTarget objects
def track(self, frame):
        '''Returns a list of detected TrackedTarget objects'''
        self.frame_points, frame_descrs = self.detect_features(frame)
        if len(self.frame_points) < MIN_MATCH_COUNT:
            return []
        matches = self.matcher.knnMatch(frame_descrs, k = 2)
        matches = [m[0] for m in matches if len(m) == 2 and m[0].distance < m[1].distance * 0.75]
        if len(matches) < MIN_MATCH_COUNT:
            return []
        matches_by_id = [[] for _ in xrange(len(self.targets))]
        for m in matches:
            matches_by_id[m.imgIdx].append(m)
        tracked = []
        for imgIdx, matches in enumerate(matches_by_id):
            if len(matches) < MIN_MATCH_COUNT:
                continue
            target = self.targets[imgIdx]
            p0 = [target.keypoints[m.trainIdx].pt for m in matches]
            p1 = [self.frame_points[m.queryIdx].pt for m in matches]
            p0, p1 = np.float32((p0, p1))
            H, status = cv2.findHomography(p0, p1, cv2.RANSAC, 3.0)
            status = status.ravel() != 0
            if status.sum() < MIN_MATCH_COUNT:
                continue
            p0, p1 = p0[status], p1[status]

            x0, y0, x1, y1 = target.rect
            quad = np.float32([[x0, y0], [x1, y0], [x1, y1], [x0, y1]])
            quad = cv2.perspectiveTransform(quad.reshape(1, -1, 2), H).reshape(-1, 2)

            track = TrackedTarget(target=target, p0=p0, p1=p1, H=H, quad=quad)
            tracked.append(track)
        tracked.sort(key = lambda t: len(t.p0), reverse=True)
        return tracked
def track ( self , frame ) : self . frame_points , frame_descrs = self . detect_features ( frame ) if len ( self . frame_points ) < MIN_MATCH_COUNT : return [ ] matches = self . matcher . knnMatch ( frame_descrs , k = 2 ) matches = [ m [ 0 ] for m in matches if len ( m ) == 2 and m [ 0 ] . distance < m [ 1 ] . distance * 0.75 ] if len ( matches ) < MIN_MATCH_COUNT : return [ ] matches_by_id = [ [ ] for _ in xrange ( len ( self . targets ) ) ] for m in matches : matches_by_id [ m . imgIdx ] . append ( m ) tracked = [ ] for imgIdx , matches in enumerate ( matches_by_id ) : if len ( matches ) < MIN_MATCH_COUNT : continue target = self . targets [ imgIdx ] p0 = [ target . keypoints [ m . trainIdx ] . pt for m in matches ] p1 = [ self . frame_points [ m . queryIdx ] . pt for m in matches ] p0 , p1 = np . float32 ( ( p0 , p1 ) ) H , status = cv2 . findHomography ( p0 , p1 , cv2 . RANSAC , 3.0 ) status = status . ravel ( ) != 0 if status . sum ( ) < MIN_MATCH_COUNT : continue p0 , p1 = p0 [ status ] , p1 [ status ] x0 , y0 , x1 , y1 = target . rect quad = np . float32 ( [ [ x0 , y0 ] , [ x1 , y0 ] , [ x1 , y1 ] , [ x0 , y1 ] ] ) quad = cv2 . perspectiveTransform ( quad . reshape ( 1 , - 1 , 2 ) , H ) . reshape ( - 1 , 2 ) track = TrackedTarget ( target = target , p0 = p0 , p1 = p1 , H = H , quad = quad ) tracked . append ( track ) tracked . sort ( key = lambda t : len ( t . p0 ) , reverse = True ) return tracked