繁体   English   中英

可视化 OpenCV 关键点

[英]Visualizing OpenCV KeyPoints

我正在学习 OpenCV,目前我正在尝试了解存储在KeyPoint的基础数据,以便我可以更好地将这些数据用于我正在处理的应用程序。

到目前为止,我一直在浏览这两页:

http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_feature_detectors.html?highlight=featuredetector#FeatureDetector

http://docs.opencv.org/doc/tutorials/features2d/feature_detection/feature_detection.html

但是,当我按照教程使用drawKeypoints() ,这些点的大小和形状都相同,并且使用看似任意的颜色绘制。

我想我可以遍历每个关键点的属性:画一个圆圈,画一个箭头(用于角度),根据响应给它一个颜色,等等。但我认为必须有更好的方法。

是否有一个内置的方法或其他方法类似drawKeypoints()这将帮助我更有效地可视化的KeyPoints的图像?

是的,有执行任务的方法。 正如文档中所说

对于每个关键点,将绘制关键点周围具有关键点大小和方向的圆圈

如果您使用的是 Java,您可以简单地指定关键点的类型:

Features2d.drawKeypoints(image1, keypoints1, imageOut2,new Scalar(2,254,255),Features2d.DRAW_RICH_KEYPOINTS);

在 C++ 中:

drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );

我有一个类似的问题,想自定义绘制的点,决定分享我的解决方案,因为我想改变绘制的点的形状。

您可以根据需要更改 cv2.circle 的行。 im 是要绘制点的输入图像,keyp 是要绘制的关键点,col 是线条颜色,th 是圆边缘的粗细。

import cv2
import numpy as np
import matplotlib.pyplot as plt

def drawKeyPts(im,keyp,col,th):
    for curKey in keyp:
        x=np.int(curKey.pt[0])
        y=np.int(curKey.pt[1])
        size = np.int(curKey.size)
        cv2.circle(im,(x,y),size, col,thickness=th, lineType=8, shift=0) 
    plt.imshow(im)    
    return im    

imWithCircles = drawKeyPts(origIm.copy(),keypoints,(0,255,0),5)

您可以遍历检测到的关键点向量,并在每个KeyPoint.pt上绘制(例如)一个圆,其半径类似于KeyPoint.size和相对于KeyPoint.response 的颜色。这当然只是一个示例; 您可以根据 KeyPoint 的倍频程和角度编写更复杂的绘图函数(如果您的检测器提供该输出)。

希望这可以帮助。

你好,这是我的代码@Alex

def drawKeyPts(im, keyp, col, th):
    draw_shift_bits = 4
    draw_multiplier = 1 << 4
    LINE_AA = 16
    im = cv2.cvtColor(im, cv2.COLOR_GRAY2BGR)
    for curKey in keyp:
        center = (int(np.round(curKey.pt[0]*draw_multiplier)), int(np.round(curKey.pt[1]*draw_multiplier)))
        radius = int(np.round(curKey.size/2*draw_multiplier))
        cv2.circle(im, center, radius, col, thickness=th, lineType=LINE_AA, shift=draw_shift_bits)
        if(curKey.angle != -1):
            srcAngleRad = (curKey.angle * np.pi/180.0)
            orient = (int(np.round(np.cos(srcAngleRad)*radius)), int(np.round(np.sin(srcAngleRad)*radius)))
            cv2.line(im, center, (center[0]+orient[0], center[1]+orient[1]), col, 1, LINE_AA, draw_shift_bits)
    cv2.imshow('name1', im)
    cv2.waitKey()
    return im

暂无
暂无

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

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