Issue in compiling and importing opencv 3.0 in python
Hi,
I am a beginner to openCV and am trying to use python-openCV 3.0 . I performed the following steps to to import and use opencv in python. I am using python 2.7 , 32-bit on windows 64-bit operating system.
- I downloaded the opencv source code from the official site
- I downloaded opencv_contrib from https://github.com/itseez/opencv_contrib
- I used cmake and Visual studio 2012 to generate the release binary cv2.pyd (I set options Build_shared_libs = false and opencv_extra_modules_path = path of the opencv_contrib modules.).
- Then I copy this cv2.pyd in my Python/Lib/site-packages folder.
Now, when I import cv2, I am able to access the usual methods of opencv but am unable to access the ones of opencv_contrib. When I type cv2.xfeatures2d , I get an import error.
Using the following lines of code :
import cv2 as cv
for method in dir(cv):
if callable(getattr(cv, method)):
print method
I do not get xfeatures2d (module of opencv_contrib) printed
However, if I remove the line if callable(getattr(cv, method))
then I get xfeatures2d printed .
The output of (first few lines )of help(cv2) is as follows:
"Help on module cv2:
NAME
cv2
FILE
c:\python27\lib\site-packages\cv2.pyd
SUBMODULES
Error
aruco
bgsegm
bioinspired
datasets
detail
face
fisheye
flann
line_descriptor
ml
motempl
ocl
ogl
optflow
ppf_match_3d
rgbd
text
videostab
xfeatures2d
ximgproc
xphoto
CLASSES
exceptions.Exception(exceptions.BaseException)
error
class error(exceptions.Exception)
| Method resolution order:
| error
| exceptions.Exception
| exceptions.BaseException
| __builtin__.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object (if defined)
|
| ----------------------------------------------------------------------
| Methods inherited from exceptions.Exception:
|
| __init__(...)
| x.__init__(...) initializes x; see help(type(x)) for signature
|
| ----------------------------------------------------------------------
| Data and other attributes inherited from exceptions.Exception:
|
| __new__ = <built-in method __new__ of type object>
| T.__new__(S, ...) -> a new object with type S, a subtype of T
|
| ----------------------------------------------------------------------
| Methods inherited from exceptions.BaseException:
|
| __delattr__(...)
| x.__delattr__('name') <==> del x.name
|
| __getattribute__(...)
| x.__getattribute__('name') <==> x.name
|
| __getitem__(...)
| x.__getitem__(y) <==> x[y]
|
| __getslice__(...)
| x.__getslice__(i, j) <==> x[i:j]
|
| Use of negative indices is not supported.
|
| __reduce__(...)
|
| __repr__(...)
| x.__repr__() <==> repr(x)
|
| __setattr__(...)
| x.__setattr__('name', value) <==> x.name = value
|
| __setstate__(...)
|
| __str__(...)
| x.__str__() <==> str(x)
|
| __unicode__(...)
|
| ----------------------------------------------------------------------
| Data descriptors inherited from exceptions.BaseException:
|
| __dict__
|
| args
|
| message
FUNCTIONS
AKAZE_create(...)
AKAZE_create([, descriptor_type[, descriptor_size[, descriptor_channels[, threshold[, nOctaves[, nOctaveLayers[, diffusivity]]]]]]]) -> retval
AgastFeatureDetector_create(...)
AgastFeatureDetector_create([, threshold[, nonmaxSuppression[, type]]]) -> retval
BFMatcher(...)
BFMatcher([, normType[, crossCheck]]) -> <BFMatcher object>
BOWImgDescriptorExtractor(...)
BOWImgDescriptorExtractor(dextractor, dmatcher) -> <BOWImgDescriptorExtractor object>
BOWKMeansTrainer(...)
BOWKMeansTrainer(clusterCount[, termcrit[, attempts[, flags]]]) -> <BOWKMeansTrainer object>
BRISK_create(...)
BRISK_create([, thresh[, octaves[, patternScale]]]) -> retval or BRISK_create(radiusList, numberList[, dMax[, dMin[, indexChange]]]) -> retval
CamShift(...)
CamShift(probImage, window, criteria) -> retval, window
Canny(...)
Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient]]]) -> edges
CascadeClassifier(...)
CascadeClassifier([filename]) -> <CascadeClassifier object>
CascadeClassifier_convert(...)
CascadeClassifier_convert(oldcascade, newcascade) -> retval"
Any ideas on what I am missing or doing wrong will be very helpful.
i don't think, anything is wrong with your build (congratulations, btw :).
aruco, bgsegm, xfeatures2d, etc. are submodules , similar to a namespace in c++, they are not 'callable'.
to use e.g. SIFT, you would write:
sift = cv2.xfeatures2d.SIFT_create()
.to make a dir listing, like you tried before :
also:
last, please do not alias cv2 as cv, this will only confuse people, because there was a different cv module in the past
Thank you for your inputs :). It made me realise everything on the opencv side is fine. There was an issue in using cv2.xfeatures2d in my pydev settings in eclipse. After adding cv2 to forced builtins I was able to use cv2.xfeatures2d