OpenCV - 仅显示关键点而不是使用SIFT的图像 [英] OpenCV - Display ONLY the keypoints NOT the image using SIFT

查看:474
本文介绍了OpenCV - 仅显示关键点而不是使用SIFT的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此示例代码绘制关键点(不带图像):

I am trying to only draw the keypoints (without the image) using this example code:

import cv2
import numpy as np

img = cv2.imread('test.png')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

sift = cv2.SIFT()
kp = sift.detect(gray,None)

img=cv2.drawKeypoints(gray,kp)

cv2.imwrite('sift_keypoints.jpg',img)

我试过 cv2.drawKeypoints(None,kp) cv2.drawKeypoints(kp)但无济于事。

如何实现这一目标?

谢谢。

推荐答案

您可以通过在原始图像具有 SAME 形状的纯黑图像上绘制关键点。

You can get ONLY the keypoints by drawing them on a solid black image having the SAME shape of your original image.

这是我用的图像:

然后我获得了关键点:

I then obtained the keypoints:

然后我创建了纯色图像(黑色)具有相同尺寸的原始图像并在其上绘制这些关键点。

Then I created an image of solid color(black) having same size of the original image and draw these keypoints on them.

Voila ONLY关键点

Voila ONLY keypoints

代码:

#---Creating image of solid color with same size as image---
mask = np.zeros((img.shape[0], img.shape[1], 3), np.uint8)
mask[:] = (0, 0, 0) 

#---Drawing keypoints on the mask image---
fmask = cv2.drawKeypoints(mask,kp,None,color=(0,255,0), flags=0)
cv2.imshow('fmask.jpg', fmask)

这篇关于OpenCV - 仅显示关键点而不是使用SIFT的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆