You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

OpenCV报错求助:cv2.face无createLBPHFaceRecognizer属性(Python3.6+OpenCV3.4)

Fixing the cv2.face.createLBPHFaceRecognizer Missing Attribute Error

Hey there, let's work through this error you're facing with OpenCV 3.4 and Python 3.6. I've dealt with this exact issue before, so here's what you need to do:

1. Correct the API Method Name

First off, the method name changed between OpenCV 2.x and 3.x. In OpenCV 3.4, the LBPH face recognizer is created using cv2.face.LBPHFaceRecognizer_create() — not cv2.face.createLBPHFaceRecognizer() (that's the old 2.x syntax). Update your code to use the 3.x method and see if that resolves the error right away.

2. Ensure Matching Versions of OpenCV and opencv-contrib-python

Even if you installed opencv-contrib-python, a version mismatch between the main opencv-python package and the contrib package can cause missing modules. Here's how to fix that:

  • First, uninstall any existing OpenCV packages to start fresh:
    pip uninstall opencv-python opencv-contrib-python -y
    
  • Then install the exact 3.4.x versions compatible with Python 3.6. The latest stable 3.4 release that works with Python 3.6 is 3.4.15.55:
    pip install opencv-python==3.4.15.55 opencv-contrib-python==3.4.15.55
    

3. Verify the Installation

Run this quick test script to confirm everything is set up correctly:

import cv2

# Check OpenCV version
print(f"OpenCV version: {cv2.__version__}")

# Try creating the LBPH recognizer
try:
    recognizer = cv2.face.LBPHFaceRecognizer_create()
    print("Successfully created LBPHFaceRecognizer!")
except AttributeError as e:
    print(f"Error still occurs: {e}")

If the script prints the 3.4.15.55 version and the success message, you're good to go!

内容的提问来源于stack exchange,提问作者Anirudh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:21:13