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

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

Snapshot of PyCharm Editor Watch Window

最佳答案

来自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/

相关文章:

java - 如何从 OpenCV Java 中的 HoughLines 变换中检测矩形

matlab - 从 OpenCV (C++) for Matlab 以 double 保存矩阵

python - 为什么每次保存模型时哈希值都会改变?

python - 使用一组过滤器在给定区域中最新的 AMI ID

Python和ftplib,无法登录?

python - pandas ExcelWriter 从右到左写入工作表

python - 使用 lxml 在根元素之前/之后添加或追加 PI

opencv - 使用 CMake 交叉编译 OpenCV 与 MinGW(在 Linux for Windows 中)

python - 计算二维数组中跨区域的平均值

opencv - 获取帧序列的平均值