Ask Your Question
2

function "drawKeypoints" do not work in openCV 4.0.1

asked 2019-01-12 12:11:19 -0500

kurt_alex gravatar image

I want to use the drawKeypoints function in openCV 4.0.1, but Python writes an error:

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

Maybe the latest version of openCV uses a different function, tell me if you know. Yes, in extreme cases, you can use version 2.4 in which this function is present, but I would like to use the latest version

edit retag flag offensive close merge delete

Comments

1

No I don't think so doc is here

Show us your code

LBerger gravatar imageLBerger ( 2019-01-12 12:26:45 -0500 )edit

cv2.drawKeypoints but not cv2.cv2.drawKeypoints

supra56 gravatar imagesupra56 ( 2019-01-12 12:48:23 -0500 )edit

I use it "cv2.drawKeypoints" example:

blank = np.zeros((1, 1))
blobs = cv2.drawKeypoints(image, keypoints, blank, (0, 0, 255),
                          cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
number_of_blobs = len(keypoints)
text = "Total Number of Blobs: " + str(len(keypoints))
cv2.putText(blobs, text, (20, 550), cv2.FONT_HERSHEY_SIMPLEX, 1, (100, 0, 255), 2)

And I don't now why pycharm show me this: "AttributeError: module 'cv2.cv2' has no attribute 'drawKeypoints'"

kurt_alex gravatar imagekurt_alex ( 2019-01-12 14:17:58 -0500 )edit

OIC, that you are using pycham. I suggested you attempt example from LBerger in below. Use named parameter for pycharm.

supra56 gravatar imagesupra56 ( 2019-01-12 22:05:26 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2019-01-22 08:15:31 -0500

supra56 gravatar image

updated 2019-01-22 08:17:48 -0500

Try this:

(kps5, descs5) = cv2.BRISK_create(10).detectAndCompute(gray,None)
cv2.drawKeypoints(gray,
                     kp,
                     None,
                     flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
edit flag offensive delete link more

Comments

@supra56, ARE you using 4.0.1 ? (imho this is a version specific issue, probably related to "named enums")

berak gravatar imageberak ( 2019-01-22 08:25:09 -0500 )edit
1

@berak. Yes.

supra56 gravatar imagesupra56 ( 2019-01-22 08:44:18 -0500 )edit

This may not work in pycharm

supra56 gravatar imagesupra56 ( 2019-01-22 08:48:42 -0500 )edit
1

@berak. I haven't attempted OpencvVINO. Too early for me.

supra56 gravatar imagesupra56 ( 2019-01-22 08:54:39 -0500 )edit

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'

there seems to be a fix here but it's only in master (4.0.1)

berak gravatar imageberak ( 2019-01-27 08:08:48 -0500 )edit
0

answered 2019-01-21 23:10:11 -0500

inzi gravatar image

I too have this issue - using 4.0.1-openvino

my code:

import cv2
import numpy as np

img = cv2.imread('image1.jpg')
img_brisk = img.copy()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

brisk = cv2.BRISK_create()

(kps5, descs5) = brisk.detectAndCompute(gray, None)
cv2.DrawMatchesFlags_DRAW_RICH_KEYPOINTS
cv2.drawKeypoints(gray, kps5, img_brisk, kps5, flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

cv2.namedWindow('Test', cv2.WINDOW_NORMAL)
cv2.imshow('Test', img_brisk)
cv2.resizeWindow('Test', 600,600)

k = cv2.waitKey(0) & 0xFF

if k == 27:         # wait for ESC key to exit
  cv2.destroyAllWindows()
else:
  print("Exit")

Not sure what I'm doing wrong, either.

edit flag offensive delete link more

Comments

1

@inzi, please do NOT post answers here, if you have a question or a comment, thank you .

berak gravatar imageberak ( 2019-01-22 01:18:08 -0500 )edit
berak gravatar imageberak ( 2019-01-27 05:08:48 -0500 )edit
0

answered 2019-01-12 15:18:15 -0500

LBerger gravatar image

updated 2019-01-24 15:49:23 -0500

Ok I can reproduce your error . Use named parameter :

t= cv2.drawKeypoints(image,p, outImage=blank, color=(0, 0, 255),
                          flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

Reference https://www.python.org/dev/peps/pep-3...

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2019-01-12 12:11:19 -0500

Seen: 3,015 times

Last updated: Jan 24