OpenCV - 仅使用SIFT显示关键点而不是图像

时间:2014-03-13 10:18:51

标签: opencv image-processing sift keypoint

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

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),但无济于事。

有关如何实现这一目标的任何想法?

感谢。

2 个答案:

答案 0 :(得分:0)

OpenCV没有任何方法可以单独绘制关键点。这是我用来查找SIFT关键点的代码。

import org.opencv.core.*;
import org.opencv.features2d.FeatureDetector;
import org.opencv.features2d.Features2d;
import org.opencv.highgui.*;

import com.atul.JavaOpenCV.Imshow;

public class testdraw 
{
public static void main(String args[])
{

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        Mat img=Highgui.imread("C:\\100.jpg");
        Mat outputImage = new Mat();

        FeatureDetector siftDetector = FeatureDetector.create(FeatureDetector.SIFT);
        MatOfKeyPoint siftKeypoint = new MatOfKeyPoint();

        siftDetector.detect(img,siftKeypoint);
        Features2d.drawKeypoints(img, siftKeypoint, outputImage);

        //Highgui.imwrite("C:\\101.jpg", outputImage);
        Imshow im = new Imshow("Output");
        im.showImage(outputImage);
}       

}

答案 1 :(得分:0)

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

这是我使用的图像:

enter image description here

然后我获得了关键点:

enter image description here

然后我创建了一张与原始图像大小相同的纯色(黑色)图像,并在上面绘制这些关键点。

enter image description here

Voila ONLY关键点

CODE:

#---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)