List of usage examples for org.opencv.core Mat cols
public int cols()
From source file:cpsd.ImageGUI.java
private void enhanceContrast() { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //System.load("/usr/local/share/OpenCV/java/libopencv_java249.so"); // rgb2Gray(); Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Imgproc.equalizeHist(source, destination); image.getInstance().setImage(destination); }
From source file:cpsd.ImageGUI.java
private void enhanceSharpness(double alpha) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // System.load("/usr/local/share/OpenCV/java/libopencv_java249.so"); Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); /// GaussianBlur(Mat src, Mat dst, Size ksize, double sigmaX); Imgproc.GaussianBlur(source, destination, new org.opencv.core.Size(0, 0), 10); ///addWeighted(Mat src1, double alpha, Mat src2, double beta, double gamma, Mat dst); Core.addWeighted(source, alpha, destination, -0.5, 0, destination); ImageClass.getInstance().setImage(destination); sharpSlider.setValue((int) (alpha * 10)); }
From source file:cpsd.ImageGUI.java
private void enhanceBrightness(double alpha) { Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); source.convertTo(destination, -1, alpha, 50); ImageClass.getInstance().setImage(destination); // brightSlider.setValue((int)(alpha*10)); }
From source file:cpsd.ImageGUI.java
private void transform(final int[][] arr) { try {// w w w.j a v a2 s . com int kernelSize = 3; System.loadLibrary(Core.NATIVE_LIBRARY_NAME); //System.load("/usr/local/share/OpenCV/java/libopencv_java249.so"); // System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Mat kernel = new Mat(kernelSize, kernelSize, CvType.CV_32F) { { for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { System.out.println(arr[i][j]); put(i, j, arr[i][j]); } } } }; Imgproc.filter2D(source, destination, -1, kernel); ImageClass.getInstance().setImage(destination); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:ctPrincipal.Ruidos.java
private String ruidoGaussiano(int mean, int desv) { Mat original_Bgr = image.clone(); Mat mGaussian_noise = new Mat(original_Bgr.size(), original_Bgr.type()); randn(mGaussian_noise, mean, desv);//from w ww. ja v a 2 s .c o m for (int m = 0; m < original_Bgr.rows(); m++) { for (int n = 0; n < original_Bgr.cols(); n++) { double[] val = new double[3]; for (int i = 0; i < original_Bgr.get(m, n).length; i++) { val[i] = original_Bgr.get(m, n)[i] + mGaussian_noise.get(m, n)[i]; } original_Bgr.put(m, n, val); } } normalize(original_Bgr, original_Bgr, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC3); Imgcodecs.imwrite("OutputImg/gaussian.jpg", original_Bgr); return "OutputImg/gaussian.jpg"; }
From source file:ctPrincipal.Ruidos.java
private String ruidoSalPimenta(int min, int max) { Mat saltPepper_img = image.clone(); Mat mSaltPepper_noise = new Mat(saltPepper_img.size(), saltPepper_img.type()); randn(mSaltPepper_noise, 0, 255);/*from w w w . j av a 2 s . c o m*/ for (int m = 0; m < saltPepper_img.rows(); m++) { for (int n = 0; n < saltPepper_img.cols(); n++) { double[] val = new double[3]; if (mSaltPepper_noise.get(m, n)[0] < min && mSaltPepper_noise.get(m, n)[1] < min && mSaltPepper_noise.get(m, n)[2] < min) { for (int i = 0; i < saltPepper_img.get(m, n).length; i++) { val[i] = 0; } saltPepper_img.put(m, n, val); } if (mSaltPepper_noise.get(m, n)[0] > max && mSaltPepper_noise.get(m, n)[1] > max && mSaltPepper_noise.get(m, n)[2] > max) { for (int i = 0; i < saltPepper_img.get(m, n).length; i++) { val[i] = 255; } saltPepper_img.put(m, n, val); } } } normalize(saltPepper_img, saltPepper_img, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC3); Imgcodecs.imwrite("OutputImg/saltpepper.jpg", saltPepper_img); return "OutputImg/saltpepper.jpg"; }
From source file:cx.uni.jk.mms.iaip.filter.LogRedBlue.java
License:Open Source License
@Override public Mat convert(Mat mat) { MinMaxLocResult negativeMmlr, positiveMmlr; double min, max, alpha, beta; /** negative values to positive and log */ Mat negativeMat = mat.clone();/*from w ww .j a v a 2 s. c o m*/ Core.min(negativeMat, new Scalar(0.0d), negativeMat); Core.multiply(negativeMat, new Scalar(-1.0d), negativeMat); Core.add(negativeMat, new Scalar(1.0d), negativeMat); Core.log(negativeMat, negativeMat); /** positve values log */ Mat positiveMat = mat.clone(); Core.max(positiveMat, new Scalar(0.0d), positiveMat); Core.add(positiveMat, new Scalar(1.0d), positiveMat); Core.log(positiveMat, positiveMat); /** find common contrast and brightness to fit into 8 bit */ negativeMmlr = Core.minMaxLoc(negativeMat); positiveMmlr = Core.minMaxLoc(positiveMat); min = 0; max = Math.max(negativeMmlr.maxVal, positiveMmlr.maxVal); alpha = 256.0d / (max - min); beta = -min * alpha; /** conversion of both matrices to 8 bit */ negativeMat.convertTo(negativeMat, CvType.CV_8UC1, alpha, beta); positiveMat.convertTo(positiveMat, CvType.CV_8UC1, alpha, beta); /** combine both matrices into one 8 bit 3 channel rgb picture */ Mat tempMat = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC3); List<Mat> mixSrcMats = new ArrayList<>(); mixSrcMats.add(negativeMat); // 1 channel: 0 mixSrcMats.add(positiveMat); // 1 channel: 1 List<Mat> mixDstMats = new ArrayList<>(); mixDstMats.add(tempMat); // 3 channels: 0-2 MatOfInt fromToMat = new MatOfInt(0, 0 /* neg->red */, -1, 1/* * null->green */, 1, 2 /* * pos- * > * blue */); Core.mixChannels(mixSrcMats, mixDstMats, fromToMat); return tempMat; }
From source file:cx.uni.jk.mms.iaip.filter.LogYellowCyan.java
License:Open Source License
@Override public Mat convert(Mat mat) { MinMaxLocResult negativeMmlr, positiveMmlr; double min, max, alpha, beta; /** negative values to positive and log */ Mat negativeMat = mat.clone();/*from w ww .j a v a2 s. co m*/ Core.min(negativeMat, new Scalar(0.0d), negativeMat); Core.multiply(negativeMat, new Scalar(-1.0d), negativeMat); Core.add(negativeMat, new Scalar(1.0d), negativeMat); Core.log(negativeMat, negativeMat); /** positve values log */ Mat positiveMat = mat.clone(); Core.max(positiveMat, new Scalar(0.0d), positiveMat); Core.add(positiveMat, new Scalar(1.0d), positiveMat); Core.log(positiveMat, positiveMat); /** find common contrast and brightness to fit into 8 bit */ negativeMmlr = Core.minMaxLoc(negativeMat); positiveMmlr = Core.minMaxLoc(positiveMat); min = 0; max = Math.max(negativeMmlr.maxVal, positiveMmlr.maxVal); alpha = 256.0d / (max - min); beta = -min * alpha; /** conversion of both matrices to 8 bit */ negativeMat.convertTo(negativeMat, CvType.CV_8UC1, alpha, beta); positiveMat.convertTo(positiveMat, CvType.CV_8UC1, alpha, beta); /** create additional mat for saturated green */ Mat brightMat = negativeMat.clone(); Core.max(negativeMat, positiveMat, brightMat); // Core.absdiff(brightMat, new Scalar(255.0d), brightMat); // Core.multiply(brightMat, new Scalar(1.0d/3.0d), brightMat); /** combine all matrices into one 8 bit 3 channel rgb picture */ Mat tempMat = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC3); List<Mat> mixSrcMats = new ArrayList<>(); mixSrcMats.add(negativeMat); // 1 channel: 0 mixSrcMats.add(positiveMat); // 1 channel: 1 mixSrcMats.add(brightMat); // 1 channel: 2 List<Mat> mixDstMats = new ArrayList<>(); mixDstMats.add(tempMat); // 3 channels: 0-2 MatOfInt fromToMat = new MatOfInt(0, 0 /* neg->red */, 2, 1/* * avg->green */, 1, 2 /* * pos- * > * blue */); Core.mixChannels(mixSrcMats, mixDstMats, fromToMat); return tempMat; }
From source file:cx.uni.jk.mms.iaip.tools.SimpleBrushTool.java
License:Open Source License
@Override public Rect apply(Mat mat, BrushModel brush, int x, int y, boolean inverseEffect) { Rect changedArea = null;//from w ww . j a v a 2 s . c o m try { this.logger.finer(String.format("apply mode=\"%s\" inverse=%s, size=%d, strength=%d", brush.getMode(), inverseEffect, brush.getSize(), brush.getValue())); this.logger.finest("mat = " + mat.toString()); /** where is brush going to work? this may reach outside the mat! */ int brushColStart = x - (brush.getSize() - 1) / 2; int brushColEnd = x + brush.getSize() / 2; int brushRowStart = y - (brush.getSize() - 1) / 2; int brushRowEnd = y + brush.getSize() / 2; if (brushColEnd >= 0 && brushColStart < mat.cols() && brushRowEnd >= 0 && brushRowStart < mat.rows()) { /** calculate bounds for roiMat to fit into original mat */ int subColStart = Math.max(0, brushColStart); int subColEnd = Math.min(brushColEnd, mat.cols() - 1); int subRowStart = Math.max(0, brushRowStart); int subRowEnd = Math.min(brushRowEnd, mat.rows() - 1); /** * the caller may want to know. Rect constructor interprets the * second point being outside of the Rect! a one pixel rectangle * Rect(Point(a,b), Point(a+1,b+1)) has height and width 1. see * * @link{http://docs.opencv.org/java/org/opencv/core/Rect.html */ changedArea = new Rect(new Point(subColStart, subRowStart), new Point(subColEnd + 1, subRowEnd + 1)); /** * get the part of original mat which going to be affected by * change */ Mat roiMat = mat.submat(subRowStart, subRowEnd + 1, subColStart, subColEnd + 1); this.logger.finest("matRoi = " + roiMat.toString()); /** does the brush fit into the roiMat we shall work on ? */ boolean brushFits = brushColStart == subColStart && brushColEnd == subColEnd && brushRowStart == subRowStart && brushRowEnd == subRowEnd; this.logger.finest("brush fits = " + brushFits); /** * make sure to have a working mat which matches the full brush * size */ Mat workMat, workRoi = null; if (brushFits) { /** just work in the original mat area defined by roi */ workMat = roiMat; } else { /** create a new mat as big as the brush */ workMat = Mat.zeros(brush.getSize(), brush.getSize(), MatModel.MAT_TYPE); this.logger.finest("workMat= " + workMat.toString()); /** * create an ROI in the workMat as big as the subMat, * correct offset for brushing in the middle */ int roiColStart = subColStart - brushColStart; int roiColEnd = roiColStart + roiMat.cols(); int roiRowStart = subRowStart - brushRowStart; int roiRowEend = roiRowStart + roiMat.rows(); workRoi = workMat.submat(roiRowStart, roiRowEend, roiColStart, roiColEnd); this.logger.finest("workRoi= " + workRoi.toString()); roiMat.copyTo(workRoi); this.logger.finest("workRoi= " + workRoi.toString()); // workRoi.put(0, 0, 1333.0d); this.logger.finest("roiMat dump1 " + roiMat.dump()); this.logger.finest("workRoi dump1 " + workRoi.dump()); this.logger.finest("workMat dump1 " + workMat.dump()); } /** the real action */ this.applyToWorkMat(brush, inverseEffect, workMat); this.logger.finest("workMat dump2 " + workMat.dump()); this.logger.finest("matRoi dump2 " + roiMat.dump()); if (brushFits) { /** * nothing to do, we have been working directly in original * mat */ } else { /** copy workMat back into original mat */ this.logger.finest("workRoi dump2 " + workRoi.dump()); // workRoi.put(0, 0, 1338); this.logger.finest("workRoi dump3 " + workRoi.dump()); /** * copy roi of changed workmat back into roi of original mat */ this.logger.finest("matRoi = " + roiMat.toString()); workRoi.copyTo(roiMat); this.logger.finest("matRoi = " + roiMat.toString()); } this.logger.finest("matRoi dump3 " + roiMat.dump()); } } catch (CvException e) { /** nevermind if the user does not notice */ this.logger.fine(e.getStackTrace().toString()); } /** let the caller know caller which area has potentially been changed */ return changedArea; }
From source file:de.hhn.android.licenseplatedecoder.decoder.CountryExtractor.java
/** * Constructor/*w w w . j a v a 2 s . c o m*/ * @param nativeAddress input image pointer address * @param withoutStripInputAddr image pointer address in order to store the cropped image without the blue strip */ public CountryExtractor(long nativeAddress, long withoutStripInputAddr) { this.nativeInputAddr = nativeAddress; this.withoutStripInputAddr = withoutStripInputAddr; this.withoutBlueStrip = new Mat(); /** OCR ENGINE INIT */ this.baseApi = new TessBaseAPI(); this.baseApi.setDebug(true); this.baseApi.init("/sdcard/", "blueBand"); // myDir + "/tessdata/eng.traineddata" must be present this.baseApi.setVariable("tessedit_char_whitelist", "ABCDFGHIKLOPRSTZ"); this.baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_CHAR); ArrayList<Mat> countryCode = getCharacters(); StringBuffer strb = new StringBuffer(); for (Mat elem : countryCode) { Bitmap pass = Bitmap.createBitmap(elem.cols(), elem.rows(), Bitmap.Config.ARGB_8888); Utils.matToBitmap(elem, pass, true); baseApi.setImage(pass); String recognizedText = baseApi.getUTF8Text(); strb.append(recognizedText); baseApi.clear(); pass.recycle(); } this.result = strb.toString(); baseApi.end(); baseApi = null; countryCode = null; }