Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package LetsStart; /** * * @author art */ import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; //mport org.opencv.core.Point; //mport org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class App { static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) throws Exception { String filePath = "src/resources/images/1.jpg"; Mat newImage = Imgcodecs.imread(filePath); Mat im = new Mat(800, 1540, CvType.CV_32F); Mat x = new Mat(); Mat y = new Mat(); Mat n = new Mat(800, 1540, CvType.CV_32F); if (newImage.dataAddr() == 0) { System.out.println("Couldn't open file " + filePath); } else { Size sz = new Size(1540, 800); Imgproc.resize(newImage, newImage, sz); //Mat image=newImage.clone(); Imgproc.blur(newImage, im, new Size(3, 3)); //Imgproc.GaussianBlur(newImage, im, new Size(10,10),0); //Imgproc.bilateralFilter(newImage, im, 9, 10, 10); Imgproc.cvtColor(im, n, Imgproc.COLOR_BGR2GRAY); Imgproc.equalizeHist(n, n); //Imgproc.Sobel(im, x, -10, 0, 1); //Imgproc.Sobel(im, y, -10, 1, 0); //Core.add(x, y, n); Imgproc.Canny(n, n, 70, 130, 3, false); /*Mat lines = new Mat(); Imgproc.HoughLines(n, lines, 1, Math.PI/180, 200); for(int i =0; i<lines.cols(); i++) { double rho = lines.get(0,i)[0]; double theta = lines.get(0,i)[1]; Point pt1 = new Point(), pt2 = new Point(); double a = Math.cos(theta), b=Math.sin(theta); double x0 = a*rho, y0=b*rho; pt1.x = Math.round(x0 + 1000*(-b)); pt1.y = Math.round(y0 + 1000*(a)); pt2.x = Math.round(x0 - 1000*(-b)); pt2.y = Math.round(y0 - 1000*(a)); Imgproc.line(image, pt1, pt2, new Scalar(255,0,0),2,Core.LINE_AA,0); }*/ /*Mat kernel = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(3,3)); Imgproc.morphologyEx(n, n, Imgproc.MORPH_CLOSE, kernel);*/ //close morph //Imgproc.threshold(n, n, 80, 255, Imgproc.THRESH_BINARY); // binary image /*Core.pow(y, 2, y); Core.pow(x, 2, x); Core.add(x, y, n); Core.pow(n, 0.5, im);*/ Imgcodecs.imwrite("src/resources/images/output/2.jpg", n); GUI gui = new GUI("Smooth Filter Example", n); gui.init(); } return; } }