def cv_Identifyfaces(identifyfaces, picture=None): ''' 運用 cv2 技術顯示的 Identifyfaces ''' import cv2 import numpy as np # print('identifyfaces=',identifyfaces) if len(identifyfaces) == 0: cv_ImageText('沒有偵測到任何人!', '請按「ENTER」繼續') return for identifyface in identifyfaces: faceimagepath = ClassUtils.getFaceImagepath(identifyface['faceId']) if 'person' not in identifyface: print('identifyface=', identifyface) cv_ImageText('你哪位?請先訓練。', '按 ENTER 繼續', faceimagepath, picture, identifyfaces) else: text = ClassUtils.textConfidence(identifyface['person']['name'], identifyface['confidence']) try: print(text, identifyface['confidence']) except UnicodeEncodeError as e: print("UnicodeEncodeERROR!!", identifyface['confidence']) #print('cv_Identifyfaces.identifyface=', identifyface) # text = ClassUtils.textConfidence(identifyface['person']['name'], # identifyface['confidence']) cv_ImageText(text, '按 ENTER 繼續', faceimagepath, picture, identifyfaces)
def cv_Identifyfaces(identifyfaces, picture=None): ''' 運用 cv2 技術顯示的 Identifyfaces ''' import cv2 import numpy as np # print('identifyfaces=',identifyfaces) if len(identifyfaces) == 0: cv_ImageText('No Faces Detected', 'Press [ENTER] to continue ') return for identifyface in identifyfaces: faceimagepath = ClassUtils.getFaceImagepath(identifyface['faceId']) if 'person' not in identifyface: print('identifyface=', identifyface) cv_ImageText('Who is it?? Please train first!', 'Press [ENTER] to continue ', faceimagepath, picture, identifyfaces) else: text = ClassUtils.textConfidence(identifyface['person']['name'], identifyface['confidence']) try: print(text, identifyface['confidence']) except UnicodeEncodeError as e: print("UnicodeEncodeERROR!!", identifyface['confidence']) #print('cv_Identifyfaces.identifyface=', identifyface) # text = ClassUtils.textConfidence(identifyface['person']['name'], # identifyface['confidence']) cv_ImageText(text, '[ENTER] to continue ', faceimagepath, picture, identifyfaces)
def __detectFaces_Save(self, detectFaces, imagepath): for detectface in detectFaces: print("faceRectangle = ", detectface['faceRectangle']) print("faceId = ", detectface['faceId']) left = detectface['faceRectangle']['left'] top = detectface['faceRectangle']['top'] height = detectface['faceRectangle']['height'] width = detectface['faceRectangle']['width'] img = Image.open(imagepath) draw = ImageDraw.Draw(img) if config['landmark'] > 0: print("save facelandmarks=", detectface['faceLandmarks']) for faceLandmark in detectface['faceLandmarks']: print('faceLandmark=', faceLandmark) print('faceLandmark=', detectface['faceLandmarks'][faceLandmark]) x = int(detectface['faceLandmarks'][faceLandmark]['x']) y = int(detectface['faceLandmarks'][faceLandmark]['y']) draw.ellipse( (x, y, x + config['landmark'], y + config['landmark']), fill=(255, 0, 0)) #faceRectangle = {'top': 141, 'height': 261, 'width': 261, 'left': 664} faceonly = img.crop((left, top, left + width, top + height)) saveFaceImagepath = ClassUtils.getFaceImagepath( detectface['faceId']) faceonly.save(saveFaceImagepath, 'PNG')