Ejemplo n.º 1
0
 def asHomography(self,forward=True):
     '''
     Get the transformation as a homography.
     
     @keyword forward: switch between the forward and reverse transform.
     @ktype forward: True|False
     '''
     fw,fh = self.frame_size
     tw,th = self.frame_size
     if forward:
         if self.homography == None:
             matrix = np.eye(3)
         else:
             matrix = np.linalg.inv(pv.OpenCVToNumpy(self.homography))
         matrix = np.dot(np.diag([tw/fw,th/fh,1.0]),matrix)
         perspective = pv.PerspectiveTransform(matrix,self.frame_size)
     else:
         if self.homography_rev == None:
             matrix = np.eye(3)
         else:
             matrix = np.linalg.inv(pv.OpenCVToNumpy(self.homography_rev))
         matrix = np.dot(np.diag([tw/fw,th/fh,1.0]),matrix)
         perspective = pv.PerspectiveTransform(matrix,self.frame_size)
         
     return perspective
Ejemplo n.º 2
0
    def annotateFrame(self,frame,color='white'):
        '''
        Renders optical flow information to the frame.
        
        @param frame: the frame that will be annotated
        @type frame: pv.Image
        @keyword type:
        @ktype type: "TRACKING" 
        
        '''
        w,h = self.tile_size
        rect = pv.Rect(0,0,w,h)
        affine = pv.AffineFromRect(rect,frame.size)
        for pt in affine.transformPoints(self.tracks[:self.n]):
            frame.annotatePoint(pt,color=color)

        for pt in affine.transformPoints(self.tracks[self.n:]):
            frame.annotatePoint(pt,color='red')
            
        for pt in affine.transformPoints(self.bad_points):
            frame.annotatePoint(pt,color='gray')
            
        
        if self.homography != None:
            matrix = pv.OpenCVToNumpy(self.homography)
            perspective = pv.PerspectiveTransform(matrix,frame.size)

            for pt in self.tracks[:self.n]:
                # Transform the point multiple times to amplify the track 
                # for visualization
                old = perspective.invertPoint(pt)
                old = perspective.invertPoint(old)
                old = perspective.invertPoint(old)
                frame.annotateLine(pt,old,color=color)