Ask Your Question
0

SIFT detection with opencv+python

asked 2019-05-27 02:32:46 -0600

gaoyang gravatar image

updated 2019-05-27 07:23:23 -0600

supra56 gravatar image

When I use opencv to sift detection, program always wrong. It show: module 'cv2.cv2' has no attribute 'xfeatures2d'. I had download same version of opencv-python and opencv-contrib-python(3.3.0.10), but don't work. This is part of code:

import cv2
import numpy as np
import sys
imgpath=r'D:\Users\Mr.Gao\Desktop\NewFile\computer vision\varese.jpg'
img=cv2.imread(imgpath)
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
sift=cv2.xfeatures2d.SIFT_create()

I use python 3.5, opencv 3.X

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2019-05-27 02:39:39 -0600

LBerger gravatar image

Please read https://github.com/skvark/opencv-pyth...

It is non-free algorithm. If you need sift in python (or in c++) you have to build opencv_contrib yourself using cmake

edit flag offensive delete link more

Comments

I looked up the solution on the net and said it was ok to install the same version of opencv-python and opencv-contrib-python as before.But it didn't work. And how do I build it by using cmake.

gaoyang gravatar imagegaoyang ( 2019-05-27 02:49:50 -0600 )edit
1

it seems your platform is windows. In python you will need flake8 pylint beautifullsoup bs4 to build opencv python binding from source

In opencv-contrib-python you have opencv-python you shouldn't use both. in your case only opencv-contrib is necessary. All opencv-python function are included in opencv-contrib-python

LBerger gravatar imageLBerger ( 2019-05-27 03:05:41 -0600 )edit

Yes,my platform is windows, but I don't understand 'flake8 pylint beautifullsoup bs4', can you say clearly?

gaoyang gravatar imagegaoyang ( 2019-05-27 03:09:46 -0600 )edit

Do you mean I only use one of the opencv-contrib-python and opencv-python?

gaoyang gravatar imagegaoyang ( 2019-05-27 03:19:49 -0600 )edit

opencv-contrib-python is right answer

supra56 gravatar imagesupra56 ( 2019-05-27 08:32:04 -0600 )edit

I had install it.

gaoyang gravatar imagegaoyang ( 2019-05-27 08:33:32 -0600 )edit
-1

answered 2019-05-27 07:42:07 -0600

supra56 gravatar image

updated 2019-05-27 07:49:58 -0600

For python 3 using windows either pip or pip3: pip install opencv-contrib-python or pip install opencv-contrib-python==3.3.0.10

edit flag offensive delete link more

Comments

I had tried it, but not be used.

gaoyang gravatar imagegaoyang ( 2019-05-27 07:56:25 -0600 )edit

Did you do cmake?

supra56 gravatar imagesupra56 ( 2019-05-27 08:04:07 -0600 )edit

What is cmake? And how should I do?

gaoyang gravatar imagegaoyang ( 2019-05-27 08:06:11 -0600 )edit

U have to rebuild it. try ; print(cv2.getBuildInformation())

supra56 gravatar imagesupra56 ( 2019-05-27 08:08:04 -0600 )edit

You will have to listened to @LBerger's comment. Or otherwise upgrade to OpenCV 4.1.0

supra56 gravatar imagesupra56 ( 2019-05-27 08:10:56 -0600 )edit

I do print(cv2.getBuildInformation()), print some messages, then I how to do. I don't konw how to do with cmake

gaoyang gravatar imagegaoyang ( 2019-05-27 08:13:46 -0600 )edit

cmake is something like this: $ cmake -D CMAKE_BUILD_TYPE=RELEASE \ How did you installed it?

supra56 gravatar imagesupra56 ( 2019-05-27 08:25:56 -0600 )edit

I had install Cmake,thought I don't know which time, Platform: Timestamp: 2018-07-21T16:23:37Z Host: Windows 6.3.9600 AMD64 CMake: 3.11.3 CMake generator: Visual Studio 14 2015 Win64 CMake build tool: C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe MSVC: 1900

gaoyang gravatar imagegaoyang ( 2019-05-27 08:30:20 -0600 )edit

OIC. I don't used Vsiual Studio

supra56 gravatar imagesupra56 ( 2019-05-27 08:36:29 -0600 )edit

I never had problem back in OpenCV 3x. I used python and OpenCV 4.1.0

supra56 gravatar imagesupra56 ( 2019-05-27 08:39:06 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-05-27 02:32:46 -0600

Seen: 3,113 times

Last updated: May 27 '19