opencv3_java akaze的特征提取与图像匹配 akaze

akaze的特征提取与图像匹配 akaze


package opencv_java_demo;

import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.features2d.*;

public class akaze {

	public static void main(String[] args) {
		try{
			System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
			
			Mat src1=Imgcodecs.imread("./imgaes/src1.jpg");
			Mat src2=Imgcodecs.imread("./imgaes/src2.jpg");
			if(src1.empty()||src2.empty()){
				throw new Exception("no file");
			}
			
			MatOfKeyPoint keypoint1=new MatOfKeyPoint();
			MatOfKeyPoint keypoint2=new MatOfKeyPoint();
			FeatureDetector sifDetector =FeatureDetector.create(FeatureDetector.AKAZE);
			
			siftDetector.detect(src1,keypoint1);
			siftDetector.detect(src2,keypoint2);
			
			DescriptorExtractor extractor=DescriptorExtractor.create(DescriptorExtractor.AKAZE);
			
			Mat descriptor1=new Mat(src1.rows(),src1.cols(),src1.type());
			extractor.compute(src1, keypoint1, descriptor1);
			Mat descriptor2=new Mat(src2.rows(),src2.cols(),src2.type());
			extractor.compute(src2, keypoint2, descriptor2);
			
			MatfOfMatch matches=new MatOfMatch();
			DescriptorExtractor matcher=DescriptorExtractor.create(DescriptorExtractor.BRUTEFORCE);
			
			matcher.match(descriptor1,descriptor2,matches);
			
			Mat dst=new Mat();
			Features2d.drawMatches(src1, keypoint1, src2, keypoint2, matches, dst);
			
			Imgcodecs.imwrite("./images/akaze.jpg", dst);
		}catch(Exception e){
			System.out.println("例外:"+e);
		}

	}

}


你可能感兴趣的:(java,opencv3)