人脸识别码为什么会报错

问题描述 投票:0回答:0

我正在尝试运行人脸识别代码,其中将相机框架上的图片与过滤器上的 jpg 图片进行比较,如果匹配则有一条消息问候语,否则打印未知,但我得到一个识别器 = cv2.face.createLBPHFaceRecognizer() ^^^^^^^^ 'AttributeError: module 'cv2' has no attribute 'face' 我已经安装了 VS、SMAKE、DLIB、CV2 和 face_recognition,但错误仍然存在。

导入cv2 导入操作系统 导入人脸识别

for filename in os.listdir("Camera_Roll"): # Camera_Roll 是目录名

 image_path = os.path.join("image_folder", filename) image = face_recognition.load_image_file(image_path)
encoding = face_recognition.face_encodings(图像)[0]

if "reference" in filename:
    reference_encoding = encoding
    break

cap = cv2.VideoCapture(0)

虽然正确: # 从网络摄像头捕获一帧 ret, 框架 = cap.read()

# Convert the frame to grayscale for face detection
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Detect faces in the grayscale frame
faces = face_recognition.face_locations(gray)

# Extract face encodings from the faces in the frame
face_encodings = face_recognition.face_encodings(frame, faces)

# Compare each face encoding to the reference encoding
for encoding in face_encodings:
    results = face_recognition.compare_faces([reference_encoding], encoding)

    # Print the result
    if results[0]:
        print("Hello, known person!")
    else:
        print("This person is unknown.")

# Draw boxes around the faces in the frame
for (top, right, bottom, left) in faces:
    cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0), 2)

# Display the frame
cv2.imshow('Webcam', frame)

# Exit the loop if the 'q' key is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

cap.release() cv2.destroyAllWindows()

python face-recognition
© www.soinside.com 2019 - 2024. All rights reserved.