List of usage examples for org.opencv.core Mat Mat
public Mat(Mat m, Rect roi)
From source file:ctPrincipal.Ruidos.java
private String ruidoGaussiano(int mean, int desv) { Mat original_Bgr = image.clone();/* w w w . j a v a2 s. co m*/ Mat mGaussian_noise = new Mat(original_Bgr.size(), original_Bgr.type()); randn(mGaussian_noise, mean, desv); 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();// ww w. j a v a2s . c o m Mat mSaltPepper_noise = new Mat(saltPepper_img.size(), saltPepper_img.type()); randn(mSaltPepper_noise, 0, 255); 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:cubesolversimulator.VisualInputForm.java
private void findAvg(List<Rect> roi) { cols = new int[9]; for (int i = 0; i < roi.size(); i++) { Mat ri = new Mat(blured, roi.get(i)); ri.convertTo(ri, -1, 1.0);/* w w w.ja v a 2 s . c om*/ Highgui.imwrite("extract" + i + ".jpg", ri); Scalar clr = new Scalar(0, 0, 0); clr = Core.mean(ri); System.out.println("old col: " + clr); if (clr.val[0] > 30) clr.val[0] = clr.val[0] - 30; else clr.val[0] = 0; //if(clr.val[2]<200) // clr.val[2]=clr.val[2]+20; //else // clr.val[0]=0; System.out.println("new col: " + clr); getDistance(clr, i); } displayLabel(); }
From source file:cx.uni.jk.mms.iaip.mat.CrossMatListener.java
License:Open Source License
/** * do the transfer from source to this.target, using DCT or IDCT * //from ww w. ja va 2 s . c om * @param source */ private void transfer(MatModel source) { Mat matSource = source.getMat(); Mat matTarget = new Mat(matSource.size(), MatModel.MAT_TYPE); if (this.inverse) { Core.idct(matSource, matTarget); } else { Core.dct(matSource, matTarget); } this.target.setMat(matTarget); }
From source file:Domain.ImgProcess.java
public Mat DetectarFace(Canvas c, Mat image) throws IOException { System.out.println("Rodando DetectFace"); CascadeClassifier faceDetector = new CascadeClassifier( "C:\\Users\\Gertrude\\Documents\\NetBeansProjects\\OWL_Sight\\src\\Resources\\lbpcascade_frontalface.xml"); // seleciona o classificador para identificao da face MatOfRect faceDetections = new MatOfRect(); //matriz de rectangulos representando os rosto encontrados faceDetector.detectMultiScale(image, faceDetections);//detecta multiplas faces na imagem fornecida System.out.printf("Detected %s faces", faceDetections.toArray().length); Mat corte = null;/*from w w w .j a v a 2 s. co m*/ for (Rect rect : faceDetections.toArray()) { Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 0, 0));// desenha os rectangulos // Highgui.imwrite("C:/TCC-FacialRecognize/src/resources/TESTECORTE.jpg", utl.corte(image, rect)); corte = new Mat(image, rect); } Size sz = new Size(120, 120); MatOfByte bytemat = new MatOfByte(); //transformando a matriz image em uma matriz de bytes para carga no canvas do form principal Highgui.imencode(".jpg", corte, bytemat); byte[] bytes = bytemat.toArray(); InputStream in = new ByteArrayInputStream(bytes); BufferedImage render = ImageIO.read(in); Graphics g = c.getGraphics(); g.drawImage(render, 1, 1, c.getHeight(), c.getWidth(), c); return corte; }
From source file:emotion.Eye.java
public Eye(Mat _face) { reg = null;/*from ww w . ja v a 2 s . com*/ CascadeClassifier eyes_cascade; eyes_cascade = new CascadeClassifier( "E:\\Studia\\OpenCV\\opencv\\sources\\data\\haarcascades\\haarcascade_eye.xml"); //Detect faces and write eyeLine to array of rectangles MatOfRect eyes = new MatOfRect(); eyes_cascade.detectMultiScale(_face, eyes); if (eyes.toArray().length == 0) { Logger.getLogger("No face found in the image!"); return; } for (int i = 0; i < eyes.toList().size(); ++i) { Rect tempRect = eyes.toArray()[i].clone(); if (tempRect.x < _face.width() / 2) { Eye.leftRect = recalculate(tempRect, _face); Eye.leftEye = new Mat(_face, Eye.leftRect); imwrite("leftEYe.jpg", Eye.leftEye); } else { Eye.rightRect = recalculate(tempRect, _face); Eye.rightEye = new Mat(_face, Eye.rightRect); imwrite("rightEye.jpg", Eye.rightEye); } } templatingOuterCorner(Eye.leftEye, false); templatingInnerCorner(Eye.leftEye, false); templatingOuterCorner(Eye.rightEye, true); templatingInnerCorner(Eye.rightEye, true); }
From source file:emotion.Eye.java
public void examineEyeOpeness(boolean rightEyeFlag) { Rect pureEyeRegion;/*www . j a va 2s . co m*/ //We take just middle half of strict eye region determined //by localized eye corners if (rightEyeFlag) { double regionWidth = EyeRegion.rightOuterEyeCorner.x - EyeRegion.rightInnerEyeCorner.x; pureEyeRegion = new Rect((int) (EyeRegion.rightInnerEyeCorner.x + regionWidth / 2 - 2), (int) (Eye.rightRect.y), (4), Eye.rightRect.height); imwrite("strictEyeRegRight.jpg", new Mat(EyeRegion._face, pureEyeRegion)); //Setting x coordinates of eyelids EyeRegion.rightLowerEyelid.x = (EyeRegion.rightOuterEyeCorner.x + EyeRegion.rightInnerEyeCorner.x) / 2; EyeRegion.rightUpperEyelid.x = EyeRegion.rightLowerEyelid.x; EyeRegion.rightEyeOpeness = (EyeRegion.rightUpperEyelid.y - EyeRegion.rightLowerEyelid.y); } else { double regionWidth; regionWidth = EyeRegion.leftInnerEyeCorner.x - EyeRegion.leftOuterEyeCorner.x; pureEyeRegion = new Rect((int) (regionWidth / 2 + EyeRegion.leftOuterEyeCorner.x - 2), (int) (Eye.leftRect.y), (4), Eye.leftRect.height); imwrite("leftEyeReg.jpg", new Mat(EyeRegion._face, pureEyeRegion)); //Setting x coordinates of eyelids EyeRegion.leftLowerEyelid.x = (EyeRegion.leftInnerEyeCorner.x + EyeRegion.leftOuterEyeCorner.x) / 2; EyeRegion.leftUpperEyelid.x = EyeRegion.leftLowerEyelid.x; EyeRegion.leftEyeOpeness = (EyeRegion.leftUpperEyelid.y - EyeRegion.leftLowerEyelid.y); } Mat strictEyeRegion = new Mat(EyeRegion._face, pureEyeRegion); Mat result = new Mat(); strictEyeRegion.convertTo(strictEyeRegion, CvType.CV_32F); Core.pow(strictEyeRegion, 1.27, strictEyeRegion); cvtColor(strictEyeRegion, strictEyeRegion, Imgproc.COLOR_BGR2GRAY); imwrite("improved.jpg", strictEyeRegion); threshold(strictEyeRegion, result, 100, 255, Imgproc.THRESH_BINARY_INV); Mat strEl = Imgproc.getStructuringElement(Imgproc.MORPH_CROSS, new Size(3, 1)); dilate(result, result, strEl, new Point(1, 0), 3); for (int i = 0; i < result.width(); i++) { for (int j = 0; j < result.height() * 0.4; j++) { result.put(j, i, new double[] { 0, 0, 0 }); } } for (int j = result.height() - 1; j >= 0; j--) { if (result.get(j, 0)[0] == 255) { if (rightEyeFlag) { if (EyeRegion.rightLowerEyelid.y == 0) { EyeRegion.rightLowerEyelid.y = j + 3; EyeRegion.rightLowerEyelid.y += Eye.rightRect.y; } EyeRegion.rightUpperEyelid.y = j; EyeRegion.rightUpperEyelid.y += Eye.rightRect.y; } else { if (EyeRegion.leftLowerEyelid.y == 0) { EyeRegion.leftLowerEyelid.y = j + 3; EyeRegion.leftLowerEyelid.y += Eye.leftRect.y; } EyeRegion.leftUpperEyelid.y = j; EyeRegion.leftUpperEyelid.y += Eye.leftRect.y; } } } imwrite("openessResult.jpg", result); }
From source file:emotion.EyeRegion.java
public static void areEyebrowsWrinkles() { //setting parameters int height = (int) (abs(rightInnerEyebrowsCorner.y - rightInnerEyeCorner.y) * 1.2); int width = (int) (rightInnerEyeCorner.x - leftInnerEyeCorner.x); int y = (int) (rightInnerEyebrowsCorner.y - height / 2); int x = (int) leftInnerEyebrowsCorner.x; Rect wrinklesRect = new Rect(x, y, width, height); Mat wrinklesArea = new Mat(_face, wrinklesRect).clone(); wrinklesThreshold = (int) (wrinklesArea.width() * wrinklesArea.height() * 0.085); //Wrinkles between eyebrows are vertical int[] gradientMask = new int[9]; gradientMask[0] = -1;/* ww w .j a v a 2s . c o m*/ gradientMask[1] = 0; gradientMask[2] = 1; gradientMask[3] = -5; gradientMask[4] = 0; gradientMask[5] = 5; gradientMask[6] = -1; gradientMask[7] = 0; gradientMask[8] = 1; wrinklesArea.convertTo(wrinklesArea, CvType.CV_32F); Imgproc.cvtColor(wrinklesArea, wrinklesArea, Imgproc.COLOR_BGR2GRAY); Core.pow(wrinklesArea, 1.09, wrinklesArea); imwrite("wrinklesArea.jpg", wrinklesArea); wrinklesArea = StaticFunctions.convolution(gradientMask, wrinklesArea); threshold(wrinklesArea, wrinklesArea, 110, 255, Imgproc.THRESH_BINARY); imwrite("wrinklesAreaGradiented.jpg", wrinklesArea); long wrinklesPoints = 0; for (int i = 0; i < wrinklesArea.width(); i++) { for (int j = 0; j < wrinklesArea.height(); j++) { if (wrinklesArea.get(j, i)[0] == 255) { wrinklesPoints++; } } } EyeRegion.wrinklesFactor = wrinklesPoints; // System.out.println("Wrinkles factor: "+wrinklesPoints); if (wrinklesPoints >= wrinklesThreshold) { // System.out.println("Expression wrinkles detected! Threshold exceeded"); Imgproc.rectangle(EyeRegion._face, wrinklesRect.br(), wrinklesRect.tl(), new Scalar(0, 50, 205)); } }
From source file:emotion.Face.java
/** * Detecting face- area of intrests/*from w w w .j a v a 2s. c o m*/ * This area will be used for further searching * Advantage: less data to analyze! * !!!This function has to be execute first!!! */ public void detectFace() { //Loading Haars' classyfier CascadeClassifier face_cascade; face_cascade = new CascadeClassifier( "E:\\Studia\\OpenCV\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt2.xml"); //Detect faces and write eyeLine to array of rectangles faceDetections = new MatOfRect(); face_cascade.detectMultiScale(head, faceDetections); if (faceDetections.toArray().length == 0) { Logger.getLogger("No face found in the image!"); return; } this.face = new Mat(head, faceDetections.toArray()[0]); //All templates for images 150x150px Imgproc.resize(this.face, this.face, new Size(150, 150)); //detectEyeRegions(this.face); EyeRegion eyeRegion = new EyeRegion(face); if (EyeRegion.unavailable) { Logger.getLogger("Unable to localize eye region!"); return; } Eye eyes = new Eye(this.face); // Eye eyes=new Eye(eyeRegion,false); new Eyebrow(eyeRegion, true); new Eyebrow(eyeRegion, false); eyes.examineEyeOpeness(true); eyes.examineEyeOpeness(false); EyeRegion.areEyebrowsWrinkles(); eyeRegion.showFaceFeatures(); eyeRegion.printData(); //Saving area of intrest imwrite("face.jpg", face); }
From source file:FaceGUI.ScannerGUI.java
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed Mat image_roi = new Mat(frame, rect_Crop); Imgproc.cvtColor(image_roi, image_roi, Imgproc.COLOR_BGR2GRAY); Size sz = new Size(200, 200); Imgproc.resize(image_roi, image_roi, sz); // Mat grayimg=new Mat(frame.getHeight(),frame.getWidth(),CvType.CV_8UC1); // Imgproc.cvtColor(image_roi, grayimg, Imgproc.COLOR_RGB2GRAY); String filename = "testimg\\" + jTextField1.getText() + ".bmp"; //String filename = "output.png"; System.out.println(String.format("Writing %s", filename)); // Highgui.imwrite(filename, frame); Imgcodecs.imwrite(filename, image_roi); // TODO add your handling code here: }