Exemplo n.º 1
0
    def __init__(self,
                 prev,
                 curr,
                 fusion_params={},
                 skin_params={},
                 motion_params={}):
        super(self.__class__, self).__init__(self.segment, **fusion_params)

        self.coseg = GaussianSkinSegmenter(model_params=skin_params)
        self.moseg = MotionSegmenter(prev, curr, model_params=motion_params)

        self.bbox = None
        self.com = None
        self.backprojection = None
        self.skin = None
        self.motion = None
Exemplo n.º 2
0
class SkinMotionSegmenter(Processor):
    '''
    Blends skin and motion segmentation together to get more accurate
    segmentation

    Parameters
    ----------
    alpha : float
        Skin-to-motion blending parameter; i.e., fusion = w*skin + (1-w)*motion
    '''
    def __init__(self,
                 prev,
                 curr,
                 fusion_params={},
                 skin_params={},
                 motion_params={}):
        super(self.__class__, self).__init__(self.segment, **fusion_params)

        self.coseg = GaussianSkinSegmenter(model_params=skin_params)
        self.moseg = MotionSegmenter(prev, curr, model_params=motion_params)

        self.bbox = None
        self.com = None
        self.backprojection = None
        self.skin = None
        self.motion = None

    def segment(self, img):
        self.bbox = self.com = None

        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        self.motion = self.moseg.segment(gray)
        self.skin = self.coseg.segment(img)

        if self.moseg.bbox is None:
            self.backprojection = np.zeros_like(self.motion, dtype=float)
            return self.motion

        x, y, w, h = self.moseg.bbox
        self.backprojection = np.zeros_like(self.coseg.backprojection)
        self.backprojection[y:y+h,x:x+w] = self.coseg.backprojection[y:y+h,x:x+w] \
                                           / self.coseg.backprojection[y:y+h,x:x+w].max()

        self.backprojection[y:y + h, x:x + w] *= self.alpha
        self.backprojection[y:y + h,
                            x:x + w] += (1 - self.alpha) * self.motion[y:y + h,
                                                                       x:x + w]

        fused = np.zeros_like(gray, dtype=bool)
        fused[y:y + h, x:x +
              w] = self.skin[y:y + h, x:x + w] | self.motion[y:y + h, x:x + w]
        if fused.any():
            self.bbox, self.com = findBBoxCoM(fused)

        return fused
Exemplo n.º 3
0
    def __init__(self,prev,curr,fusion_params={},skin_params={},motion_params={}):
        super(self.__class__, self).__init__(self.segment,**fusion_params)

        self.coseg = GaussianSkinSegmenter(model_params=skin_params)
        self.moseg = MotionSegmenter(prev,curr,model_params=motion_params)

        self.bbox = None
        self.com = None
        self.backprojection = None
        self.skin = None
        self.motion = None
Exemplo n.º 4
0
class SkinMotionSegmenter(Processor):
    '''
    Blends skin and motion segmentation together to get more accurate
    segmentation

    Parameters
    ----------
    alpha : float
        Skin-to-motion blending parameter; i.e., fusion = w*skin + (1-w)*motion
    '''

    def __init__(self,prev,curr,fusion_params={},skin_params={},motion_params={}):
        super(self.__class__, self).__init__(self.segment,**fusion_params)

        self.coseg = GaussianSkinSegmenter(model_params=skin_params)
        self.moseg = MotionSegmenter(prev,curr,model_params=motion_params)

        self.bbox = None
        self.com = None
        self.backprojection = None
        self.skin = None
        self.motion = None

    def segment(self,img):
        self.bbox = self.com = None

        gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        self.motion = self.moseg.segment(gray)
        self.skin = self.coseg.segment(img)

        if self.moseg.bbox is None:
            self.backprojection = np.zeros_like(self.motion,dtype=float)
            return self.motion

        x,y,w,h = self.moseg.bbox
        self.backprojection = np.zeros_like(self.coseg.backprojection)
        self.backprojection[y:y+h,x:x+w] = self.coseg.backprojection[y:y+h,x:x+w] \
                                           / self.coseg.backprojection[y:y+h,x:x+w].max()

        self.backprojection[y:y+h,x:x+w] *= self.alpha
        self.backprojection[y:y+h,x:x+w] += (1-self.alpha)*self.motion[y:y+h,x:x+w]

        fused = np.zeros_like(gray,dtype=bool)
        fused[y:y+h,x:x+w] = self.skin[y:y+h,x:x+w] | self.motion[y:y+h,x:x+w]
        if fused.any():
            self.bbox,self.com = findBBoxCoM(fused)

        return fused