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