List of usage examples for org.opencv.core Core convertScaleAbs
public static void convertScaleAbs(Mat src, Mat dst, double alpha, double beta)
From source file:logic.imagelocalizator.EyeBrowsLocalizator.java
private boolean detectEyeBrowBoundRect(MatContainer mc) { int eyePairW = mc.eyePairRect.width; int eyePairH = mc.eyePairRect.height; //contains eyebrow bounding rectangles Rect boundRectArr[] = new Rect[2]; //for each eyebrow Mat binMat = new Mat(); for (int i = 0; i < 2; ++i) { mc.eyeBrowMatArr[i] = mc.grayFrame.submat(mc.eyeBrowRectArr[i]); Scalar meanScalar = Core.mean(mc.eyeBrowMatArr[i]); //negate image Core.convertScaleAbs(mc.eyeBrowMatArr[i], mc.eyeBrowMatArr[i], 1, 255 - meanScalar.val[0]); Imgproc.equalizeHist(mc.eyeBrowMatArr[i], mc.eyeBrowMatArr[i]); Imgproc.blur(mc.eyeBrowMatArr[i], mc.eyeBrowMatArr[i], new Size(4, 4)); //obtain binary image Imgproc.threshold(mc.eyeBrowMatArr[i], binMat, 70, 255, Imgproc.THRESH_BINARY_INV); Imgproc.morphologyEx(binMat, binMat, Imgproc.MORPH_OPEN, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(4, 4))); //find contours List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Imgproc.findContours(binMat, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); //find the biggest contour int maxSize = -1; int tmpSize = -1; int index = -1; if (contours.size() != 0) { maxSize = contours.get(0).toArray().length; tmpSize = 0;/*from w ww .ja v a 2 s . com*/ index = 0; } //find max contour for (int j = 0; j < contours.size(); ++j) { //if contour is vertical, exclude it Rect boundRect = Imgproc.boundingRect(contours.get(j)); if (boundRect.height > boundRect.width) continue; if ((double) boundRect.height / (double) mc.eyeBrowRectArr[i].height > Parameters.eyebrowBoundRectThresh) { LOG.warn("Reset brow rect"); mc.eyeBrowBoundRectArr[i] = null; return false; } tmpSize = contours.get(j).toArray().length; LOG.info("Contour " + j + "; size = " + tmpSize); if (tmpSize > maxSize) { maxSize = tmpSize; index = j; } } binMat.setTo(new Scalar(0)); boundRectArr[i] = Imgproc.boundingRect(contours.get(index)); //save eyebrow bounding rectangle mc.eyeBrowBoundRectArr[i] = new Rect(mc.eyeBrowRectArr[i].x + boundRectArr[i].x, mc.eyeBrowRectArr[i].y + boundRectArr[i].y, boundRectArr[i].width, boundRectArr[i].height); //save binary eyebrow Mat for further FP detection (skeletonization) mc.eyeBrowBinMatArr[0] = binMat; //define tracking template for eyebrow mc.eyeBrowTrackingTemplateArr[i] = mc.grayFrame.submat(mc.eyeBrowBoundRectArr[i]); } //compute eyebrow interrocular distance mc.eyeBrowBaseDst = Math.abs(mc.eyeBrowBoundRectArr[0].x + mc.eyeBrowBoundRectArr[0].width / 2 - (mc.eyeBrowBoundRectArr[1].x + mc.eyeBrowBoundRectArr[1].width / 2)); LOG.info("eyeBrowBaseDst = " + mc.eyeBrowBaseDst); //define new bound rect centers for tracking template mc.eyeBrowCentersPointsArr = new Point[2]; return true; }
From source file:logic.localizator.EyeBrowsLocalizator.java
private boolean detectEyeBrowBoundRect(MatContainer mc) { int eyePairW = mc.eyePairRect.width; int eyePairH = mc.eyePairRect.height; //contains eyebrow bounding rectangles Rect boundRectArr[] = new Rect[2]; //for each eyebrow Mat binMat = new Mat(); for (int i = 0; i < 2; ++i) { mc.eyeBrowMatArr[i] = mc.grayFrame.submat(mc.eyeBrowRectArr[i]); Scalar meanScalar = Core.mean(mc.eyeBrowMatArr[i]); //negate image Core.convertScaleAbs(mc.eyeBrowMatArr[i], mc.eyeBrowMatArr[i], 1, 255 - meanScalar.val[0]); Imgproc.equalizeHist(mc.eyeBrowMatArr[i], mc.eyeBrowMatArr[i]); Imgproc.blur(mc.eyeBrowMatArr[i], mc.eyeBrowMatArr[i], new Size(4, 4)); //obtain binary image Imgproc.threshold(mc.eyeBrowMatArr[i], binMat, 70, 255, Imgproc.THRESH_BINARY_INV); Imgproc.morphologyEx(binMat, binMat, Imgproc.MORPH_OPEN, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(4, 4))); //find contours List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Imgproc.findContours(binMat, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); //find the biggest contour int maxSize = -1; int tmpSize = -1; int index = -1; if (contours.size() != 0) { maxSize = contours.get(0).toArray().length; tmpSize = 0;/*w ww . jav a2s . co m*/ index = 0; } //find max contour for (int j = 0; j < contours.size(); ++j) { //if contour is vertical, exclude it Rect boundRect = Imgproc.boundingRect(contours.get(j)); if (boundRect.height > boundRect.width) continue; if ((double) boundRect.height / (double) mc.eyeBrowRectArr[i].height > Parameters.eyebrowBoundRectThresh) { LOG.warn("Reset brow rect"); mc.eyeBrowBoundRectArr[i] = null; return false; } tmpSize = contours.get(j).toArray().length; LOG.info("Contour " + j + "; size = " + tmpSize); if (tmpSize > maxSize) { maxSize = tmpSize; index = j; } } binMat.setTo(new Scalar(0)); boundRectArr[i] = Imgproc.boundingRect(contours.get(index)); //save eyebrow bounding rectangle mc.eyeBrowBoundRectArr[i] = new Rect(mc.eyeBrowRectArr[i].x + boundRectArr[i].x, mc.eyeBrowRectArr[i].y + boundRectArr[i].y, boundRectArr[i].width, boundRectArr[i].height); //save binary eyebrow Mat for further FP detection (skeletonization) mc.eyeBrowBinMatArr[0] = binMat; //define tracking template for eyebrow mc.eyeBrowTrackingTemplateArr[i] = mc.grayFrame.submat(mc.eyeBrowBoundRectArr[i]); //local rectangle } //compute eyebrow interrocular distance mc.eyeBrowBaseDst = Math.abs(mc.eyeBrowBoundRectArr[0].x + mc.eyeBrowBoundRectArr[0].width / 2 - (mc.eyeBrowBoundRectArr[1].x + mc.eyeBrowBoundRectArr[1].width / 2)); LOG.info("eyeBrowBaseDst = " + mc.eyeBrowBaseDst); //define new bound rect centers for tracking template mc.eyeBrowCentersPointsArr = new Point[2]; //save eyebrow centers //left-right Point p1 = new Point( mc.eyePairGlobalRect.x + mc.eyeBrowBoundRectArr[0].x + mc.eyeBrowBoundRectArr[0].width / 2, mc.eyePairGlobalRect.y + mc.eyeBrowBoundRectArr[0].y + mc.eyeBrowBoundRectArr[0].height / 2); Point p2 = new Point( mc.eyePairGlobalRect.x + mc.eyeBrowBoundRectArr[1].x + mc.eyeBrowBoundRectArr[1].width / 2, mc.eyePairGlobalRect.y + mc.eyeBrowBoundRectArr[1].y + mc.eyeBrowBoundRectArr[1].height / 2); Point[] pointArr = new Point[2]; pointArr[0] = p1; pointArr[1] = p2; mc.features.eyeBrowCenterPointArr = pointArr; return true; }