コード例 #1
0
    def detect(self, frame):
        """
        Detect the hand
        :param frame: image frame
        :return: cropped image, transformation, center
        """

        hd = HandDetector(frame,
                          self.sync['config']['fx'],
                          self.sync['config']['fy'],
                          importer=self.importer,
                          refineNet=self.comrefNet)
        doHS = (self.state.value == self.STATE_INIT)
        if self.tracking.value and not numpy.allclose(self.lastcom, 0):
            loc, handsz = hd.track(self.lastcom,
                                   self.sync['config']['cube'],
                                   doHandSize=doHS)
        else:
            loc, handsz = hd.detect(size=self.sync['config']['cube'],
                                    doHandSize=doHS)

        self.lastcom = loc

        if self.state.value == self.STATE_INIT:
            self.handsizes.append(handsz)
            if self.verbose is True:
                print(numpy.median(numpy.asarray(self.handsizes), axis=0))
        else:
            self.handsizes = []

        if self.state.value == self.STATE_INIT and len(
                self.handsizes) >= self.numinitframes:
            cfg = self.sync['config']
            cfg['cube'] = tuple(
                numpy.median(numpy.asarray(self.handsizes),
                             axis=0).astype('int'))
            self.sync.update(config=cfg)
            self.state.value = self.STATE_RUN
            self.handsizes = []

        if numpy.allclose(loc, 0):
            return numpy.zeros(
                (self.poseNet.input_images.get_shape()[1].value,
                 self.poseNet.input_images.get_shape()[2].value),
                dtype='float32'), numpy.eye(3), loc
        else:
            crop, M, com = hd.cropArea3D(
                com=loc,
                size=self.sync['config']['cube'],
                dsize=(self.poseNet.input_images.get_shape()[1].value,
                       self.poseNet.input_images.get_shape()[2].value))
            com3D = self.importer.jointImgTo3D(com)
            sc = (self.sync['config']['cube'][2] / 2.)
            crop[crop == 0] = com3D[2] + sc
            crop.clip(com3D[2] - sc, com3D[2] + sc)
            crop -= com3D[2]
            crop /= sc
            return crop, M, com3D
コード例 #2
0
    def detect(self, frame):
        """
        Detect the hand
        :param frame: image frame
        :return: cropped image, transformation, center
        """

        hd = HandDetector(frame,
                          self.config['fx'],
                          self.config['fy'],
                          importer=self.importer,
                          refineNet=self.comrefNet)
        doHS = (self.state == self.STATE_INIT)
        if self.tracking and not numpy.allclose(self.lastcom, 0):
            loc, handsz = hd.track(self.lastcom,
                                   self.config['cube'],
                                   doHandSize=doHS)
        else:
            loc, handsz = hd.detect(size=self.config['cube'], doHandSize=doHS)

        self.lastcom = loc

        if self.state == self.STATE_INIT:
            self.handsizes.append(handsz)
            print numpy.median(numpy.asarray(self.handsizes), axis=0)
        else:
            self.handsizes = []

        if self.state == self.STATE_INIT and len(
                self.handsizes) >= self.numinitframes:
            self.config['cube'] = tuple(
                numpy.median(numpy.asarray(self.handsizes),
                             axis=0).astype('int'))
            self.state = self.STATE_RUN
            self.handsizes = []

        if numpy.allclose(loc, 0):
            return numpy.zeros((self.poseNet.cfgParams.inputDim[2],
                                self.poseNet.cfgParams.inputDim[3]),
                               dtype='float32'), numpy.eye(3), loc
        else:
            crop, M, com = hd.cropArea3D(
                loc,
                size=self.config['cube'],
                dsize=(self.poseNet.layers[0].cfgParams.inputDim[2],
                       self.poseNet.layers[0].cfgParams.inputDim[3]))
            com3D = self.importer.jointImgTo3D(com)
            crop[crop == 0] = com3D[2] + (self.config['cube'][2] / 2.)
            crop[crop >= com3D[2] +
                 (self.config['cube'][2] / 2.)] = com3D[2] + (
                     self.config['cube'][2] / 2.)
            crop[crop <= com3D[2] -
                 (self.config['cube'][2] / 2.)] = com3D[2] - (
                     self.config['cube'][2] / 2.)
            crop -= com3D[2]
            crop /= (self.config['cube'][2] / 2.)
            return crop, M, com3D