List of usage examples for org.opencv.core Mat Mat
public Mat(int rows, int cols, int type, Scalar s)
From source file:classes.ObjectFinder.java
private void applyMorphologicalFilters() { Mat element = new Mat(3, 3, CvType.CV_8U, new Scalar(1)); Imgproc.erode(thresholdedBackprojection, morphologicalImage, element); Imgproc.morphologyEx(morphologicalImage, morphologicalImage, Imgproc.MORPH_CLOSE, element, new Point(-1, -1), 2); Imgproc.morphologyEx(morphologicalImage, morphologicalImage, Imgproc.MORPH_OPEN, element, new Point(-1, -1), 2);/*from w ww .j av a 2 s. c o m*/ }
From source file:cx.uni.jk.mms.iaip.brush.BrushModel.java
License:Open Source License
private void updateOneMinusAlphaMat() { this.oneMinusAlphaMat = this.alphaMat.clone(); Core.subtract(new Mat(this.alphaMat.rows(), this.alphaMat.cols(), MatModel.MAT_TYPE, new Scalar(1.0d)), this.alphaMat, this.oneMinusAlphaMat); }
From source file:depthDataFromStereoCamsOpenCV.ProcessImages.java
/** * //from ww w.j a va 2 s . c o m * @param image * @return */ public static Mat bringImageToStdSize(Mat image) { //create the square container int dstWidth = 300; int dstHeight = 500; Mat dst = new Mat(dstHeight, dstWidth, CvType.CV_8UC3, new Scalar(0, 0, 0)); //ProcessImages.displayImage(ProcessImages.Mat2BufferedImage(dst),"background"); //Put the image into the container, roi is the new position Rect roi = new Rect((dstWidth - image.cols()) / 2, (dstHeight - image.rows()) / 2, image.cols(), image.rows()); Mat targetROI = new Mat(dst, roi); image.copyTo(targetROI); // ProcessImages.displayImage(ProcessImages.Mat2BufferedImage(dst),"Standardized"); return dst; }
From source file:edu.soict.hust.k57.mmdb.components.HistogramImageBulder.java
private ImageIcon createImageIcon(Mat hist, int bin, Channel c) { int hist_w = 150; // width of the histogram image int hist_h = 100; // height of the histogram image int bin_w = (int) Math.round(hist_w * 1.0 / bin); Mat histImage = new Mat(hist_h, hist_w, CvType.CV_8UC3, new Scalar(80, 60, 60)); Mat normalizeHist = hist.clone();/*w w w. ja v a 2 s .c o m*/ Core.normalize(normalizeHist, normalizeHist, 0, histImage.rows(), Core.NORM_MINMAX, -1, new Mat()); Scalar scalar = null; switch (c) { case B: scalar = new Scalar(255, 0, 0); break; case G: scalar = new Scalar(0, 255, 0); break; case R: scalar = new Scalar(0, 0, 255); } for (int i = 1; i < bin; i++) { Imgproc.line(histImage, new Point(bin_w * (i - 1), hist_h - Math.round(normalizeHist.get(i - 1, 0)[0])), new Point(bin_w * (i), hist_h - Math.round(normalizeHist.get(i - 1, 0)[0])), scalar, 1, 8, 0); Imgproc.line(histImage, new Point(bin_w * (i), hist_h - Math.round(normalizeHist.get(i - 1, 0)[0])), new Point(bin_w * (i), hist_h - Math.round(normalizeHist.get(i, 0)[0])), scalar, 1, 8, 0); } MatOfByte buffer = new MatOfByte(); Imgcodecs.imencode(".png", histImage, buffer); return new ImageIcon(buffer.toArray()); }
From source file:edu.wpi.cscore.RawCVMatSink.java
License:Open Source License
/** * Wait for the next frame and get the image. * Times out (returning 0) after timeout seconds. * The provided image will have three 3-bit channels stored in BGR order. * * @return Frame time, or 0 on error (call GetError() to obtain the error * message); the frame time is in 1 us increments. *//*w ww.jav a2 s . c o m*/ public long grabFrame(Mat image, double timeout) { frame.setWidth(0); frame.setHeight(0); frame.setPixelFormat(bgrValue); long rv = CameraServerJNI.grabSinkFrameTimeout(m_handle, frame, timeout); if (rv <= 0) { return rv; } if (frame.getDataByteBuffer() != origByteBuffer || width != frame.getWidth() || height != frame.getHeight() || pixelFormat != frame.getPixelFormat()) { origByteBuffer = frame.getDataByteBuffer(); height = frame.getHeight(); width = frame.getWidth(); pixelFormat = frame.getPixelFormat(); tmpMat = new Mat(frame.getHeight(), frame.getWidth(), getCVFormat(VideoMode.getPixelFormatFromInt(pixelFormat)), origByteBuffer); } tmpMat.copyTo(image); return rv; }
From source file:emotion.StaticFunctions.java
public static Mat gabor(Mat image) { Mat img = image.clone();//from w w w . j a va 2 s . c om double ksize = 15; double sigme = 4; double gamma = 1; double psi = 50; int lambd[] = new int[] { 5, 6, 7, 10/*,15,13,2*/ }; double theta[] = new double[] { 180, 200 }; ArrayList<Mat> kernels = new ArrayList<>(); for (int i = 0; i < theta.length; i++) { for (int j = 0; j < lambd.length; j++) { kernels.add(Imgproc.getGaborKernel(new Size(ksize, ksize), sigme, theta[i], lambd[j], gamma, psi, CvType.CV_32F)); } } Mat result = new Mat(img.height(), img.width(), img.type(), new Scalar(0, 0, 0)); for (Mat kernel : kernels) { Mat temp = new Mat(img.height(), img.width(), img.type(), new Scalar(0, 0, 0)); Imgproc.filter2D(img, temp, -1, kernel); Core.add(result, temp, result); } //imwrite("gaborResult.jpg",result); return result; }
From source file:es.ugr.osgiliart.drawer.OpenCVCollageDrawer.java
License:Open Source License
@Override public void draw(ArtisticIndividual artistic) { /*//from w w w .j a v a 2s. c om * */ int imageWidth = (Integer) this.getAlgorithmParameters().getParameter(ArtisticParameters.IMAGE_WIDTH); int imageHeight = (Integer) this.getAlgorithmParameters().getParameter(ArtisticParameters.IMAGE_HEIGHT); String imageType = (String) this.getAlgorithmParameters().getParameter(ArtisticParameters.IMAGE_TYPE); String folderPath = (String) this.getAlgorithmParameters().getParameter(ArtisticParameters.DATA_FOLDER); List<Primitive> primitives = ((ArtisticGenome) artistic.getGenome()).getPrimitives(); Mat orig = new Mat(imageWidth, imageHeight, CvType.CV_8UC3, new Scalar(255, 255, 255)); for (Primitive p : primitives) { Patch patch = (Patch) p; Mat pm = patch.getMat(); int posCol = (int) (patch.getLocation().x * orig.cols()); int posRow = (int) (patch.getLocation().y * orig.rows()); int finalCol = posCol + pm.cols(); int finalRow = posRow + pm.rows(); if (finalCol > orig.cols()) finalCol = orig.cols(); if (finalRow > orig.rows()) finalRow = orig.rows(); //System.out.println("Poniendo imagen de tamao "+pm.rows()+","+pm.cols()+" en "+posRow+","+posCol+" hasta "+finalRow+","+finalCol); Mat bSubmat = orig.submat(posRow, finalRow, posCol, finalCol); pm.copyTo(bSubmat); } /* * draw image ****************************************************/ /*save image */ String imageExtension = null; if (imageType.equalsIgnoreCase(IMAGE_TYPE_JPEG)) { imageExtension = "jpg"; } else if (imageType.equalsIgnoreCase(IMAGE_TYPE_PNG)) { imageExtension = "png"; } if (imageExtension != null) { String imagePath = String.format("%s/%s.%s", folderPath, artistic.getId(), imageExtension); //System.out.println("Saving... " + imagePath + " primitives: " + primitives.size()); //graphics.save(imagePath); //applet.save(imagePath); Highgui.imwrite(imagePath, orig); artistic.setImagePath(imagePath); } }
From source file:imageprocess.HistogramProcessor.java
public static Mat getHistogramImage(Mat image) { // Compute histogram first Mat hist = getGrayHistogram(image);/*from w w w.j av a 2s . co m*/ // Get min and max bin values MinMaxLocResult locPeak = Core.minMaxLoc(hist); double maxVal = locPeak.maxVal; double minVal = locPeak.minVal; // Image on which to display histogram Mat histImg = new Mat(image.rows(), image.rows(), CV_8U, new Scalar(255)); // set highest point at 90% of nbins int hpt = (int) (0.9 * 256); // Draw vertical line for each bin for (int h = 0; h < 256; h++) { double[] f = hist.get(h, 0); float binVal = (float) f[0]; int intensity = (int) (binVal * hpt / maxVal); Core.line(histImg, new Point(h, 256.0d), new Point(h, 256.0d - intensity), Scalar.all(0)); } return histImg; }
From source file:javaapplication1.JavaApplication1.java
public static void main(String[] args) { // you must load the OpenCV library like this before trying to do // anything with OpenCV! System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Print OpenCV version System.out.println("Welcome to OpenCV " + Core.VERSION); // In OpenCV, the most important data type is the Matrix, Mat. ////w w w.j a va2 s . co m // Here, we create a matrix that has 5 rows and 10 columns. It // stores an 8-bit type with a single channel. In other words, a // matrix of bytes. We'll initialize every element to 0. Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0)); // Dump information about the matrix System.out.println("OpenCV Mat: " + m); // set row 1 to be all 1s, and then column 5 to be all 5s Mat mr1 = m.row(1); mr1.setTo(new Scalar(1)); Mat mc5 = m.col(5); mc5.setTo(new Scalar(5)); // Dump the actual matrix contents System.out.println("OpenCV Mat data:\n" + m.dump()); Ocv ocv = new Ocv(); ocv.getFilePath(); /** * Find faces in an image. * * @param filter Path to the xml face finding filter to use * @param input Path to the input image file * @param output Path to the output image file */ //ocv.findFaces("lbpcascade_frontalface.xml", "C:\\Users\\Wellesley\\Documents\\GitHub\\CSE398\\opencvTutorial\\JavaApplication1\\src\\javaapplication1\\lena.png", "../javaapplication1"); ocv.setOutput("step2.png"); ocv.findFaces("", "", ""); ocv.setOutput("step3.png"); ocv.cropEachFace("", ""); ocv.setOutput("step4.png"); ocv.resizeEachFace("", ""); ocv.setOutput("step6.png"); ocv.makeFacesGray("", "", ""); ocv.setOutput("step8.png"); ocv.blendWithGray50("", ""); ocv.setOutput("step10.png"); ocv.doSobel("", ""); ocv.setOutput("step11.png"); ocv.directManip("", ""); }