Ejemplo n.º 1
0
    def __init__(self,
                 prev,
                 curr,
                 templates,
                 callback=None,
                 match_threshold=0.8):
        """
        State machine for hand gesture recognition.

        Callback is called with the parameters:

        query : array_like
            The set of (x,y) points that represent the hand path
        template : array_like
            The best matching template gesture
        score : float
            The matching score (in range [0,1] with 1 being perfect match)
        theta : float
            The rotation of the gesture that gave the best match
        clsid : int
            The ID of the template class that matched best

        Parameters
        ----------
        imshape : tuple
            The dimensions tuple of the image stream
        templates : string, h5py.File
            h5py.File instance or path to the h5 dataset of template gestures to use
        callback : function
            Callback function called when a gesture match is made
        """
        super(self.__class__, self).__init__(self.Wait)

        self.callback = callback
        self.match_threshold = match_threshold

        if isinstance(templates, basestring):
            self.template_ds = h5py.File(templates, 'r')
        else:
            self.template_ds = templates

        self.segmenter = SkinMotionSegmenter(prev, curr)
        self.detector = ConvexityHandDetector()
        self.tracker = CrCbMeanShiftTracker()

        self.imshape = prev.shape
        self.counter = 0
        self.waypts = []