Ejemplo n.º 1
0
    def enroll(self,
               faces,
               enroll_gallery,
               subject_id=None,
               subject_name=None,
               run_async=False,
               **kwargs):
        request = fsd.EnrollRequest()
        request.enroll_gallery = enroll_gallery
        if subject_id is not None:
            for face in faces.face_records:
                face.subject_id = subject_id
        if subject_name is not None:
            for face in faces.face_records:
                face.name = subject_name

        request.records.CopyFrom(faces)

        if run_async == False:
            error = self.service_stub.enroll(request, None)
        elif run_async == True:
            self.waitOnResults()
            error = self.service_stub.enroll.future(request, None)
            self.running_async_jobs.append(error)
        else:
            raise ValueError("Unexpected run_async value: %s" % (run_async, ))

        return error
Ejemplo n.º 2
0
    def detectExtractEnroll(self,
                            im,
                            enroll_gallery='default',
                            best=False,
                            threshold=None,
                            min_size=None,
                            run_async=False,
                            source=None,
                            subject_id=None,
                            subject_name=None,
                            frame=None):
        request = fsd.DetectExtractEnrollRequest()
        request.detect_request.CopyFrom(fsd.DetectRequest())
        request.extract_request.CopyFrom(fsd.ExtractRequest())
        request.enroll_request.CopyFrom(fsd.EnrollRequest())

        try:
            request.detect_request.image.CopyFrom(pt.image_np2proto(im))
        except:
            request.detect_request.image.CopyFrom(
                pt.image_np2proto(im.asOpenCV2()[:, :, ::-1]))

        request.enroll_request.enroll_gallery = enroll_gallery

        # Setup the source and subject information.
        request.detect_request.source = 'UNKNOWN_SOURCE'
        request.detect_request.subject_id = 'UNKNOWN_SUBJECT'
        if source is not None:
            request.detect_request.source = source
        if frame is not None:
            request.detect_request.frame = frame
        if subject_id is not None:
            request.detect_request.subject_id = subject_id
        if subject_name is not None:
            request.detect_request.subject_name = subject_name

        request.detect_request.detect_options.best = best

        if threshold == None:
            request.detect_request.detect_options.threshold = self.info.detection_threshold
        else:
            request.detect_request.detect_options.threshold = float(threshold)

        if run_async == False:
            face_records = self.service_stub.detectExtractEnroll(request, None)
        elif run_async == True:
            self.waitOnResults()
            face_records = self.service_stub.detectExtractEnroll.future(
                request, None)
            self.running_async_jobs.append(face_records)
        else:
            raise ValueError("Unexpected run_async value: %s" % (run_async, ))

        return face_records