def extract(self, im, face_records, run_async=False): request = fsd.ExtractRequest() try: request.image.CopyFrom( pt.image_np2proto(im, compression=self.options.compression, quality=self.options.quality)) except: request.image.CopyFrom( pt.image_np2proto(im.asOpenCV2()[:, :, ::-1], compression=self.options.compression, quality=self.options.quality)) request.records.CopyFrom(face_records) if run_async == False: face_records = self.service_stub.extract(request, None) elif run_async == True: self.waitOnResults() face_records = self.service_stub.extract.future(request, None) self.running_async_jobs.append(face_records) else: raise ValueError("Unexpected run_async value: %s" % (run_async, )) return face_records
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
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
def detectExtract(self,request,context): ''' runs the face detector and extraction in one call and returns extracted faces. ''' # Run detection face_records_list = self.detect(request,context) # Run extract extract_request = fsd.ExtractRequest() extract_request.image.CopyFrom( request.image ) extract_request.records.CopyFrom(face_records_list) extract_request.extract_options.CopyFrom(request.extract_options) face_records_list = self.extract(extract_request, context) return face_records_list
def extract(self, im, face_records, run_async=False): request = fsd.ExtractRequest() print("DR INFO", dir(request)) try: request.image.CopyFrom(pt.image_np2proto(im)) except: request.image.CopyFrom( pt.image_np2proto(im.asOpenCV2()[:, :, ::-1])) request.records.CopyFrom(face_records) if run_async == False: face_records = self.rec_stub.extract(request, None) elif run_async == True: self.waitOnResults() face_records = self.rec_stub.extract.future(request, None) self.running_async_jobs.append(face_records) else: raise ValueError("Unexpected run_async value: %s" % (run_async, )) return face_records