def async_detect(self, path): """Async detection.""" self.log.log('Request: Detecting {}'.format(path)) self.result.SetLabelText('Detecting ...') self.btn.Disable() self.face_list.Clear() self.face_list.Refresh() self.rsizer.Layout() self.vhsizer.Layout() try: attributes = ( 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,' 'makeup,occlusion,accessories,blur,exposure,noise') res = util.CF.face.detect(path, False, False, attributes) faces = [model.Face(face, path) for face in res] self.face_list.SetItems(faces) util.draw_bitmap_rectangle(self.bitmap, faces) log_text = 'Response: Success. Detected {} face(s) in {}'.format( len(res), path) self.log.log(log_text) text = '{} face(s) has been detected.'.format(len(res)) self.result.SetLabelText(text) except util.CF.CognitiveFaceException as exp: self.log.log('Response: {}. {}'.format(exp.code, exp.msg)) self.btn.Enable() self.rsizer.Layout() self.vhsizer.Layout()
def async_detect(self, path): """Async detection.""" self.log.log('Request: Detecting {}'.format(path)) self.result.SetLabelText('Detecting ...') self.btn.Disable() self.face_list.Clear() self.face_list.Refresh() self.rsizer.Layout() self.vhsizer.Layout() try: attributes = ( 'age,gender,headPose,smile,facialHair,glasses,emotion,hair,' 'makeup,occlusion,accessories,blur,exposure,noise') res = util.CF.face.detect(path, False, False, attributes) faces = [model.Face(face, path) for face in res] self.face_list.SetItems(faces) util.draw_bitmap_rectangle(self.bitmap, faces) log_text = 'Response: Success. Detected {} face(s) in {}'.format( len(res), path) self.log.log(log_text) text = '{} face(s) has been detected.'.format(len(res)) self.result.SetLabelText(text) except util.CF.CognitiveFaceException as exp: self.log.log('Response: {}. {}'.format(exp.code, exp.msg)) self.btn.Enable() self.rsizer.Layout() self.vhsizer.Layout()
def OnChooseImage(self, evt, bitmap, face_id): """Choose Image""" dlg = wx.FileDialog(self, wildcard=util.IMAGE_WILDCARD) if dlg.ShowModal() != wx.ID_OK: return path = dlg.GetPath() self.log.log('Request: Detecting {}'.format(path)) res = util.CF.face.detect(path) faces = [model.Face(face, path) for face in res] self.log.log('Response: Success. Detected {} face(s) in {}'.format( len(res), path)) if len(faces) > 1: text = ( 'Verification accepts two faces as input, please pick images' 'with only one detectable face in it.' ) title = 'Warning' style = wx.OK | wx.ICON_WARNING wx.MessageBox(text, title, style) return bitmap.set_path(path) util.draw_bitmap_rectangle(bitmap, faces) self.face_ids[face_id] = faces[0].id self.check_btn_verify()
def OnChooseImage(self, evt, bitmap, face_id): """Choose Image""" dlg = wx.FileDialog(self, wildcard=util.IMAGE_WILDCARD) if dlg.ShowModal() != wx.ID_OK: return path = dlg.GetPath() self.log.log('Request: Detecting {}'.format(path)) res = util.CF.face.detect(path) faces = [model.Face(face, path) for face in res] self.log.log('Response: Success. Detected {} face(s) in {}'.format( len(res), path)) if len(faces) > 1: text = ( 'Verification accepts two faces as input, please pick images ' 'with only one detectable face in it.') title = 'Warning' style = wx.OK | wx.ICON_WARNING wx.MessageBox(text, title, style) return bitmap.set_path(path) util.draw_bitmap_rectangle(bitmap, faces) self.face_ids[face_id] = faces[0].id self.check_btn_verify()
def async_detect(self, path): """Async detection.""" self.log.log('Request: Detecting {}'.format(path)) self.result.SetLabelText('Detecting ...') self.btn.Disable() self.rsizer.Layout() self.vhsizer.Layout() try: # Use the ML algo on input image, give background (BG) as a class res = util.DD.detect.detect(path, self.detection_init.model, class_names=['BG', 'object_interest']) # Read in image self.bitmap.set_path(res['image_file']) # Set the image on the StaticBitmap object for display util.draw_bitmap_rectangle(self.bitmap) log_text = 'Response: Success. Detected {} object location(s)'.format( res['num_objects'], path) self.log.log(log_text) text = '{} object location(s) detected.'.format(res['num_objects']) self.result.SetLabelText(text) except Exception as exp: self.log.log('Response: {}'.format(exp)) self.btn.Enable() self.rsizer.Layout() self.vhsizer.Layout()
def OnChooseImage(self, evt): """Choose Image.""" util.CF.util.wait_for_large_face_list_training(self.large_face_list_id) self.log.log( 'Response: Success. List "{0}" training process is Succeeded'. format(self.large_face_list_id)) dlg = wx.FileDialog(self, wildcard=util.IMAGE_WILDCARD) if dlg.ShowModal() != wx.ID_OK: return path = dlg.GetPath() self.bitmap.set_path(path) self.log.log('Detecting faces in {}'.format(path)) self.faces.clear() res = util.CF.face.detect(path) for entry in res: face = model.Face(entry, path) self.faces[face.id] = face util.draw_bitmap_rectangle(self.bitmap, self.faces.values()) self.log.log('Success. Detected {} face(s) in {}'.format( len(self.faces), path)) res_tot = { 'matchPerson': {}, 'matchFace': {}, } for face_id in self.faces: self.log.log( ('Request: Finding similar faces in Person Match Mode for ' 'face {}').format(face_id)) for mode in ('matchPerson', 'matchFace'): res_tot[mode][face_id] = [] res = util.CF.face.find_similars( face_id, large_face_list_id=self.large_face_list_id, mode=mode) self.log.log( 'Response: Found {} similar faces for face {} in {} mode'. format(len(res), face_id, mode)) for entry in res: persisted_id = entry['persistedFaceId'] confidence = entry['confidence'] res_tot[mode][face_id].append( (self.persisted_faces[persisted_id], confidence)) self.result.set_data(self.faces, res_tot) self.panel.SetupScrolling(scroll_x=False)
def OnChooseImage(self, evt): """Choose Image.""" util.CF.util.wait_for_large_face_list_training(self.large_face_list_id) self.log.log( 'Response: Success. List "{0}" training process is Succeeded'. format(self.large_face_list_id)) dlg = wx.FileDialog(self, wildcard=util.IMAGE_WILDCARD) if dlg.ShowModal() != wx.ID_OK: return path = dlg.GetPath() self.bitmap.set_path(path) self.log.log('Detecting faces in {}'.format(path)) self.faces.clear() res = util.CF.face.detect(path) for entry in res: face = model.Face(entry, path) self.faces[face.id] = face util.draw_bitmap_rectangle(self.bitmap, self.faces.values()) self.log.log( 'Success. Detected {} face(s) in {}'.format(len(self.faces), path)) res_tot = { 'matchPerson': {}, 'matchFace': {}, } for face_id in self.faces: self.log.log(( 'Request: Finding similar faces in Person Match Mode for ' 'face {}').format(face_id)) for mode in ('matchPerson', 'matchFace'): res_tot[mode][face_id] = [] res = util.CF.face.find_similars( face_id, large_face_list_id=self.large_face_list_id, mode=mode) self.log.log( 'Response: Found {} similar faces for face {} in {} mode'. format(len(res), face_id, mode)) for entry in res: persisted_id = entry['persistedFaceId'] confidence = entry['confidence'] res_tot[mode][face_id].append( (self.persisted_faces[persisted_id], confidence)) self.result.set_data(self.faces, res_tot) self.panel.SetupScrolling(scroll_x=False)
def OnChooseImage(self, evt): """Choose Image.""" util.CF.util.wait_for_large_person_group_training( self.large_person_group_id) self.log.log( 'Response: Success. Group "{0}" training process is Succeeded'. format(self.large_person_group_id)) dlg = wx.FileDialog(self, wildcard=util.IMAGE_WILDCARD) if dlg.ShowModal() != wx.ID_OK: return path = dlg.GetPath() self.bitmap.set_path(path) self.log.log('Detecting faces in {}'.format(path)) self.faces.clear() del self.face_ids[:] res = util.CF.face.detect(path) for entry in res: face = model.Face(entry, path) self.faces[face.id] = face self.face_ids.append(face.id) self.log.log('Request: Identifying {0} face(s) in group "{1}"'.format( len(self.faces), self.large_person_group_id)) res = util.CF.face.identify( self.face_ids, large_person_group_id=self.large_person_group_id) for entry in res: face_id = entry['faceId'] if entry['candidates']: person_id = entry['candidates'][0]['personId'] self.faces[face_id].set_name(self.person_id_names[person_id]) else: self.faces[face_id].set_name('Unknown') util.draw_bitmap_rectangle(self.bitmap, self.faces.values()) log_text = 'Response: Success.' for face_id in self.faces: log_text += ' Face {0} is identified as {1}.'.format( face_id, self.faces[face_id].name) self.log.log(log_text)
def OnChooseImage(self, evt): """Choose Image.""" util.CF.util.wait_for_large_person_group_training( self.large_person_group_id) self.log.log( 'Response: Success. Group "{0}" training process is Succeeded'. format(self.large_person_group_id)) dlg = wx.FileDialog(self, wildcard=util.IMAGE_WILDCARD) if dlg.ShowModal() != wx.ID_OK: return path = dlg.GetPath() self.bitmap.set_path(path) self.log.log('Detecting faces in {}'.format(path)) self.faces.clear() del self.face_ids[:] res = util.CF.face.detect(path) for entry in res: face = model.Face(entry, path) self.faces[face.id] = face self.face_ids.append(face.id) self.log.log('Request: Identifying {0} face(s) in group "{1}"'.format( len(self.faces), self.large_person_group_id)) res = util.CF.face.identify( self.face_ids, large_person_group_id=self.large_person_group_id) for entry in res: face_id = entry['faceId'] if entry['candidates']: person_id = entry['candidates'][0]['personId'] self.faces[face_id].set_name(self.person_id_names[person_id]) else: self.faces[face_id].set_name('Unknown') util.draw_bitmap_rectangle(self.bitmap, self.faces.values()) log_text = 'Response: Success.' for face_id in self.faces: log_text += ' Face {0} is identified as {1}.'.format( face_id, self.faces[face_id].name) self.log.log(log_text)
def async_detect(self, path): """Async detection.""" self.log.log('Request: Detecting {}'.format(path)) self.result.SetLabelText('Detecting ...') self.btn.Disable() self.face_list.Clear() self.face_list.Refresh() self.rsizer.Layout() self.vhsizer.Layout() attributes = 'age,gender,headPose,smile,facialHair,glasses,emotion' res = util.CF.face.detect(path, False, False, attributes) faces = [model.Face(face, path) for face in res] self.face_list.SetItems(faces) util.draw_bitmap_rectangle(self.bitmap, faces) log_text = 'Response: Success. Detected {} face(s) in {}'.format( len(res), path) self.log.log(log_text) text = '{} face(s) has been detected.'.format(len(res)) self.result.SetLabelText(text) self.btn.Enable() self.rsizer.Layout() self.vhsizer.Layout()