从OpenCV Python中的ORB生成的关键点中提取像素值

时间:2015-01-08 00:17:11

标签: python opencv

我使用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) 

现在,当我查看kpdes的存储值时,我看到了这一点:

>>> 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)。当我在调试器监视窗口中调出kp时(见下图)我看到我列为pt后的像素值。我可以用什么代码来获取这些值?

Snapshot of PyCharm Editor Watch Window

1 个答案:

答案 0 :(得分:1)

doc开始,我了解您的des变量包含关键点的描述符。这些描述符的灵感来自Brief算法(ORB paper)。

至于获取KeyPoint的属性,就像对任何Python对象一样:

for keypoint in kp:
    print(keypoint.angle)
    print(keypoint.class_id)
    # ...
相关问题