Ask Your Question
0

ERROR using opencv_contrib with Python 3.x

asked 2017-03-15 12:40:26 -0600

Matheusft gravatar image

updated 2017-03-16 09:01:47 -0600

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.

  • Configuring: Ok - File
  • Making: Ok - File
  • Installing: Ok - File

  • 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

edit retag flag offensive close merge delete

Comments

I don't know python and linux but I think it is better to organize folder like this :

/Users/MatheusTorquato/opencv/
/Users/MatheusTorquato/opencv_contrib/modules

Now you can check C++ example. and search for an example with surf_matcher in name

LBerger gravatar imageLBerger ( 2017-03-15 16:07:28 -0600 )edit

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.

Matheusft gravatar imageMatheusft ( 2017-03-15 23:29:08 -0600 )edit

xfeatures module is disable in CMake. There is no opencv_contrib modules something is wrong in your path

LBerger gravatar imageLBerger ( 2017-03-16 02:17:11 -0600 )edit

I really can't see how my path can be wrong. See Image

Matheusft gravatar imageMatheusft ( 2017-03-16 09:00:00 -0600 )edit

^^ please spare us downloading screenshots, instead append text to your **question, thank you !

berak gravatar imageberak ( 2017-03-16 09:10:47 -0600 )edit

Ok, I'm sorry for that. I'm not able to the edit the comment anymore.

Matheusft gravatar imageMatheusft ( 2017-03-16 09:14:01 -0600 )edit

if you moved the contrib modules in the meantime, please clean the build folder, and start cmake from scratch

berak gravatar imageberak ( 2017-03-16 09:16:18 -0600 )edit

Ok, I always do it.

Matheusft gravatar imageMatheusft ( 2017-03-16 09:38:30 -0600 )edit

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

berak gravatar imageberak ( 2017-03-16 13:09:22 -0600 )edit

Try the -D BUILD_NEW_PYTHON_SUPPORT=ON option. Was having problems last time compiling OpenCV with python3, and that one helped.

adn gravatar imageadn ( 2017-03-16 15:25:19 -0600 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2017-03-17 12:45:31 -0600

Matheusft gravatar image

updated 2017-03-17 12:46:01 -0600

After trying hundreds of different combinations it finally worked!!!

I'm not sure which was the modification responsible for making it work, since in my last attempt I've modified two things:

  1. Instead of /Users/MatheusTorquato/OpenCV/opencv_contrib/modules I've used ~/OpenCV/opencv_contrib/modules (I can't really spot the difference)
  2. I've added ~/OpenCV/main after the "opencv_contrib/modules" path in the OPENCV_EXTRA_MODULES_PATH resulting in:

    -D OPENCV_EXTRA_MODULES_PATH= ~/OpenCV/opencv_contrib/modules ~/OpenCV/main
    

Where ~/OpenCV/opencv_contrib/modules is the opencv_contrib/modules path and ~/OpenCV/main is the OpenCV source directory path.

I've found this information in the file README.md in the opencv_contrib folder:

Here is the CMake command for you:


$ cd <opencv_build_directory>
$ cmake -D OPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j4
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-03-15 12:40:26 -0600

Seen: 3,184 times

Last updated: Mar 17 '17