Ask Your Question
0

errors on running FAST algorithm on corner detection

asked 2016-09-28 01:39:46 -0600

SB gravatar image

updated 2016-09-28 01:52:16 -0600

berak gravatar image

Could any one provide a example python script to test FAST algorithm on corner detection?

When I run below example python script from opencv-python tutorial, I get a error "TypeError: Required argument 'outImage' (pos 3) not found"

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

img = cv2.imread('Penguins.jpg',0)

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

# find and draw the keypoints
kp = fast.detect(img,None)
img2 = cv2.drawKeypoints(img, kp, color=(255,0,0))

# Print all default params
print "Threshold: ", fast.getInt('threshold')
print "nonmaxSuppression: ", fast.getBool('nonmaxSuppression')
print "neighborhood: ", fast.getInt('type')
print "Total Keypoints with nonmaxSuppression: ", len(kp)

cv2.imwrite('fast_true.png',img2)

# Disable nonmaxSuppression
fast.setBool('nonmaxSuppression',0)
kp = fast.detect(img,None)

print "Total Keypoints without nonmaxSuppression: ", len(kp)

img3 = cv2.drawKeypoints(img, kp, color=(255,0,0))

cv2.imwrite('fast_false.png',img3)
edit retag flag offensive close merge delete

Comments

1

I would suggest you for this and other posts in the future, that you use the function to highlight code in your question. It is not easy to read a post without it.

Vintez gravatar imageVintez ( 2016-09-28 01:48:24 -0600 )edit

where did you find that example ? i'm pretty sure, i fixed it lately, see here

berak gravatar imageberak ( 2016-09-28 01:53:38 -0600 )edit
1

Thanks Berak,

I run the example from the link you provided. There is a issue on print out threshold. Below is the error: AttributeError: 'cv2.FastFeatureDetector' object has no attribute 'getInt'

Could you kindly let me know the solution?

SB gravatar imageSB ( 2016-09-28 11:23:32 -0600 )edit

oh, right. thanks for the notice.

(you probably need to comment out the whole "print ..." block for now)

but again, your issue was about drawKeypoints, right ?

berak gravatar imageberak ( 2016-09-28 11:39:39 -0600 )edit

well yea, no idea, how that slipped, but it's fast.getThreshold(), fast.getNonmaxSuppression(), etc, now.

try a : help(fast) , and see yourself !

berak gravatar imageberak ( 2016-09-28 11:49:24 -0600 )edit

I do comment out all print. The original issue is about drawKeypoints. After fixing the issue about drawKeypoints. It is observed that several function from FastFeatureDetector_create, such as getInt() and setBool() does not work.

Let me know if you have some ideas about it.

Thanks

SB gravatar imageSB ( 2016-09-28 11:50:59 -0600 )edit
1

It works after changing it as below:

print "Threshold: ", fast.getThreshold()

Thanks

SB gravatar imageSB ( 2016-09-28 11:55:45 -0600 )edit

remember me to fix the docs sample !

berak gravatar imageberak ( 2016-09-28 12:04:07 -0600 )edit

Hi When I run this example on Python 2.7.14-x64. The following error is shown.


Traceback (most recent call last): File "fast.py", line 9, in <module> kp = fast.detect(img,None)

TypeError: Incorrect type of self (must be 'Feature2D' or its derivative)

Could anyone help me to fix it? Other PC with Same python version tun OK without this.

JackCha gravatar imageJackCha ( 2018-05-07 20:38:03 -0600 )edit

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

berak gravatar imageberak ( 2018-05-07 20:42:39 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2019-01-09 20:41:55 -0600

vasiliyx gravatar image

updated 2019-01-09 21:13:57 -0600

This works on CV '3.4.5', Python 3.6.1

# Load image
img = cv.imread(myImagePath);
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY);

# Initiate FAST object with default values
fast = cv.FastFeatureDetector_create();

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

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


# Disable nonmaxSuppression
fast.setNonmaxSuppression(False);
kp = fast.detect(gray,None);
print("Total Keypoints without nonmaxSuppression: ", len(kp));

# Output the points on the mats
img2 = cv2.drawKeypoints(img, kp, None, color=BLUE)
img3 = cv2.drawKeypoints(img, kp, None, color=BLUE);

# Show the mats
cv.imshow("img1", img); # Original mat
cv.imshow("img2", img2); # With nonmaxSuppression
cv.imshow("img3", img3); # Without nonmaxSuppression
cv.waitKey();
edit flag offensive delete link more
0

answered 2016-09-28 01:55:53 -0600

berak gravatar image

the output image is mandatory, so it has to be:

img3 = cv2.drawKeypoints(img, kp, None, color=(255,0,0))

(None, to create an empty image internally)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-09-28 01:39:46 -0600

Seen: 3,487 times

Last updated: Jan 09 '19