List of usage examples for org.opencv.core Mat rows
public int rows()
From source file:contador_de_moedas.Reconhecimento.java
public Mat CriaMascara(Point pt, double raio, Mat img_Original) { // Cria uma img toda preta com as mesmas dimenses da original Mat mask = zeros(img_Original.rows(), img_Original.cols(), CV_8U); // Cria um circulo branco preenchido Imgproc.circle(mask, pt, (int) raio, new Scalar(255, 255, 255), -1, 8, 0); return (mask); }
From source file:controller.GhostDetection.java
public static int[][] detect(Mat imgR, Mat imgO, JointPDF jointPDF) { double count_blue, count_green, count_red; final double threshold = 0.00001; int[][] ghostPixel = new int[imgO.rows()][imgO.cols()]; // Tresholding for (int i = 0; i < imgR.rows(); i++) { for (int j = 0; j < imgR.cols(); j++) { double[] rgbR = imgR.get(i, j); double[] rgbO = imgO.get(i, j); count_blue = jointPDF.getPDF_blue()[(int) rgbO[0]][(int) rgbR[0]]; count_green = jointPDF.getPDF_green()[(int) rgbO[1]][(int) rgbR[1]]; count_red = jointPDF.getPDF_red()[(int) rgbO[2]][(int) rgbR[2]]; if (count_blue < threshold || count_green < threshold || count_red < threshold) { ghostPixel[i][j] = 0;/*from w w w . j a va 2 s .c o m*/ } else { ghostPixel[i][j] = 1; } } } // for (int i = 0; i < 3; i++) { // for (int j = 0; j < 5; j++) { // double ghost = ghostPixel[i][j]; // System.out.print(ghost+";"); // } // System.out.println(""); // } return ghostPixel; }
From source file:cpsd.ImageGUI.java
private void cannyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cannyButtonActionPerformed try {//from w w w .j ava2s . c om Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); threshold(source, destination, 50, 255, CV_THRESH_BINARY); // ImageClass.getInstance().setImage(destination); // Imgproc.GaussianBlur(destination,destination,new org.opencv.core.Size(0,0),10); // fastNlMeansDenoising(destination,destination,3,7,21); // source = ImageClass.getInstance().getImage(); Imgproc.Canny(destination, destination, 0.05, 0.15, 3, true); ImageClass.getInstance().setImage(destination); } catch (NullPointerException e) { System.err.println("..........Please load a valid Image.........."); } displayImage(); // TODO add your handling code here: }
From source file:cpsd.ImageGUI.java
private void AnalyzeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnalyzeButtonActionPerformed try {// w ww .j a v a 2 s .c o m double pixelArea = 1; double imageSize = 1; if (magnification == 50) pixelArea = 1.2996; else if (magnification == 100) pixelArea = 0.329476; else if (magnification == 200) pixelArea = 0.08162; else { imageSize = pow(10, 10) * pow(magnification, -2); pixelArea = (imageSize) / (resolution1 * resolution2); } Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), source.type()); //Imgproc.adaptiveThreshold(source,destination,255,ADAPTIVE_THRESH_GAUSSIAN_C,THRESH_BINARY_INV,13,2); //Imgproc.GaussianBlur(destination,destination,new org.opencv.core.Size(0,0),5); threshold(source, destination, 30, 255, CV_THRESH_BINARY); distanceTransform(destination, destination, CV_DIST_L2, 3); normalize(destination, destination, 0, 1, NORM_MINMAX); threshold(destination, destination, 0.5, 1, CV_THRESH_BINARY); destination.convertTo(destination, CV_8U); /*ImageClass.getInstance().setImage(destination); displayImage();*/ ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); MatOfInt4 hierarchy = new MatOfInt4(); // Rect roi = new Rect(100,100,destination.cols()-100,destination.rows()-100); // Mat imageROI = destination.submat(roi); /*ImageClass.getInstance().setImage(imageROI); displayImage();*/ //Imgproc.Canny(source,destination,0.05,0.15); Imgproc.findContours(destination, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); int total = contours.size(); int count = 0; //System.out.println(total); MatOfPoint[] cntrs = contours.toArray(new MatOfPoint[contours.size()]); ArrayList<Double> value = new ArrayList<Double>(); double temp = 0; for (int i = 0; i < contours.size(); i++) { if (contourArea(cntrs[i]) > 1/*&& contourArea(cntrs[i])<3000*/) { temp = 2 * Math.sqrt((contourArea(cntrs[i]) * (pixelArea)) / Math.PI); //temp = contourArea(cntrs[i]); if (temp > 0) { value.add(count, temp); System.out.println("area of contour " + count++ + " is : " + contourArea(cntrs[i])); } } } System.out.println("total number of contours : " + count); double[] values = new double[count]; for (int i = 0; i < count; i++) { //temp = value.get(i);//2*Math.sqrt((value.get(i)*127.024)/Math.PI); //if(temp>0) values[i] = value.get(i); //System.out.println("the diameter of particle "+i+ "is "+values[i]); // values[i]=(contourArea(cntrs[i])*127.024)/100; } //int number = 300; /*HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); XYSeries series = new XYSeries("Particle Size Distribution"); try{ dataset.addSeries("Histogram1",values,number,0,300); for(int i=0;i<300;i++){ if(dataset.getYValue(0,i)>0) series.add(dataset.getXValue(0,i),dataset.getYValue(0,i)); } // XYDataset xydataset = new XYSeriesCollection(series); }catch(Exception e) { e.printStackTrace(); } XYDataset xydataset = new XYSeriesCollection(series); String plotTitle = "Particle Size Distribution"; String xAxis = "particle diameter in microns"; String yAxis = "particle count"; PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = true; boolean toolTips = true; boolean urls = false; JFreeChart chart1 = ChartFactory.createXYLineChart(plotTitle,xAxis,yAxis,xydataset,orientation,show,toolTips,urls); JFreeChart chart2 = ChartFactory.createHistogram(plotTitle,xAxis,yAxis,dataset,orientation,show,toolTips,urls); int width1 = 500; int height1 = 500; ChartFrame frame1 = new ChartFrame("Coal PSD",chart1); frame1.setSize(width1,height1); frame1.setVisible(true); frame1.setDefaultCloseOperation(DISPOSE_ON_CLOSE); int width2 = 500; int height2 = 500; ChartFrame frame2 = new ChartFrame("Coal PSD",chart2); frame2.setSize(width2,height2); frame2.setVisible(true); frame2.setDefaultCloseOperation(DISPOSE_ON_CLOSE);*/ } catch (NullPointerException e) { System.err.println("..........Please load a valid Image.........."); } // TODO add your handling code here: }
From source file:cpsd.ImageGUI.java
private void rgb2Gray() { //String str = path.getText().toString(); Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat(source.rows(), source.cols(), CV_8UC1); Imgproc.cvtColor(source, destination, COLOR_RGB2GRAY); ImageClass.getInstance().setImage(destination); }
From source file:cpsd.ImageGUI.java
private void zoomImage(double zoomlevel) { Mat source = ImageClass.getInstance().getImage(); Mat destination = new Mat((int) (source.rows() * zoomlevel), (int) (source.cols() * zoomlevel), source.type());/*from w w w .jav a2 s. c o m*/ Imgproc.resize(source, destination, destination.size(), zoomlevel, zoomlevel, INTER_CUBIC); ImageClass.getInstance().setImage(destination); zoomSlider.setValue((int) (zoomlevel * 10)); }
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 {//from ww w . j av a 2 s . c o m 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()); } }