Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Brisk keypoints with less keypoints in Python

I have the following code in python

import cv2
import numpy as np

def save_keypoints(image_path, type_image):
    img = cv2.imread(image_path)
    gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    kp, descriptors =cv2.BRISK_create(10).detectAndCompute(gray,None)
    mg=cv2.drawKeypoints(gray, kp, None, 
    flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
    cv2.imwrite('brisk_keypoints-'+ type_image+'.jpg',mg)

if __name__=="__main__":
    save_keypoints("original.bmp" ,"original")
    save_keypoints("fake600.bmp" ,"fake600")
    save_keypoints("fake1200.bmp" ,"fake1200")
    save_keypoints("fake2400.bmp" ,"fake2400")

Basically, the code will save an image with BRISK keypoints detected. However, here are the results of applying this code in four images:

enter image description hereenter image description hereenter image description hereenter image description here

Although the images are different (I can easily discriminate them using these BRISK descriptors in a bag of visual words approach), it seems that the keypoints detected in all these four images are visually the same or maybe the high number of concentric circles are confusing the viewer. How can I reduce the number of keypoints shown in such a way that I can see how these images are different through these descriptors?

like image 838
mad Avatar asked Jan 21 '26 02:01

mad


1 Answers

The ideal answer would be as @Silencer suggested to filter the Keypoints. There are several ways you can achieve that. If you debug, you can see what information is contained in the ndarray Keypoints. The information should be something like this. So, using this, you can either sort the Keypoints based on the response (I'd suggest to start with that) or with the coordinates of the Keypoints. Response is basically how-good the Keypoint is, roughly speaking, how good is the corner-ness of the particular Keypoint.

For example:

Based on index

keypoints = detector.detect(frame) #list of keypoints
x = keypoints[i].pt[0] #i is the index of the Keypoint you want to get the position
y = keypoints[i].pt[1]

This you can use in a lamda expression (and not a loop) or a numpy function for fast optimization. Similarly, for response, you can do:

res = keypoints[i].response

I have seen responses from 31 to 320 for BRISK but you have to find the best value for your image.

Hope it helps!

like image 91
Rick M. Avatar answered Jan 23 '26 15:01

Rick M.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!