无法在OpenCV中使用SURF,SIFT [英] Can't use SURF, SIFT in OpenCV
问题描述
我正在尝试一个简单的事情
I'm trying a simple thing like
detector = cv2.SIFT()
并得到这个严重的错误
detector = cv2.SIFT()
AttributeError: 'module' object has no attribute 'SIFT'
我不明白,因为安装了cv2.
I do not understand that because cv2 is installed.
cv2.__version__
是
$Rev: 4557 $
我的系统是Ubuntu 12.04.
My system is Ubuntu 12.04.
也许有人遇到了同样的问题,可以为我提供帮助.
Maybe someone has got the same problem and could help me.
长话短说, testypypypypy.py :
import cv2
detector = cv2.SIFT()
错误:
Traceback (most recent call last):
File "testypypy.py", line 3, in <module>
detector = cv2.SIFT()
AttributeError: 'module' object has no attribute 'SIFT
如果我使用SURF
,那么它会起作用,因为SURF
在dir(cv2)
中,但是如果我也使用cv2.BFMatcher()
,则会遇到相同的错误...因此它丢失了,我必须添加它,但是我没有知道怎么做.
If I take SURF
it works because SURF
is in dir(cv2)
but if I also take cv2.BFMatcher()
I get the same error... So it's missing and I have to add it but I don't know how.
推荐答案
我认为这与正确"的方法相去甚远(Ubuntu上的正确"方法似乎要坚持下去,并且/或者过时的OpenCV),但对我来说,从源代码构建opencv-2.4.6.1会带回cv2.SIFT和cv2.SURF.
I think this is far from the "correct" way to do it (the "correct" way on Ubuntu seems to be to stick to a broken and/or outdated OpenCV), but for me building opencv-2.4.6.1 from source brings back cv2.SIFT and cv2.SURF.
步骤:
- 从 opencv.org 下载opencv-2.4.6.1.tar.gz.
-
提取来源:
- Download opencv-2.4.6.1.tar.gz from opencv.org.
Extract the source:
tar -xf opencv-2.4.6.1.tar.gz -C /tmp
配置源.这将告诉OpenCV安装到主目录中的.opencv-2.4.6.1:
Configure the source. This will tell OpenCV to install into .opencv-2.4.6.1 in your home directory:
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D BUILD_PYTHON_SUPPORT=ON \
-D WITH_XINE=ON \
-D WITH_OPENGL=ON \
-D WITH_TBB=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_NEW_PYTHON_SUPPORT=ON \
-D WITH_V4L=ON \
-D CMAKE_INSTALL_PREFIX=~/.opencv-2.4.6.1 \
/tmp/opencv-2.4.6.1
构建并安装:
Build and install:
cd /tmp/opencv-2.4.6.1
make -j4
make install
设置PYTHONPATH(这在bash中有效,我对其他shell毫无头绪):
Set PYTHONPATH (this works in bash, I have no clue about other shells):
export PYTHONPATH=~/.opencv-2.4.6.1/lib/python2.7/dist-packages
现在,如果我启动python并导入cv2(对我来说,这会产生gnome-keyring警告),则我有cv2.SIFT和cv2.SURF可用.
Now if I start python and import cv2 (for me, this produces a gnome-keyring warning), I have cv2.SIFT and cv2.SURF available.
这篇关于无法在OpenCV中使用SURF,SIFT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!