简体   繁体   English

在 Python 中用较少的关键点显示 Brisk 关键点

[英]Show Brisk keypoints with less keypoints in Python

I have the following code in python我在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.基本上,代码将保存检测到 BRISK 关键点的图像。 However, here are the results of applying this code in four images:但是,以下是在四个图像中应用此代码的结果:

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

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.尽管图像不同(我可以在视觉词袋方法中使用这些 BRISK 描述符轻松区分它们),但似乎在所有这四个图像中检测到的关键点在视觉上是相同的,或者可能大量的同心圆混淆了观众。 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?如何减少显示的关键点数量,以便我可以通过这些描述符查看这些图像的不同之处?

The ideal answer would be as @Silencer suggested to filter the Keypoints .理想的答案是@Silencer 建议过滤Keypoints There are several ways you can achieve that.有几种方法可以实现这一目标。 If you debug, you can see what information is contained in the ndarray Keypoints .如果调试,你可以看到什么样的信息包含在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 .因此,使用此,您可以排序的Keypoints基于响应(我建议先从能),或者使用的坐标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.您可以在 lamda 表达式(而不是循环)或 numpy 函数中使用它以进行快速优化。 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.我看到 BRISK 的回复从 31 到 320,但您必须为您的形象找到最佳价值。

Hope it helps!希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM