简体   繁体   中英

How to draw detected keypoints on an image in java/javacv?

Can anyone tell me that how can i detect keypoints of an image and draw that keypoints on that image in java? I tried smt but i couldn't figure out how to draw them? Any ideas for how should i proceed or any ideas for drawing for my code?

final IplImage image1 = cvLoadImage(
                "C:/Users/Can/Desktop/panorama_image1.jpg",
                CV_LOAD_IMAGE_GRAYSCALE);

        final CanvasFrame canvas1 = new CanvasFrame("Image1");

        canvas1.showImage(image1);

        canvas1.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

        SIFT sift = new SIFT();

        KeyPoint keypoint1 = new KeyPoint();

        sift.detect(image1, null, keypoint1);

        System.out.println("Keypoints for image1: " + keypoint1.capacity());

If you or others still need an answer, I believe the possible way of doing that is

opencv_features2d.drawKeypoints(_image1, keypoint1, Mat.EMPTY);

Then you may save your _image1 to file using

ImageIO.write(_image1.getBufferedImage(), "png", new File("image1.png"));

But before that you'll have to open your image1 as a Mat object: Mat _image1 = new Mat(image1);

Assuming you or anyone else still requires this, you can do the following.

Using Java, after you have computed your keypoints you can do the following using the Features2d class in OpenCV.

    // draw keypoints on image
    Mat outputImage = new Mat();
    // Your image, keypoints, and output image
    Features2d.drawKeypoints(image, keypoints, outputImage);
    String filename = "keypoints.jpg";
    System.out.println(String.format("Writing %s...", filename));
    Highgui.imwrite(filename, outputImage);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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