List of usage examples for org.opencv.core Mat get
public int get(int row, int col, double[] data)
From source file:OCV_Canny.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // srcdst/* www .j a va 2 s . c o m*/ int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.Canny(src_mat, dst_mat, thr1, thr2, SIZE_VAL[ind_size], l2grad); dst_mat.get(0, 0, srcdst_bytes); }
From source file:OCV_Threshold.java
License:Open Source License
@Override public void run(ImageProcessor ip) { int imw = ip.getWidth(); int imh = ip.getHeight(); if (ip.getBitDepth() == 8) { // srcdst byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat/* w w w .ja v a2s .c o m*/ Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.threshold(src_mat, dst_mat, thresh, maxVal, INT_TYPE[idxType]); dst_mat.get(0, 0, srcdst_bytes); } else if (ip.getBitDepth() == 32) { // srcdst float[] srcdst_floats = (float[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_32F); Mat dst_mat = new Mat(imh, imw, CvType.CV_32F); // run src_mat.put(0, 0, srcdst_floats); Imgproc.threshold(src_mat, dst_mat, thresh, maxVal, INT_TYPE[idxType]); dst_mat.get(0, 0, srcdst_floats); } else { IJ.error("Wrong image format"); } }
From source file:OCV_MatchTemplate.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // src// w w w . j ava 2 s .co m byte[] arr_src = (byte[]) imp_src.getChannelProcessor().getPixels(); int imw_src = imp_src.getWidth(); int imh_src = imp_src.getHeight(); Mat mat_src = new Mat(imh_src, imw_src, CvType.CV_8UC1); mat_src.put(0, 0, arr_src); // tmp byte[] arr_tmp = (byte[]) imp_tmp.getChannelProcessor().getPixels(); int imw_tmp = imp_tmp.getWidth(); int imh_tmp = imp_tmp.getHeight(); Mat mat_tmp = new Mat(imh_tmp, imw_tmp, CvType.CV_8UC1); mat_tmp.put(0, 0, arr_tmp); // dst String title_dst = WindowManager.getUniqueName(title_src + "_MatchTemplate"); int imw_dst = imw_src - imw_tmp + 1; int imh_dst = imh_src - imh_tmp + 1; ImagePlus imp_dst = new ImagePlus(title_dst, new FloatProcessor(imw_dst, imh_dst)); float[] arr_dst = (float[]) imp_dst.getChannelProcessor().getPixels(); Mat mat_dst = new Mat(); // run Imgproc.matchTemplate(mat_src, mat_tmp, mat_dst, TYPE_VAL[ind_type]); mat_dst.get(0, 0, arr_dst); imp_dst.show(); if (TYPE_VAL[ind_type] == Imgproc.TM_SQDIFF_NORMED) { substracted_from_one(arr_dst); } IJ.run(imp_dst, "Enhance Contrast", "saturated=0.35"); // show data if (enResult) { if (enSearchMax) { showData_enSearchMaxPoint(imp_dst, thr_res, imw_tmp, imh_tmp); } else { showData(arr_dst, imw_dst, imh_dst, imw_tmp, imh_tmp); } } }
From source file:OCV_WarpPerspective.java
License:Open Source License
@Override public void run(ImageProcessor ip) { int imw = ip.getWidth(); int imh = ip.getHeight(); Size size = new Size((double) imw, (double) imh); Mat mat = new Mat(3, 3, CvType.CV_64FC1); for (int i = 0; i < 3; i++) { mat.put(i, 0, new double[] { Double.valueOf(rt.getStringValue(0, i).replaceAll("\"|'", "")) }); mat.put(i, 1, new double[] { Double.valueOf(rt.getStringValue(1, i).replaceAll("\"|'", "")) }); mat.put(i, 2, new double[] { Double.valueOf(rt.getStringValue(2, i).replaceAll("\"|'", "")) }); }/*from w w w . j a v a 2 s .c o m*/ if (ip.getBitDepth() == 8) { byte[] srcdst_ar = (byte[]) ip.getPixels(); Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); src_mat.put(0, 0, srcdst_ar); Imgproc.warpPerspective(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]); dst_mat.get(0, 0, srcdst_ar); } else if (ip.getBitDepth() == 16) { short[] srcdst_ar = (short[]) ip.getPixels(); Mat src_mat = new Mat(imh, imw, CvType.CV_16UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_16UC1); src_mat.put(0, 0, srcdst_ar); Imgproc.warpPerspective(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]); dst_mat.get(0, 0, srcdst_ar); } else if (ip.getBitDepth() == 24) { int[] srcdst_ar = (int[]) ip.getPixels(); Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3); OCV__LoadLibrary.intarray2mat(srcdst_ar, src_mat, imw, imh); Imgproc.warpPerspective(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]); OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ar, imw, imh); } else if (ip.getBitDepth() == 32) { float[] srcdst_ar = (float[]) ip.getPixels(); Mat src_mat = new Mat(imh, imw, CvType.CV_32FC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_32FC1); src_mat.put(0, 0, srcdst_ar); Imgproc.warpPerspective(src_mat, dst_mat, mat, size, FLAGS_INT[flags_ind]); dst_mat.get(0, 0, srcdst_ar); } else { IJ.error("Wrong image format"); } }
From source file:OCV_ConnectedComponentsWithStats.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // src/*from w w w. j a va2s . c o m*/ int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] src_arr = (byte[]) ip.getPixels(); Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); // dst String titleDst = WindowManager .getUniqueName(impSrc.getTitle() + "_Connect" + String.valueOf(TYPE_INT[type_ind])); ImagePlus impDst = new ImagePlus(titleDst, new FloatProcessor(imw, imh)); float[] dst_arr = (float[]) impDst.getChannelProcessor().getPixels(); Mat dst_mat_32s = new Mat(imh, imw, CvType.CV_32S); Mat dst_mat_32f = new Mat(imh, imw, CvType.CV_32F); Mat stats_mat = new Mat(); Mat cens_mat = new Mat(); // run src_mat.put(0, 0, src_arr); int output_con = Imgproc.connectedComponentsWithStats(src_mat, dst_mat_32s, stats_mat, cens_mat, TYPE_INT[type_ind], CvType.CV_32S); dst_mat_32s.convertTo(dst_mat_32f, CvType.CV_32F); dst_mat_32f.get(0, 0, dst_arr); // show data if (1 < output_con) { showData(dst_arr, imw, imh, output_con, stats_mat, cens_mat); } // finish if (1 < output_con && enOutImg) { impDst.show(); } else { impDst.close(); } }
From source file:OCV_ConnectedComponentsWithStats.java
License:Open Source License
private void showData(float[] dst_arr, int imw, int imh, int output_con, Mat stats_mat, Mat cens_mat) { int num_lab = output_con - 1; // get stats/*www . j a v a 2s . co m*/ Rectangle[] rects = new Rectangle[output_con]; int[] areas = new int[output_con]; double[] cens = new double[output_con * 2]; cens_mat.get(0, 0, cens); for (int i = 0; i < output_con; i++) { rects[i] = new Rectangle((int) (stats_mat.get(i, 0)[0]), (int) (stats_mat.get(i, 1)[0]), (int) (stats_mat.get(i, 2)[0]), (int) (stats_mat.get(i, 3)[0])); areas[i] = (int) (stats_mat.get(i, 4)[0]); } // set the ResultsTable ResultsTable rt = OCV__LoadLibrary.GetResultsTable(true); for (int i = 1; i < output_con; i++) { rt.incrementCounter(); rt.addValue("Area", areas[i]); rt.addValue("BX", rects[i].x); rt.addValue("BY", rects[i].y); rt.addValue("Width", rects[i].width); rt.addValue("Height", rects[i].height); } rt.show("Results"); // set the ROI Manager RoiManager roiManager = OCV__LoadLibrary.GetRoiManager(true, true); Macro_Runner mr = new Macro_Runner(); mr.runMacro("setBatchMode(true);", ""); int[] tbl = new int[num_lab + 1]; int val = 0; String type = TYPE_STR[type_ind]; for (int y = 0; y < imh; y++) { for (int x = 0; x < imw; x++) { val = (int) dst_arr[x + y * imw]; if (val != 0 && tbl[val] == 0) { mr.runMacro( "doWand(" + String.valueOf(x) + ", " + String.valueOf(y) + ", 0.0, \"" + type + "\");", ""); roiManager.runCommand("add"); tbl[val] = 1; } } } mr.runMacro("setBatchMode(false);", ""); roiManager.runCommand("show all"); }
From source file:OCV_LinearPolar.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // srcdst/*from w w w. ja v a2 s . c om*/ int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_ar = (byte[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_ar); Imgproc.linearPolar(src_mat, dst_mat, new Point(cx, cy), (double) rmax, TYPE_INT[type_ind]); dst_mat.get(0, 0, srcdst_ar); }
From source file:OCV_Sobel.java
License:Open Source License
@Override public void run(ImageProcessor ip) { if (ip.getBitDepth() == 8) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat//from w w w .j a va2s . c o m Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.Sobel(src_mat, dst_mat, src_mat.depth(), dx, dy, ksize, scale, delta, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else if (ip.getBitDepth() == 16) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); short[] srcdst_shorts = (short[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_16S); Mat dst_mat = new Mat(imh, imw, CvType.CV_16S); // run src_mat.put(0, 0, srcdst_shorts); Imgproc.Sobel(src_mat, dst_mat, src_mat.depth(), dx, dy, ksize, scale, delta, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_shorts); } else if (ip.getBitDepth() == 32) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_floats = (float[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_32F); Mat dst_mat = new Mat(imh, imw, CvType.CV_32F); // run src_mat.put(0, 0, srcdst_floats); Imgproc.Sobel(src_mat, dst_mat, src_mat.depth(), dx, dy, ksize, scale, delta, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_floats); } else { IJ.error("Wrong image format"); } }
From source file:ImagemScreenAtual.java
public static BufferedImage createBufferedImage(Mat mat) { BufferedImage image = new BufferedImage(mat.width(), mat.height(), BufferedImage.TYPE_3BYTE_BGR); WritableRaster raster = image.getRaster(); DataBufferByte dataBuffer = (DataBufferByte) raster.getDataBuffer(); byte[] data = dataBuffer.getData(); mat.get(0, 0, data); return image; }
From source file:frmMain.java
public static BufferedImage mat2Img(Mat in) { BufferedImage out;//from w w w . java 2s. c o m byte[] data = new byte[in.width() * in.height() * (int) in.elemSize()]; int type; in.get(0, 0, data); if (in.channels() == 1) type = BufferedImage.TYPE_BYTE_GRAY; else type = BufferedImage.TYPE_3BYTE_BGR; out = new BufferedImage(in.width(), in.height(), type); out.getRaster().setDataElements(0, 0, in.width(), in.height(), data); return out; }