Logo Search packages:      
Sourcecode: gnome-mousetrap version File versions  Download package

def mouseTrap::ocvfw::ocvfw::cmGetMotionPoints (   self,
  imgRoi = None 
)

Calculate the motion points in the image.

Arguments:
- self: The main object pointer.
- start: The start ROI point.
- end: The end ROI point.
- num: The nomber of points to return

Returns A list with the points found.

Definition at line 289 of file ocvfw.py.

00289                                                :
        """
        Calculate the motion points in the image.
        
        Arguments:
        - self: The main object pointer.
        - start: The start ROI point.
        - end: The end ROI point.
        - num: The nomber of points to return
        
        Returns A list with the points found.
        """
        
        mv = []
        N = 4
        
        timestamp = time.clock()/1.0

        if imgRoi:
            img     = cv.cvGetSubRect( self.img, imgRoi )
            imgSize = cv.cvSize( imgRoi.width, imgRoi.height )
            self.imgRoi = img
        else:
            img     = self.img
            imgSize = self.imgSize 
            
        # Motion Related Variables
        if not self.mhi or self.mhi.width != imgSize.width or self.mhi.height != imgSize.height:
            self.buf        = [ 0, 0, 0, 0 ]
            self.lastFm     = 0
            self.mhiD       = 1
            self.maxTD      = 0.5
            self.minTD      = 0.05
            self.mask       = cv.cvCreateImage( imgSize,  8, 1 )
            self.mhi        = cv.cvCreateImage( imgSize, 32, 1 )
            self.orient     = cv.cvCreateImage( imgSize, 32, 1 )
            self.segmask    = cv.cvCreateImage( imgSize, 32, 1 )
            
            cv.cvZero( self.mhi )
            
            for i in range( N ):
                self.buf[i] = cv.cvCreateImage( imgSize, 8, 1 )
                cv.cvZero( self.buf[i] )
        
        idx1 = self.lastFm
        
        # convert frame to grayscale
        cv.cvCvtColor( img, self.buf[self.lastFm], cv.CV_BGR2GRAY )
        
        # index of (self.lastFm - (N-1))th frame
        idx2 = ( self.lastFm + 1 ) % N 
        self.lastFm = idx2
        
        silh = self.buf[idx2]
        
        # Get difference between frames
        cv.cvAbsDiff( self.buf[idx1], self.buf[idx2], silh ) 
        
        # Threshold it
        cv.cvThreshold( silh, silh, 30, 1, cv.CV_THRESH_BINARY )
        
        # Update MHI
        cv.cvUpdateMotionHistory( silh, self.mhi, timestamp, self.mhiD )
        
        cv.cvCvtScale( self.mhi, self.mask, 255./self.mhiD, (self.mhiD - timestamp)*255./self.mhiD )
        
        cv.cvCalcMotionGradient( self.mhi, self.mask, self.orient, self.maxTD, self.minTD, 3 )
        
        cv.cvClearMemStorage( self.storage )
        
        seq = cv.cvSegmentMotion( self.mhi, self.segmask, self.storage, timestamp, self.maxTD )
        
        for i in range(0, seq.total):
            if i < 0:  # case of the whole image
                continue
            else:  # i-th motion component
                # Movement Rectangle
                mRect = seq[i].rect 
                
                # reject very small components
                if( mRect.width + mRect.height < 30 ):
                    continue
                
            center = cv.cvPoint( (mRect.x + mRect.width/2), (mRect.y + mRect.height/2) )
           
            silhRoi = cv.cvGetSubRect(silh, mRect)
            count = cv.cvNorm( silhRoi, None, cv.CV_L1, None )
            
             # calculate number of points within silhouette ROI
            if( count < mRect.width * mRect.height * 0.05 ):
                continue
            
            mv.append(center)
            
        return mv
        return mv


Generated by  Doxygen 1.6.0   Back to index