opencv获取图片特征

122 阅读1分钟
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.features2d.FeatureDetector;
import org.opencv.features2d.Features2d;
import org.opencv.features2d.KeyPoint;
import org.opencv.imgcodecs.Imgcodecs;

public class SIFTDemo {
    public static void main(String[] args) {
        // Load the OpenCV native library
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        // Read an image from file
        Mat image = Imgcodecs.imread("path/to/image.jpg");

        // Create a SIFT feature detector
        FeatureDetector siftDetector = FeatureDetector.create(FeatureDetector.SIFT);

        // Detect keypoints in the image
        Mat mask = new Mat();
        KeyPoint keypoints = new KeyPoint();
        siftDetector.detect(image, keypoints, mask);

        // Draw the keypoints on the image
        Mat outputImage = new Mat();
        Features2d.drawKeypoints(image, keypoints, outputImage);

        // Display the resulting image
        Imgcodecs.imshow("SIFT Keypoints", outputImage);
        Imgcodecs.waitKey(0);
    }
}

<dependency>
    <groupId>org.opencv</groupId>
    <artifactId>opencv</artifactId>
    <version>2.4.11</version>
</dependency>