def detect(self, img, ConvexHulls=False):
        # Smooth the image
        cvim = img.asOpenCV()
        cvim = cv.CloneImage(cvim)
        if self._smooth:
            cv.Smooth(cvim, cvim)
        
        self._imageBuff.add(pv.Image(cvim))
        if not self._imageBuff.isFull():
            return -1
        
        #initialize background subtraction object only after buffer is full.
        if self._bgSubtract == None:
            self._initBGSubtract()

        #update current annotation image from buffer, as appropriate for
        # the different methods
        if self._method==BG_SUBTRACT_FD:
            self._annotateImg = self._imageBuff.getMiddle()
        if self._method==BG_SUBTRACT_MCFD:
            self._annotateImg = self._imageBuff.getMiddle()
        elif self._method==BG_SUBTRACT_MF:
            self._annotateImg = self._imageBuff.getLast()
        elif self._method==BG_SUBTRACT_AMF:
            self._annotateImg = self._imageBuff.getLast()

        mask = self._bgSubtract.getForegroundMask()
#        if self._softThreshold:
#            cvWeights = mask.asOpenCVBW()
#            scale = (1.0/255.0)  #because weights are 0-255 in mask image
#            cvCurImg = self._annotateImg.copy().asOpenCVBW()
#            cvDst = cv.CreateImage(cv.GetSize(cvWeights), cv.IPL_DEPTH_8U, 1)
#            cv.Mul(cvWeights, cvCurImg, cvDst, scale)
#            cv.Smooth(cvDst, cvDst)
#            #update the foreground mask
#            self._fgMask = pv.Image(cvDst) 
#        else:    

        cvBinary = mask.asOpenCVBW()
        cv.Smooth(cvBinary, cvBinary)
        cv.Dilate(cvBinary, cvBinary, None, 3)
        cv.Erode(cvBinary, cvBinary, None, 1)
        
        #update the foreground mask
        self._fgMask = pv.Image(cvBinary)
        
        #update the detected foreground contours
        self._computeContours()
        self._computeConvexHulls()
            
        if ConvexHulls:
            for hull in self._convexHulls:
                cv.FillConvexPoly(cvBinary, hull, cv.RGB(255,255,255))
            #k = cv.CreateStructuringElementEx(15, 15, 7, 7, cv.CV_SHAPE_RECT)
            #cv.Dilate(mask, mask, element=k, iterations=1)
            
        return len(self._contours)
You call this method to update detection results, given the new
dataset/ETHPy150Open bolme/pyvision/src/pyvision/surveillance/MotionDetector.py/MotionDetector.detect