Пример #1
0
    def detectExtractSearch(self,
                            im,
                            search_gallery='default',
                            max_results=3,
                            search_threshold=None,
                            best=False,
                            threshold=None,
                            min_size=None,
                            run_async=False,
                            source=None,
                            subject_id=None,
                            frame=None):
        request = fsd.DetectExtractSearchRequest()
        request.detect_request.CopyFrom(fsd.DetectRequest())
        request.extract_request.CopyFrom(fsd.ExtractRequest())
        request.search_request.CopyFrom(fsd.SearchRequest())

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

        request.search_request.search_gallery = search_gallery
        request.search_request.max_results = max_results

        if search_threshold is None:
            search_threshold = self.match_threshold

        request.search_request.threshold = search_threshold

        # 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

        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.detectExtractSearch(request, None)
        elif run_async == True:
            self.waitOnResults()
            face_records = self.service_stub.detectExtractSearch.future(
                request, None)
            self.running_async_jobs.append(face_records)
        else:
            raise ValueError("Unexpected run_async value: %s" % (run_async, ))

        return face_records
Пример #2
0
    def detectExtract(self,
                      im,
                      best=False,
                      threshold=None,
                      min_size=None,
                      run_async=False,
                      source=None,
                      subject_id=None,
                      frame=None,
                      downsample=0):
        request = fsd.DetectExtractRequest()
        request.detect_request.CopyFrom(fsd.DetectRequest())
        request.extract_request.CopyFrom(fsd.ExtractRequest())

        try:
            request.detect_request.image.CopyFrom(
                pt.image_np2proto(im,
                                  compression=self.options.compression,
                                  quality=self.options.quality))
        except:
            request.detect_request.image.CopyFrom(
                pt.image_np2proto(im.asOpenCV2()[:, :, ::-1],
                                  compression=self.options.compression,
                                  quality=self.options.quality))

        # 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

        request.detect_request.detect_options.best = best
        request.detect_request.detect_options.downsample = downsample

        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.detectExtract(request, None)
        elif run_async == True:
            self.waitOnResults()
            face_records = self.service_stub.detectExtract.future(
                request, None)
            self.running_async_jobs.append(face_records)
        else:
            raise ValueError("Unexpected run_async value: %s" % (run_async, ))
        return face_records