opencv3_java 图像的角点检测DetectConers goodFeaturesToTrack

图像的角点检测DetectConers goodFeaturesToTrack 


package opencv_java_demo;

import org.opencv.core.*;
import org.opencv.imgcodecs.*;
import org.opencv.imgproc.*;

public class DetectConers {

	public static void main(String[] args) {
		try{
			System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
			
			final int maxCorners=50,blockSize=3;
			final double qualityLevel=0.01,minDistance=20.0,k=0.04;
			final boolean useHarrisDetector=false;
			MatOfPoint corners=new MatOfPoint();
			
			Mat src=Imgcodecs.imread("./images/lenna.jpg");
			if(src.empty()){
				throw new Exception("no file");
			}
			Mat dst=src.clone();
			Mat gray=new Mat();
			
			Imgproc.cvtColor(src, gray, Imgproc.COLOR_RGB2GRAY);
			Imgproc.goodFeaturesToTrack(gray, corners, maxCorners, qualityLevel, minDistance,
					new Mat(),blockSize,useHarrisDetector,k);
			Point[] pCorners=corners.toArray();
			for(int i=0;i<pCorners.length;i++){
				Imgproc.circle(dst, pCorners[i], 4, new Scalar(255,255,0),2);
			}
			Imgcodecs.imwrite("./images/corners.jpg", dst);	
		}catch(Exception e){
			System.out.println("例外:" + e);
		}
	}
}




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