不能在 OpenCV 中使用 SURF、SIFT [英] Can't use SURF, SIFT in OpenCV

查看:57
本文介绍了不能在 OpenCV 中使用 SURF、SIFT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试一个简单的事情

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.

长话短说,testypypypy.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 它会起作用,因为 SURFdir(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.

步骤:

  1. opencv.org 下载 opencv-2.4.6.1.tar.gz.
  2. 提取来源:

  1. Download opencv-2.4.6.1.tar.gz from opencv.org.
  2. 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆