我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用cv2.createLBPHFaceRecognizer()。
def index(): img_array = [] label_array = [] face_cascade = cv2.CascadeClassifier("https://raw.githubusercontent.com/opencv/opencv/master/data/haarcascades/haarcascade_frontalface_alt.xml") recognizer = cv2.createLBPHFaceRecognizer() for row in db(db.faces.id > 0).select(): rtn = row path=os.path.join(request.folder, 'uploads', rtn.file) # image = response.download(open(path, 'rb'), chunk_size=4096) img = cv2.imread(path, 0) img_array.append(img) # faces = face_cascade.detectMultiScale(img, 1.3, 5) # for (x,y,w,h) in faces: # img_array.append(img[y: y + h, x: x + w]) label_array.append(rtn.user_id) recognizer.train(img_array, np.array(label_array)) recognizer.save(os.path.join(request.folder, 'private', "trained_recognizer.xml")) return response.download("trained_recognizer.xml")
def train(self): """ Entraînement du jeu de données Méthode à surcharger """ logging.info("Entraînement du trainset...") #self.model = cv2.createFisherFaceRecognizer() #self.model = cv2.createEigenFaceRecognizer() self.model = cv2.createLBPHFaceRecognizer() #self.model = cv2.createLBPHFaceRecognizer(radius = 1, grid_x = 6, grid_y = 6) self.model.train(numpy.asarray(self.trainset_images), numpy.asarray(self.trainset_index))
def model(algorithm, thresh): # set the choosen algorithm model = None if is_cv3(): # OpenCV version renamed the face module if algorithm == 1: model = cv2.face.createLBPHFaceRecognizer(threshold=thresh) elif algorithm == 2: model = cv2.face.createFisherFaceRecognizer(threshold=thresh) elif algorithm == 3: model = cv2.face.createEigenFaceRecognizer(threshold=thresh) else: print("WARNING: face algorithm must be in the range 1-3") os._exit(1) else: if algorithm == 1: model = cv2.createLBPHFaceRecognizer(threshold=thresh) elif algorithm == 2: model = cv2.createFisherFaceRecognizer(threshold=thresh) elif algorithm == 3: model = cv2.createEigenFaceRecognizer(threshold=thresh) else: print("WARNING: face algorithm must be in the range 1-3") os._exit(1) return model
def train_recognizer(): recognizer = cv2.createLBPHFaceRecognizer() images, labels = get_images_and_labels() #print images #print labels if images==False: return False cv2.destroyAllWindows() recognizer.train(images, np.array(labels)) #print recognizer return recognizer
def initialize_recognizer(): try: face_recognizer = cv2.face.createLBPHFaceRecognizer() except: face_recognizer = cv2.createLBPHFaceRecognizer() print "Training.........." Dataset = get_images("./Dataset") print "Recognizer trained using Dataset: "+str(Dataset[2])+" Images used" face_recognizer.train(Dataset[0],np.array(Dataset[1])) return face_recognizer
def recognizer(self): """ Creates new FaceRecognizer using Local Binary Patterns (LBP) Returns current recognizer object """ self.current_recognizer = cv2.createLBPHFaceRecognizer() self.current_recognizer.train(self.faces, np.array(self.index)) return self.current_recognizer