ERROR using opencv_contrib with Python 3.x
Whenever I try to use something from the opencv_contrib I get an error:
Ex1: In the command line
python
>>> import cv2
>>> help(cv2.xfeatures2d)
AttributeError: module 'cv2' has no attribute 'xfeatures2d'
Ex2: Trying to run the following code (just the first few lines)
import cv2
import sys
if __name__ == '__main__' :
tracker = cv2.Tracker_create("BOOSTING")
I Get
Traceback (most recent call last):
File "tracking.py", line 6, in <module>
tracker = cv2.Tracker_create("BOOSTING")
AttributeError: module 'cv2' has no attribute 'Tracker_create'
My seetings for the cmake were:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH= /Users/MatheusTorquato/OpenCV/opencv_contrib/modules \
-D PYTHON3_LIBRARY=/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-darwin/libpython3.6.dylib \
-D PYTHON3_INCLUDE_DIR=/usr/local/Cellar/python3/3.6.0_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m/ \
-D PYTHON3_EXECUTABLE=$VIRTUAL_ENV/bin/python \
-D BUILD_opencv_python2=OFF \
-D BUILD_opencv_python3=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_cvv=OFF\
-D BUILD_opencv_adas=OFF ..
Everything looks fine.
- Python Version – 3.6.0
- OpenCV Version – ‘3.2.0-dev’
- Operating System - macOS Sierra
I've installed everything using this tutorial
Any ideas?
Regards,
Matheus Torquato
I don't know python and linux but I think it is better to organize folder like this :
Now you can check C++ example. and search for an example with surf_matcher in name
They were like these before. I've put both of them inside a folder in an attempt to use relative folder paths. As you might guess, It didn't work. Thanks anyway for your suggestion.
xfeatures module is disable in CMake. There is no opencv_contrib modules something is wrong in your path
I really can't see how my path can be wrong. See Image
^^ please spare us downloading screenshots, instead append text to your **question, thank you !
Ok, I'm sorry for that. I'm not able to the edit the comment anymore.
if you moved the contrib modules in the meantime, please clean the build folder, and start cmake from scratch
Ok, I always do it.
btw, unless the opencv_contrib modules show up in the "to be built" section of the cmake output, - don't even consider to run make
Try the
-D BUILD_NEW_PYTHON_SUPPORT=ON
option. Was having problems last time compiling OpenCV with python3, and that one helped.