Herokuで当てはまるかどうか分かりませんが、以下のいくつかの記事を見ると、
opencv-python
とopencv-contrib-python
の両方をインストールしてはいけない。
どちらか片方のみをインストールすること、そしてface
を使うならopencv-contrib-python
らしいです。
ただし未承認ですが、逆に両方インストールで解決したという回答もあります。
AttributeError: module 'cv2.cv2' has no attribute 'faces' in OpenCV
承認マーク付き回答
Try update OpenCV with
pip install opencv-contrib-python
それに付いたコメント
It worked in my case. Do you know how are these modules: opencv-contrib-python and openCV different?
私の場合はうまくいきました。これらのモジュール:opencv-contrib-pythonとopenCVがどのように異なるか知っていますか?
I believeopencv-contrib-python
is the unofficial pre-built OpenCV package. It's not the official OpenCV package released by OpenCV.org. There is alsoopencv-python
which contains just the main modules of the OpenCV library whileopencv-contrib-python
contains both the main modules along with the contrib modules. You don't want to install both, pick only one.
opencv-contrib-pythonは、非公式のビルド済みOpenCVパッケージだと思います。
OpenCV.orgによってリリースされた公式のOpenCVパッケージではありません。
また、OpenCVライブラリのメインモジュールのみを含むopencv-pythonがあり、opencv-contrib-pythonにはcontribモジュールとともにメインモジュールの両方が含まれます。
両方をインストールするのではなく、1つだけを選択します。
本家で同様のものが解決済みらしいです。
module 'cv2.cv2' has no attribute 'face' #13848 - opencv/opencv
他に承認マークは無いですが、類似の回答もあります。
module 'cv2.cv2' has no attribute 'face'
Theface
module isn't actually a part of theopencv
library proper. Rather, face is part of theopencv-contrib
library. From the readme:
This repository [opencv-contrib
] is intended for development of so-called "extra" modules, contributed functionality. New modules quite often do not have stable API, and they are not well-tested. Thus, they shouldn't be released as a part of official OpenCV distribution, since the library maintains binary compatibility, and tries to provide decent performance and stability.
opencv-contrib
needs to be installed separately. As @james pointed out (in a now deleted comment), the current easy way to get the Python version is to just do:
pip install opencv-contrib-python
After you run the abovepip
call, your code should work.
逆にこちらは未承認ですが両方インストールして動作したらしいです。
AttributeError: module 'cv2' has no attribute 'face'
Finally, I got it working. I just used pip for both installations:
pip install opencv-python
pip install opencv-contrib-python
類似で未承認。
AttributeError: module 'cv2.cv2' has no attribute 'createLBPHFaceRecognizer'
attributeerror: module 'cv2.face' has no attribute 'createlbphfacerecognizer'