def getWatershedMask(self): 
        cvMarkerImg = cv.CreateImage( self._fgMask.size, cv.IPL_DEPTH_32S, 1)        
        cv.SetZero(cvMarkerImg)
                
        #fill each contour with a different gray level to label connected components
        seq = self._contours        
        c = 50
        while not (seq == None) and len(seq) != 0:
            if cv.ContourArea(seq) > self._minArea:
                c += 10
                moments = cv.Moments(seq)
                m00 = cv.GetSpatialMoment(moments, 0, 0)
                m01 = cv.GetSpatialMoment(moments, 0, 1)
                m10 = cv.GetSpatialMoment(moments, 1, 0)
                centroid = ( int(m10/m00), int(m01/m00))
                cv.Circle(cvMarkerImg, centroid, 3, cv.RGB(c,c,c), cv.CV_FILLED)
            seq = seq.h_next()
        
        if(c>0):
            img = self._annotateImg.asOpenCV()
            cv.Watershed(img, cvMarkerImg)
        
        tmp = cv.CreateImage( cv.GetSize(cvMarkerImg), cv.IPL_DEPTH_8U, 1)
        cv.CvtScale(cvMarkerImg, tmp)
        return pv.Image(tmp)
Uses the watershed algorithm to refine the foreground mask.
dataset/ETHPy150Open bolme/pyvision/src/pyvision/surveillance/MotionDetector.py/MotionDetector.getWatershedMask