Пример #1
0
    def run(self,
            detector='detector_ssd_mobilenet_v2',
            recognizer=FaceRecognizerResnet.NAME,
            image='./samples/redhot/redhot_1.jpg',
            visualize=True):

        self.set_detector(detector)  # Inicializar modelo de deteccion
        self.set_recognizer(recognizer)  # Inicializar modelo de reconocimiento

        npimg = cv2.imread(image, cv2.IMREAD_COLOR)  # Leer imagen

        if npimg is None:  # Verificar lectura de imagen
            sys.exit(-1)

        t = time.time()
        faces = self.detector.detect(npimg)  # Correr detector de faces
        #print("Detecta {} faces en {} segundos".format(len(faces), round(time.time()-t,2)))

        if recognizer:
            t = time.time()
            faces = self.run_recognizer(
                npimg, faces, recognizer)  # Correr Reconocimiento de rostros
        #    print("Reconoce {} faces en {} segundos".format(len(faces), round(time.time()-t, 2)))

        img = draw_bboxs(np.copy(npimg), faces)  # Dibujar los bounding boxes
        if visualize:
            f = 2
            cv2.imshow('DeepFace',
                       cv2.resize(img, (img.shape[1] * f,
                                        img.shape[0] * f)))  # Mostrar imagen
            cv2.waitKey(0)

        return faces
Пример #2
0
    def run(self, detector='detector_ssd_mobilenet_v2', recognizer=FaceRecognizerResnet.NAME, image='./samples/blackpink/blackpink1.jpg',
            visualize=False):
        self.set_detector(detector)
        self.set_recognizer(recognizer)

        if image is None:
            return []
        elif isinstance(image, str):
            logger.debug('read image, path=%s' % image)
            npimg = cv2.imread(image, cv2.IMREAD_COLOR)
        elif isinstance(image, np.ndarray):
            npimg = image
        else:
            logger.error('Argument image should be str or ndarray. image=%s' % str(image))
            sys.exit(-1)

        if npimg is None:
            logger.error('image can not be read, path=%s' % image)
            sys.exit(-1)

        logger.debug('run face detection+ %dx%d' % (npimg.shape[1], npimg.shape[0]))
        faces = self.detector.detect(npimg)

        logger.debug('run face detection- %s' % len(faces))

        if recognizer:
            faces = self.run_recognizer(npimg, faces, recognizer)

        img = draw_bboxs(np.copy(npimg), faces)
        cv2.imwrite('result.jpg', img)
        if visualize and visualize not in ['false', 'False']:
            cv2.imshow('DeepFace', img)
            cv2.waitKey(0)

        return faces
Пример #3
0
def show_with_face(npimg, faces, visualize=False):
    if visualize:
        img = draw_bboxs(np.copy(npimg), faces)
        cv2.imshow('DeepFace', img)
        cv2.waitKey(0)