Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with cv2.drawKeypoints in version 4.0.0.21 #168

Closed
LaurentBerger opened this issue Jan 24, 2019 · 16 comments

Comments

Projects
None yet
9 participants
@LaurentBerger
Copy link

commented Jan 24, 2019

system windows 10 msvc 2017 python 3.6.6

Hi,

It seems that some users have got some problem with drawKeypoints (http://answers.opencv.org/question/206950/function-drawkeypoints-do-not-work-in-opencv-401/ and http://answers.opencv.org/question/207758/drawkeypoints-bug/) using this code

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('lena.jpg')
if input_image is None:
    print("check file path")
    exit()
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()

Error is AttributeError: module 'cv2.cv2' has no attribute 'drawKeypoints'

If i use my own version opencv-python there is no problem. Something is wrong but what ?

may be opencv/opencv#10250

@LaurentBerger LaurentBerger changed the title Problem withcv2.drawKeypoints in version 4.0.0.21 Problem with cv2.drawKeypoints in version 4.0.0.21 Jan 24, 2019

@skvark

This comment has been minimized.

Copy link
Owner

commented Jan 25, 2019

This seems to be a bug in the binding generators in the upstream? You will have to wait that I have time to make a release for version 4.0.1 as it seems that the bug was fixed between 4.0.0 and 4.0.1 releases.

@skvark skvark closed this Jan 25, 2019

@LaurentBerger

This comment has been minimized.

Copy link
Author

commented Jan 25, 2019

Yes it is fixed now. Some users wait the new release. As moderator on answers.opencv.org I can give an explanation.

Thanks

@woctezuma

This comment has been minimized.

Copy link

commented Feb 5, 2019

Thanks for your work on opencv-python.

I encounter the same issue.

In the meantime, I have worked around the issue by editing my code: I have replaced each call to drawKeypoints() with several calls to drawMarker().

For instance, in the tutorial:

img2 = cv.drawKeypoints(img, kp, None, color=(0,255,0), flags=0)
plt.imshow(img2), plt.show()

with:

img2 = img.copy()
for marker in kp:
	img2 = cv.drawMarker(img2, tuple(int(i) for i in marker.pt), color=(0, 255, 0))
plt.imshow(img2), plt.show()
@skvark

This comment has been minimized.

Copy link
Owner

commented Feb 5, 2019

This issue should be fixed in 4.0.1 but unfortunately I cannot release 4.0.1 before macOS build issues have been solved.

@Stephanehk

This comment has been minimized.

Copy link

commented Feb 8, 2019

Do you know when 4.0.1 might be released? Thanks

@wipix

This comment has been minimized.

Copy link

commented Feb 9, 2019

Hello ,
I had a question about the version available : when I run pip install opencv-python on my Rpi 3B+ : it installs opencv 3.4 .. but here it's said the current version is 4.0 ( " opencv-python 4.0.0.21 " // https://pypi.org/project/opencv-python/ ) .
(In fact I first tried for 3 days to compil myself a 4.0.0 build, following several tutorials webpage, but without any success .. each time after installing the build/make it says " no module named cv2 found .. " So the only working solution for me is using this ' pip install opencv-python ' )

Could you let me know how to reach this version '4.0.0.21' please ?
Thanks for your work Skvark !

@waveform80

This comment has been minimized.

Copy link

commented Feb 9, 2019

@wipix sorry, that's my fault - I built the opencv-python packages on the RPi but I've been too swamped to finish 4.x recently. I'll try and get the builders working on this next week but if you can't wait that long you'll just have to build it from source for now.

@wipix

This comment has been minimized.

Copy link

commented Feb 10, 2019

Hi Waveform80 , thank your for your response. Ok no problem , happy to hear that it's coming soon ! I'll wait ;) . Thanks for your hard work !

@ra-jamieson

This comment has been minimized.

Copy link

commented Mar 6, 2019

Hi,
Is there any rough ETA on releasing 4.01 with the fix to this drawKeypoints issue?
Like a week, a month, six months?
Thanks for any guidance.

@woctezuma

This comment has been minimized.

Copy link

commented Mar 6, 2019

Just in case someone who needs v4.0.1 on Windows stumbles here and cannot wait for the fix, you can download a .whl file from this repository and install it locally with pip. It is less handy than a PyPI install, but that might help in the meantime.

@skvark

This comment has been minimized.

Copy link
Owner

commented Mar 7, 2019

You can build OpenCV yourself if you need 4.0.1 right now or downgrade opencv-python to 3.4.5. I have been busy lately, but I'll have a look at the macOS Travis environments again during this week. I cannot give any estimates about the release date.

@Vincent-CIRCL

This comment has been minimized.

Copy link

commented Mar 19, 2019

Still the error. Is the 4.0.1 being release, or we still need to build it from source ?

@skvark

This comment has been minimized.

Copy link
Owner

commented Mar 19, 2019

As you can see from the releases page or from PyPI there is no new release. I have very little free time to debug the macOS build issue. Any help is appreciated, especially since I do not own any macOS devices.

@Vincent-CIRCL

This comment has been minimized.

Copy link

commented Mar 19, 2019

Well, not sure if it's for the same reason or it's just me, but I have the issue on Ubuntu 18.XX, so a non-macOS device. :-)
EDIT : Compilation eventually ended, and same problem from source. So my issue may be a false positive.

@skvark

This comment has been minimized.

Copy link
Owner

commented Mar 19, 2019

I mean that the compilation fails in this repository (due to homebrew issues on Travis) on macOS. This drawKeypoints issue should be fixed if you compile OpenCV 4.0.1 manually. I have to release all the builds (Windows, macOS, Linux) simultaneosly to PyPi to avoid breaking millions of installations. There are no build issues currently with Windows or Linux builds.

@joshlynsathish

This comment has been minimized.

Copy link

commented Mar 20, 2019

Below code worked for me after modifying drawKeypoints as suggested by @woctezuma
Thanks 👍

import numpy as np
import cv2
from matplotlib import pyplot as plt

img = cv2.imread('/Images/object3.jpg',0)

# Initiate FAST object with default values
fast = cv2.FastFeatureDetector_create(threshold=25)

# find and draw the keypoints
kp = fast.detect(img, None)

# Print all default params
print ("Threshold: ", fast.getThreshold())
print ("NonmaxSuppression: ", fast.getNonmaxSuppression())
print ("Neighborhood: ", fast.getType())
print ("Total Keypoints with NonmaxSuppression: ", len(kp))

img2 = img.copy()
for marker in kp:
	img2 = cv2.drawMarker(img2, tuple(int(i) for i in marker.pt), color=(0, 255, 0))

cv2.imshow("FAST TRUE", img2)
cv2.imwrite('/Output/fast_true.png',img2)

# Disable nonmaxSuppression
fast.setNonmaxSuppression(0)
kp = fast.detect(img,None)
print ("Total Keypoints without NonmaxSuppression: ", len(kp))

img3 = img.copy()
for marker in kp:
	img3 = cv2.drawMarker(img3, tuple(int(i) for i in marker.pt), color=(0, 255, 0))

cv2.imshow("FAST False", img3)

if cv2.waitKey(0) & 0xFF == ord('q'):
    cv2.imwrite('/Output/fast_false.png',img3)
    cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.