Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 绘制筛选关键点_Python_Opencv - Fatal编程技术网

Python 绘制筛选关键点

Python 绘制筛选关键点,python,opencv,Python,Opencv,我正在使用SIFT关键点提取器/描述符在图像上提取和绘制关键点,如下代码所示: import cv2 as cv img = cv.imread("my_img.jpg") sift = cv.SIFT_create() (keypoints, descriptors) = sift.detectAndCompute(img,None) img_kp=cv.drawKeypoints(img,kp,cv.DRAW_MATCHES_FLAGS_DEFAULT,color=(1

我正在使用SIFT关键点提取器/描述符在图像上提取和绘制关键点,如下代码所示:

import cv2 as cv 
img = cv.imread("my_img.jpg")
sift = cv.SIFT_create()
(keypoints, descriptors) = sift.detectAndCompute(img,None)
img_kp=cv.drawKeypoints(img,kp,cv.DRAW_MATCHES_FLAGS_DEFAULT,color=(120,157,187))
cv.imwrite("img.jpg", img_kp)

上面的代码将关键点绘制为橙色圆圈,如何将每个关键点的表示形式更改为橙色“+”符号


非常感谢您的帮助

一个简单的解决方案可能是:迭代所有关键点并使用绘制一个“+”符号

下面是一个代码示例:

import numpy as np
import cv2


def draw_cross_keypoints(img, keypoints, color):
    """ Draw keypoints as crosses, and return the new image with the crosses. """
    img_kp = img.copy()  # Create a copy of img

    # Iterate over all keypoints and draw a cross on evey point.
    for kp in keypoints:
        x, y = kp.pt  # Each keypoint as an x, y tuple  https://stackoverflow.com/questions/35884409/how-to-extract-x-y-coordinates-from-opencv-cv2-keypoint-object

        x = int(round(x))  # Round an cast to int
        y = int(round(y))

        # Draw a cross with (x, y) center
        cv2.drawMarker(img_kp, (x, y), color, markerType=cv2.MARKER_CROSS, markerSize=5, thickness=1, line_type=cv2.LINE_8)

    return img_kp  # Return the image with the drawn crosses.


img = cv2.imread("my_img.jpg")
sift = cv2.SIFT_create()
(keypoints, descriptors) = sift.detectAndCompute(img, None)
#img_kp = cv2.drawKeypoints(img, keypoints, cv2.DRAW_MATCHES_FLAGS_DEFAULT, color=(120,157,187))
img_kp = draw_cross_keypoints(img, keypoints, color=(120,157,187))  # Draw keypoints as "+" signs
cv2.imwrite("img.jpg", img_kp)

样本结果:


十字和圆圈-用于测试:

如您所见,“+”符号位于圆圈的中心