Ask Your Question
2

drawKeypoints bug?

asked 2019-01-23 20:19:33 -0600

updated 2019-01-24 15:07:43 -0600

Hi! I'm trying to learn some Opencv with Python, and I'm following illustrations/examples from a book, and I'm stuck because of what seems to be a bug. It says " AttributeError: module 'cv2.cv2' has no attribute 'drawKeypoints' "

I'm using native Python 3.6.6 on windows 7, 64bit. I installed Opencv3 with pip. The OpenCv version I'm using is 4.0.0. The book I'm trying to learn from is called OpenCV 3x with Python By Example Second Edition. And it's written by Gabriel Garrido.

I've reinstalled OpenCv, without success...I also tried some suggestion about installing Opencv-contrib module (or something like that), and it didn't do any differences or whatsoever.

I've also attached a link with a picture of the code that gives me the error, so I hope the picture is available by the time this post is accepted by a mod! ^^

So is this a bug or something like that in OpenCv, or is cv2.drawKeypoints(input_image, keypoints, input_image, color=(0,255,0)) this just an incorrect use of the drawKeypoints function?

[Edit] So here's the result of print(cv2.getBuildInformation()) :

General configuration for OpenCV 4.0.0 =====================================
  Version control:               4.0.0

  Platform:
    Timestamp:                   2019-01-09T18:51:15Z
    Host:                        Windows 6.3.9600 AMD64
    CMake:                       3.12.2
    CMake generator:             Visual Studio 14 2015 Win64
    CMake build tool:            C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
    MSVC:                        1900

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (5 files):          + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (11 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

  C/C++:
    Built as dynamic libs?:      NO
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe  (ver 19.0.
24241.7)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D
 _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi      /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP2   /MT /O2 /Ob2 /
DNDEBUG
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D
 _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi      /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP2   /MTd /Zi /Ob0
/Od /RTC1
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SC
L_SECURE_NO_WARNINGS /Gy /bigobj /Oi        /MP2    /MT /O2 /Ob2 /DNDEBUG
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SC
L_SECURE_NO_WARNINGS /Gy /bigobj /Oi        /MP2  /MTd /Zi /Ob0 /Od /RTC1
    Linker flags (Release):      /machine:x64  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NO
DEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
    Linker flags (Debug):        /machine:x64  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib
/NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          ade ...
(more)
edit retag flag offensive close merge delete

Comments

can you show us your code ? Have you got same problem with this code if you use

t= cv2.drawKeypoints(input_image, keypoints, outImage=input_image, color=(0,255,0),
                          flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
LBerger gravatar imageLBerger ( 2019-01-24 01:51:36 -0600 )edit

First of all, thanks for trying to help me!

import cv2
import numpy as np

def draw_keypoints(vis, keypoints, color = (0, 255, 255)):
    for kp in keypoints:
        x, y = kp.pt
        cv2.circle(vis, (int(x), int(y), 2, color))

input_image = cv2.imread('D:/Downloads/OpenCV_3X_With_Python_By_Example_SecondEdition Codes/OpenCV3xwithPythonByExample_Code/Chapter05/images/fishing_house.jpg')
gray_image = cv2.cvtColor(input_image, cv2.COLOR_BGR2GRAY)

orb = cv2.ORB_create()

keypoints = orb.detect(gray_image, None)

keypoints, descriptor = orb.compute(gray_image, keypoints)

t= cv2.drawKeypoints(input_image, keypoints, outImage=input_image, color=(0,255,0),
                          flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

cv2.imshow('ORB keypoints', input_image)
cv2.waitKey()
MasterChenSensei gravatar imageMasterChenSensei ( 2019-01-24 11:28:29 -0600 )edit

And I tried your suggestion LBerger, but I still get the very same error.

MasterChenSensei gravatar imageMasterChenSensei ( 2019-01-24 11:31:44 -0600 )edit

With my code I cannot reproduce your bug (python 3.6 opencv4..0.1). Now can you insert in your question print(cv2.getBuildInformation())

LBerger gravatar imageLBerger ( 2019-01-24 12:17:23 -0600 )edit

When I put it in my code, I still got the very same error, so I simply ran it in a terminal, and it showed lots of things. Anything specific I should look for?

MasterChenSensei gravatar imageMasterChenSensei ( 2019-01-24 13:29:27 -0600 )edit

insert all in your post as here

LBerger gravatar imageLBerger ( 2019-01-24 13:31:27 -0600 )edit

Sadly can't post the code right now, the website says:

New users must wait 2 days to answer own questions. You can post an answer tomorrow
MasterChenSensei gravatar imageMasterChenSensei ( 2019-01-24 14:08:23 -0600 )edit
1

edit your question : don't need to post an answer

LBerger gravatar imageLBerger ( 2019-01-24 14:24:08 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-01-24 15:45:15 -0600

LBerger gravatar image

updated 2019-01-24 16:02:22 -0600

I think there is a bug in opencv-python==4.0.0.21 (pip install) If I use opencv-python====3.4.5.20 ((pip install)) there is no problem with your code

Now I cannot reproduce your bug on my computer using my own version of opencv-python

I think we need that someone could confirm my answer @berak ?

Issue https://github.com/skvark/opencv-pyth... and https://github.com/opencv/opencv/issu...

PS please don't forget to check image is not None when you use imread

edit flag offensive delete link more

Comments

2

Alright! And once again, thank you very much for your help! :)

MasterChenSensei gravatar imageMasterChenSensei ( 2019-01-24 15:59:35 -0600 )edit

It is not drawKeypoints. The bugs is coming from orb.compute and orb.detectAndCompute. If comment out. It will work. Otherwise, you will have to write extra code such as mask, x2features, BFmatcher, etc. There is bug under OpenCV 4.0.1. but uncertainly about OpenCV 4.0.0

supra56 gravatar imagesupra56 ( 2019-01-25 08:25:55 -0600 )edit
LBerger gravatar imageLBerger ( 2019-01-25 09:56:33 -0600 )edit
1

@LBerger --

i just updated via pip to 4.0.0, and encounter the same problem:

>>> cv2.__version__
'4.0.0'
>>> help(cv2.drawKeypoints)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2.cv2' has no attribute 'drawKeypoints'

(no problem with previous 3.4.3)

berak gravatar imageberak ( 2019-01-28 00:29:21 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-23 20:03:50 -0600

Seen: 1,291 times

Last updated: Jan 24 '19