Java OpenCV-4.0.0 圖像處理27.1 Harris角點檢測
package comxu.opencv.image;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
public class CornerCheck {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
shi_tomasi();
}
public static void harris() {
Mat src=Imgcodecs.imread("C:\\Users\\hyacinth\\Pictures\\2.png");
Mat gray=new Mat();
Mat dst=new Mat();
Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);
Imgproc.cornerHarris(gray, dst, 2, 3, 0.04);
Core.normalize(dst, dst, 0, 255,Core.NORM_MINMAX,-1,new Mat());
Core.convertScaleAbs(dst, dst);
Mat result=src.clone();
for (int i = 0,row=result.rows(); i < row; i++) {
for (int j = 0,col=result.cols(); j < col; j++) {
if (dst.get(i,j).clone()[0]>130) {
Imgproc.circle(result, new Point(i-3,j+2), 1, new Scalar(0,0,255),Imgproc.FILLED);
}
}
}
HighGui.imshow("Harris 角點檢測", result);
HighGui.waitKey(0);
}
}