我使用 OpenCV 查找图像中的关键点,这些关键点以矢量形式存储在名为 kp
的变量中。用于此的代码:
#Read image and convert to greyscale
img = cv2.imread(DIR + i,0)
#Resize image to 100 x 100
r_g_img = cv2.resize(img, (100,100))
#Feature extraction
orb = cv2.ORB_create(scaleFactor=2, edgeThreshold=0)
kp = orb.detect(r_g_img,None)
kp,des = orb.compute(r_g_img,kp)
现在,当我查看 kp
和 des
的存储值时,我看到了:
>>> kp
[<KeyPoint 05DA9318>, <KeyPoint 02F7A0C0>, <KeyPoint 02F7A098>, <KeyPoint 02F7ABB0>,...
>>> des
array([[ 89, 4, 163, ..., 14, 116, 98],
[ 17, 93, 81, ..., 184, 112, 173],
[184, 85, 50, ..., 63, 52, 67],
...,
[ 3, 216, 229, ..., 29, 88, 220],
[163, 29, 71, ..., 124, 124, 86],
[102, 92, 166, ..., 126, 244, 124]], dtype=uint8)
我什至不完全确定 des
指的是什么,但我想要的是关键点的像素位置 (x,y)。当我在调试器监 window 口中拉出 kp
时(见下图),我看到我之后列出的像素值作为 pt
。我可以使用什么代码来获取这些值?
最佳答案
来自doc ,我知道您的 des
变量包含关键点的描述符。这些描述符的灵感来自 BRIEF 算法 (ORB paper)。
关于获取 KeyPoint 的属性,就像获取任何 Python 对象一样:
for keypoint in kp:
print(keypoint.angle)
print(keypoint.class_id)
# ...
关于python - 从 OpenCV Python 中 ORB 生成的关键点中提取像素值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27831004/