def detect_faces_from_picture(pic_file_path):
print(">>> Let me check this picture: " + pic_file_path)
frame = cv2.imread(pic_file_path)
# Detect faces in the frame
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray_frame, 1.3, 5)
# Match the detected faces with the trained model
if len(faces) > 0:
print(">>> Someone is in the picture!")
for (x, y, w, h) in faces:
face = frame[y:y+h, x:x+w]
result = model.predict(face)
for index, name in model.getTrainCfg():
if result == index:
print(">>> Aha, it's %s!" % name)
评论列表
文章目录