List of usage examples for org.opencv.core Mat cols
public int cols()
From source file:spring2017ip.ConvolutionDemo.java
public Mat combineGxGy(Mat gx, Mat gy) { Mat outputImage = new Mat(gx.rows(), gx.cols(), gx.type()); for (int r = 0; r < gx.height(); r++) for (int c = 0; c < gx.width(); c++) { double x[] = gx.get(r, c); double y[] = gy.get(r, c); double m = Math.sqrt(x[0] * x[0] + y[0] * y[0]); outputImage.put(r, c, m);/* w w w .j a va 2 s .c o m*/ } return outputImage; }
From source file:src.model.filters.CannyFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________CANNY_______________**"); try {//from w ww . ja v a 2 s.co m String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ Mat source = Imgcodecs.imread(savePath); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Mat det = new Mat(source.rows(), source.cols(), source.type()); Imgproc.cvtColor(source, destination, Imgproc.COLOR_BGR2GRAY); Imgproc.blur(destination, det, new Size(3, 3)); Imgproc.Canny(det, det, 5, 15, 3, false); Mat dest = new Mat(); Core.add(dest, Scalar.all(0), dest); source.copyTo(dest, det); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_CA_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_CA_temp.jpg"; Imgcodecs.imwrite(output, dest); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:src.model.filters.DilationFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________DILATION_______________**"); try {/* ww w . j a va2s .com*/ String imgInput = request.getParameter("name").toString(); System.out.println("imgIn put " + imgInput); String savePath = savePath(request); //____________________________________ Mat source = Imgcodecs.imread(savePath, Imgcodecs.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(), source.cols(), source.type()); destination = source; int dilation_size = 5; Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2 * dilation_size + 1, 2 * dilation_size + 1)); Imgproc.dilate(source, destination, element); // src.model.ApplyFilter.deleteTemps(output); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_DIL_temp.jpg"; String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_DIL_temp.jpg"; Imgcodecs.imwrite(output, destination); //____________________________________ System.out.println("output: " + output); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:src.model.filters.DotsFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________DOTS_______________**"); try {/*from w ww . j a v a2 s. c o m*/ String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ int elementSize = 2; int bsize = 10; Mat source = Imgcodecs.imread(savePath); Mat dst = zeros(source.size(), CV_8UC3); Mat cir = zeros(source.size(), CV_8UC1); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Mat element = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(elementSize * 3 + 1, elementSize * 3 + 1), new Point(elementSize, elementSize)); for (int i = 0; i < source.rows(); i += bsize) { for (int j = 0; j < source.cols(); j += bsize) { circle(cir, new Point(j + bsize / (double) 2, i + bsize / (double) 2), bsize / 2 - 1, new Scalar(255, 255, 255), -1, -1, Core.LINE_AA); } } Imgproc.morphologyEx(source, dst, Imgproc.MORPH_CLOSE, element); Mat cir_32f = new Mat(source.rows(), source.cols(), CV_32F); cir.convertTo(cir_32f, CV_32F); normalize(cir_32f, cir_32f, 0, 1, NORM_MINMAX); Mat dst_32f = new Mat(source.rows(), source.cols(), CV_32F); dst.convertTo(dst_32f, CV_32F); Vector<Mat> channels = new Vector(); split(dst_32f, channels); System.out.println(channels.size()); for (int i = 0; i < channels.size(); ++i) { channels.set(i, channels.get(i).mul(cir_32f)); } merge(channels, dst_32f); dst_32f.convertTo(dst, CV_8U); // Core.gemm(source, source, bsize, source, bsize, dst); // Core.gemm(cir, destination, 1, new Mat(), 0,dst , 0); // Imgcodecs.imwrite("images\\outddput.jpg", dst); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_DOTS_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_DOTS_temp.jpg"; Imgcodecs.imwrite(output, dst); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:src.model.filters.ErosionFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________EROSION_______________**"); try {//from www. jav a 2 s . co m String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ Mat source = Imgcodecs.imread(savePath, Imgcodecs.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(), source.cols(), source.type()); destination = source; int erosion_size = 5; int dilation_size = 5; Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2 * erosion_size + 1, 2 * erosion_size + 1)); Imgproc.erode(source, destination, element); // String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_ER_temp.jpg"; // src.model.ApplyFilter.renameTemps(request); // src.model.ApplyFilter.deleteTemps(output); // String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_ER_temp.jpg"; // Imgcodecs.imwrite(output, destination); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_ER_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_ER_temp.jpg"; Imgcodecs.imwrite(output, destination); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:src.model.filters.GaussianFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________GAUSSIAN_______________**"); try {/*from w ww .j a v a2s . c o m*/ String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ Mat source = Imgcodecs.imread(savePath, Imgcodecs.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Imgproc.GaussianBlur(source, destination, new Size(35, 35), 0); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_GA_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_GA_temp.jpg"; Imgcodecs.imwrite(output, destination); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:src.model.filters.GrayscaleFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________GRAYSCALE_______________**"); try {/*from w w w . java 2 s. c o m*/ String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ Mat source = Imgcodecs.imread(savePath); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Imgproc.cvtColor(source, destination, Imgproc.COLOR_BGR2GRAY); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_BW_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_BW_temp.jpg"; Imgcodecs.imwrite(output, destination); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:src.model.filters.MorphFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________MORPH_______________**"); try {//from w w w .j a v a 2 s . c om String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ int elementSize = 9; Mat source = Imgcodecs.imread(savePath); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Mat element = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(elementSize * 2 + 1, elementSize * 2 + 1), new Point(elementSize, elementSize)); Imgproc.morphologyEx(source, destination, Imgproc.MORPH_GRADIENT, element); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_MORPH_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_MORPH_temp.jpg"; Imgcodecs.imwrite(output, destination); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:src.model.filters.SobelFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________SOBEL_______________**"); try {//from w w w. j ava2 s.com String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ int kernelSize = 3; // Mat source = Imgcodecs.imread(folder+"\\"+imgName, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); Mat source = Imgcodecs.imread(savePath, Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Mat kernel = new Mat(kernelSize, kernelSize, CvType.CV_32F) { { put(0, 0, -3); put(0, 1, -3); put(0, 2, -3); put(1, 0 - 3); put(1, 1, 0); put(1, 2, -3); put(2, 0, 5); put(2, 1, 5); put(2, 2, 5); } }; Imgproc.filter2D(source, destination, -8, kernel); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_SOBEL_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_SOBEL_temp.jpg"; Imgcodecs.imwrite(output, destination); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:syncleus.dann.data.video.FernEnsembleClassifier.java
License:Apache License
/** * The numbers in this array can be up to 2^params.structSize as we shift left once of each feature *///w ww. j av a 2 s. c o m int[] getAllFernsHashCodes(final Mat patch, int scaleIdx) { final int[] result = new int[ferns.length]; final byte[] imageData = TLDUtil.getByteArray(patch); final int cols = patch.cols(); for (int fern = 0; fern < ferns.length; fern++) { result[fern] = ferns[fern].calculateHashCode(scaleIdx, imageData, cols); } return result; }