Pregunta

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)

I tried cv2.drawKeypoints(None,kp)and cv2.drawKeypoints(kp) but to no avail.

Any ideas how this could be achieved ?

Thanks.

¿Fue útil?

Solución

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

This is the image I used:

enter image description here

I then obtained the keypoints:

enter image description here

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

enter image description here

Voila ONLY keypoints

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)

Otros consejos

OpenCV does not have any method to draw the keypoints alone.This is the code i used to find SIFT keypoints.

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);
}       

}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top