List of usage examples for org.opencv.core Point Point
public Point(double x, double y)
From source file:logic.analyzer.VideoAnalyzer.java
/** * Algorithm: INITIAL LOCALIZATION * Open port // w w w . j a v a2s. com * Take frame * Preprocess frame * Localize face * Localize eyepair * Localize mouth * OBJECT TRACKING * Track eyebrows * Rotate frame * Track mouth * FEATURE POINT EXTRACTION * Extract mouth Features */ @Override public void analyze() { //open port if (!this.imLoader.open()) return; //define counter for retrived Frames. If count = 0, then run //INITIAL LOCALIZATION, other wise skip INITIAL LOCALIZATION boolean isRunInit = true; //set status flag in container.features to false //set to false when will be error. //It means that drawing process must be run from the begining //localize ROI and extract FP retrieve_frame: do { //take frame container.origFrame = this.imLoader.loadImage(); if (container.origFrame == null) continue; //Preprocess frame container.grayFrame = Util.preprocessFrame(container.origFrame); //run INITIAL LOCALIZATION initial_localization: while (isRunInit) { if (!detectFaceFeatures()) { //clear deque container.features.isStocked = true; container.featuresDeque.clear(); container.featuresDeque.add(container.features); continue retrieve_frame; } isRunInit = false; } //track face and eye pair //rotate frame int rotRes = rotateFrameAndTrackTemplate(container.eyeBrowBaseDst, container.eyePairRect.width, container.eyeBrowBoundRectArr, container.eyeBrowTrackingTemplateArr, container.eyeBrowCentersPointsArr, new Scalar(0, 0, 255)); if (rotRes != 1) { container.features.isStocked = true; container.featuresDeque.clear(); container.featuresDeque.add(container.features); isRunInit = true; continue retrieve_frame; } //track mouth (AFTER PUT TO INITIALIZATION STEP) container.mouthRect = Util.trackTemplate(container.grayFrame, container.mouthRect, container.mouthMat); //track nose container.noseRect = Util.trackTemplate(container.grayFrame, container.noseRect, container.noseMat); if (container.mouthRect == null) { container.features.isStocked = true; container.featuresDeque.clear(); container.featuresDeque.add(container.features); LOG.warn("Tracking pattern of nose is out of image scope"); isRunInit = true; continue retrieve_frame; } container.features.noseCenterPoint = new Point(container.noseRect.x + container.noseRect.width / 2, container.noseRect.y + container.noseRect.height / 2); Core.circle(container.origFrame, container.features.noseCenterPoint, 5, new Scalar(0, 0, 255), -1); Core.rectangle(container.origFrame, container.noseRect.tl(), container.noseRect.br(), new Scalar(255, 0, 0), 1); Core.rectangle(container.origFrame, container.mouthRect.tl(), container.mouthRect.br(), new Scalar(255, 0, 0), 1); //detect mouth FPE and show results mouthFPE.detect(container); //all features have been detected, therefore add features to deque if (container.features.isStocked) container.features.isStocked = false; container.featuresDeque.add(container.features); // imShowOrig.showImage(container.mouthProcessedMat); imShowProc.showImage(container.origFrame); } while (!isByKey); }
From source file:logic.featurepointextractor.EyeIrisesFPE.java
@Override public Point[] detect(MatContainer mc) { Mat eyePairMat = mc.grayEyePairMat;// w w w. j a v a2s .c o m Rect eyePairRect = mc.eyePairRect; Rect faceRect = mc.faceRect; //search for eye centers Mat circlesMat = new Mat(); double minDist = 2 * eyePairRect.width / 5; int minRad = eyePairRect.height / 5; int maxRad = 2 * eyePairRect.height / 3; Imgproc.HoughCircles(eyePairMat, circlesMat, Imgproc.CV_HOUGH_GRADIENT, 3.0, minDist, 200.0, 20.0, minRad, maxRad); float arr1[] = new float[3]; float arr2[] = new float[3]; if (circlesMat.size().width == 2) { circlesMat.get(0, 0, arr1); circlesMat.get(0, 1, arr2); float f11 = arr1[0], f12 = arr1[1], f21 = arr2[0], f22 = arr2[1]; if (Math.abs(f11 - f21) < Parameters.irisXDifferencesThreshold * eyePairRect.width && Math.abs(f12 - f22) > Parameters.irisYDifferencesThreshold) { //find where left and right eye if (f11 < f21) //left-right return new Point[] { new Point(f11 + faceRect.x + eyePairRect.x, f12 + faceRect.y + eyePairRect.y), new Point(f21 + faceRect.x + eyePairRect.x, f22 + faceRect.y + eyePairRect.y) }; else //right-left return new Point[] { new Point(f21 + faceRect.x + eyePairRect.x, f22 + faceRect.y + eyePairRect.y), new Point(f11 + faceRect.x + eyePairRect.x, f12 + faceRect.y + eyePairRect.y) }; } } LOG.warn("Extract eye iris: FAIL"); return null; }
From source file:logic.featurepointextractor.MouthFPE.java
/** * Detect mouth feature points//from ww w.j a v a 2 s. c o m * Algorithm: Equalize histogram of mouth rect * Implement Sobel horizontal filter * Find corners * Invert color + Binarization * Find lip up and down points * @param mc * @return */ @Override public Point[] detect(MatContainer mc) { /**Algorithm * find pix(i) = (R-G)/R * normalize: 2arctan(pix(i))/pi */ //find pix(i) = (R-G)/R Mat mouthRGBMat = mc.origFrame.submat(mc.mouthRect); List mouthSplitChannelsList = new ArrayList<Mat>(); Core.split(mouthRGBMat, mouthSplitChannelsList); //extract R-channel Mat mouthR = (Mat) mouthSplitChannelsList.get(2); mouthR.convertTo(mouthR, CvType.CV_64FC1); //extract G-channel Mat mouthG = (Mat) mouthSplitChannelsList.get(1); mouthG.convertTo(mouthG, CvType.CV_64FC1); //calculate (R-G)/R Mat dst = new Mat(mouthR.rows(), mouthR.cols(), CvType.CV_64FC1); mc.mouthProcessedMat = new Mat(mouthR.rows(), mouthR.cols(), CvType.CV_64FC1); Core.absdiff(mouthR, mouthG, dst); // Core.divide(dst, mouthR, mc.mouthProcessedMat); mc.mouthProcessedMat = dst; mc.mouthProcessedMat.convertTo(mc.mouthProcessedMat, CvType.CV_8UC1); Imgproc.equalizeHist(mc.mouthProcessedMat, mc.mouthProcessedMat); // Imgproc.blur(mc.mouthProcessedMat, mc.mouthProcessedMat, new Size(4,4)); // Imgproc.morphologyEx(mc.mouthProcessedMat, mc.mouthProcessedMat, Imgproc.MORPH_OPEN, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(4,4))); Imgproc.threshold(mc.mouthProcessedMat, mc.mouthProcessedMat, 230, 255, THRESH_BINARY); List<MatOfPoint> contours = new ArrayList<MatOfPoint>(); Imgproc.findContours(mc.mouthProcessedMat, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); //find the biggest contour int maxSize = -1; int tmpSize = -1; int index = -1; Rect centMouthRect = new Rect(mc.mouthRect.x + mc.mouthRect.width / 4, mc.mouthRect.y + mc.mouthRect.height / 4, mc.mouthRect.width / 2, mc.mouthRect.height / 2); if (contours.size() != 0) { maxSize = contours.get(0).toArray().length; tmpSize = 0; 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)); int centX = mc.mouthRect.x + boundRect.x + boundRect.width / 2; int centY = mc.mouthRect.y + boundRect.y + boundRect.height / 2; // LOG.info("Center = " + centX + "; " + centY); // LOG.info("Rect = " + centMouthRect.x + "; " + centMouthRect.y); if (!centMouthRect.contains(new Point(centX, centY))) continue; tmpSize = contours.get(j).toArray().length; LOG.info("Contour " + j + "; size = " + tmpSize); if (tmpSize > maxSize) { maxSize = tmpSize; index = j; } } //appproximate curve Point[] p1 = contours.get(index).toArray(); MatOfPoint2f p2 = new MatOfPoint2f(p1); MatOfPoint2f p3 = new MatOfPoint2f(); Imgproc.approxPolyDP(p2, p3, 1, true); p1 = p3.toArray(); MatOfInt tmpMatOfPoint = new MatOfInt(); Imgproc.convexHull(new MatOfPoint(p1), tmpMatOfPoint); Rect boundRect = Imgproc.boundingRect(new MatOfPoint(p1)); if (boundRect.area() / mc.mouthRect.area() > 0.3) return null; int size = (int) tmpMatOfPoint.size().height; Point[] _p1 = new Point[size]; int[] a = tmpMatOfPoint.toArray(); _p1[0] = new Point(p1[a[0]].x + mc.mouthRect.x, p1[a[0]].y + mc.mouthRect.y); Core.circle(mc.origFrame, _p1[0], 3, new Scalar(0, 0, 255), -1); for (int i = 1; i < size; i++) { _p1[i] = new Point(p1[a[i]].x + mc.mouthRect.x, p1[a[i]].y + mc.mouthRect.y); Core.circle(mc.origFrame, _p1[i], 3, new Scalar(0, 0, 255), -1); Core.line(mc.origFrame, _p1[i - 1], _p1[i], new Scalar(255, 0, 0), 2); } Core.line(mc.origFrame, _p1[size - 1], _p1[0], new Scalar(255, 0, 0), 2); /* contours.set(index, new MatOfPoint(_p1)); mc.mouthProcessedMat.setTo(new Scalar(0)); Imgproc.drawContours(mc.mouthProcessedMat, contours, index, new Scalar(255), -1); */ mc.mouthMatOfPoint = _p1; MatOfPoint matOfPoint = new MatOfPoint(_p1); mc.mouthBoundRect = Imgproc.boundingRect(matOfPoint); mc.features.mouthBoundRect = mc.mouthBoundRect; /**extract feature points: 1 most left * 2 most right * 3,4 up * 5,6 down */ // mc.mouthMatOfPoint = extractFeaturePoints(contours.get(index)); return null; }
From source file:logic.helpclass.Util.java
/** * Track template within the image// ww w .j a va 2 s . co m * @param grayFrame * @param rect * @param temp * @return */ static public Rect trackTemplate(Mat grayFrame, Rect rect, Mat temp) { Rect searchRect = new Rect(new Point(rect.x - rect.width / 2, rect.y - rect.height / 2), new Point(rect.x + rect.width * 3 / 2, rect.y + rect.height * 3 / 2)); Mat dst = new Mat(searchRect.width - temp.width() + 1, searchRect.height - temp.height() + 1, CV_32FC1); if ((searchRect.x < 0 || searchRect.y < 0) || (searchRect.x + searchRect.width > grayFrame.cols() || searchRect.y + searchRect.height > grayFrame.rows())) return null; Imgproc.matchTemplate(grayFrame.submat(searchRect), temp, dst, Imgproc.TM_SQDIFF_NORMED); Core.MinMaxLocResult result = Core.minMaxLoc(dst); //check new location: if coordinates change so variously, remain previous location if (true) { rect.x = (int) (searchRect.x + result.minLoc.x); rect.y = (int) (searchRect.y + result.minLoc.y); return rect; } else { return null; } }
From source file:logic.imagelocalizator.EyeBrowsLocalizator.java
@Override public boolean localize(MatContainer mc) { Rect eyePairRect = mc.eyePairRect;//ww w .j a va 2s .com int width = eyePairRect.width; int height = eyePairRect.height; //build eyebrown search rectangle int x, y, w, h; double shiftH = 0.13, shiftV = 0.1; Point browPoint1UpLft = null, browPoint2UpLft = null, browPointDwnRght1 = null, browPointDwnRght2 = null; double browROIHeight = eyePairRect.y; /* if(mc.irisPointsArr[0].y > mc.irisPointsArr[1].y) { browPoint1 = new Point(mc.irisPointsArr[0].x - eyePairW * shiftH * 2, mc.irisPointsArr[1].y - eyePairH * shiftV); browPoint2 = new Point(mc.irisPointsArr[1].x + eyePairW * shiftH * 2, mc.irisPointsArr[1].y - browROIHeight ); } else { browPoint1 = new Point(mc.irisPointsArr[0].x - eyePairW * shiftH * 2, mc.irisPointsArr[0].y - eyePairH * shiftV); browPoint2 = new Point(mc.irisPointsArr[1].x + eyePairW * shiftH * 2, mc.irisPointsArr[0].y - browROIHeight); } Point middlePointDown = new Point(browPoint1.x + (browPoint2.x - browPoint1.x)/2, browPoint2.y); Point middlePointUp = new Point(browPoint1.x + (browPoint2.x - browPoint1.x)/2, browPoint1.y); mc.eyeBrowRectArr[0] = new Rect(browPoint1, middlePointDown); mc.eyeBrowRectArr[1] = new Rect(middlePointUp, browPoint2); mc.eyeBrowMatArr[0] = mc.grayFrame.submat(mc.eyeBrowRectArr[0]); mc.eyeBrowMatArr[1] = mc.grayFrame.submat(mc.eyeBrowRectArr[1]); */ //define eyebrow searching rectangle browPoint1UpLft = new Point(mc.faceRect.x + eyePairRect.x, mc.faceRect.y + eyePairRect.y - height / 2); browPointDwnRght1 = new Point(mc.faceRect.x + eyePairRect.x + width / 2, mc.faceRect.y + eyePairRect.y + height / 2); browPoint2UpLft = new Point(mc.faceRect.x + eyePairRect.x + width / 2, mc.faceRect.y + eyePairRect.y - height / 2); browPointDwnRght2 = new Point(mc.faceRect.x + eyePairRect.x + width, mc.faceRect.y + eyePairRect.y + height / 2); mc.eyeBrowRectArr[0] = new Rect(browPoint1UpLft, browPointDwnRght1); mc.eyeBrowRectArr[1] = new Rect(browPoint2UpLft, browPointDwnRght2); //save Mat from eyeBrowRect mc.eyeBrowMatArr[0] = mc.grayFrame.submat(mc.eyeBrowRectArr[0]); mc.eyeBrowMatArr[1] = mc.grayFrame.submat(mc.eyeBrowRectArr[1]); //detect eyebrows if (!detectEyeBrowBoundRect(mc)) return false; return true; }
From source file:logic.imagelocalizator.MouthLocalizator.java
/**Localizes mouth rectangle * Divide face on upRect end botRect * Extract Mat from botRect/*w w w.j a va2 s . c om*/ * Equalize botMat * Find mouthRect using Haar cascades * Enlarge mouthRect according to face size * @param mc * @return mouthRect, mouthMat */ @Override public boolean localize(MatContainer mc) { /* Mouth Localization by Haar cascades*/ /* //Divide face on upRect end botRect int start_x = mc.faceRect.x; int start_y = mc.faceRect.y + (int)mc.faceRect.height*2/3; int end_x = start_x + mc.faceRect.width; int end_y = start_y + (int)mc.faceRect.height*2/3; end_x = end_x >= mc.grayFrame.width() ? mc.grayFrame.width() : end_x; end_y = end_y >= mc.grayFrame.height() ? mc.grayFrame.height() : end_y; mc.mouthRect = new Rect(new Point(start_x, start_y), new Point(end_x, end_y)); //Extract Mat from botRect LOG.error(mc.mouthRect.tl() + " " + mc.mouthRect.br()); LOG.error(mc.grayFrame.size()); mc.mouthMat = mc.grayFrame.submat(mc.mouthRect); //Equalize botMat Imgproc.equalizeHist(mc.mouthMat, mc.mouthMat); //Find mouthRect using Haar cascades MatOfRect mouthRectMat = new MatOfRect(); mouthCascade.detectMultiScale(mc.mouthMat, mouthRectMat); Rect rMat[] = mouthRectMat.toArray(); //find real mouth within detected mouth array rMat List<Rect> newFacesArr = new ArrayList(); for(Rect rect:rMat) { rect = new Rect(rect.x + mc.faceRect.x, rect.y + mc.faceRect.y + mc.faceRect.height*2/3, rect.width, rect.height); //check if rect out of face if(!mc.faceRect.contains(rect.br()) || !mc.faceRect.contains(rect.tl())) continue; newFacesArr.add(rect); } if( newFacesArr.size() !=1 )//need just 1 mouth { LOG.warn("Detected mouth number: " + newFacesArr.size()); return false; } //Enlarge mouthRect according to mouth size Rect rect = newFacesArr.get(0); int enlargeX = (int)Math.round(Parameters.enlargeMouthRect * rect.width); int enlargeY = (int)Math.round(Parameters.enlargeMouthRect * rect.height); mc.mouthRect = new Rect(rect.x - enlargeX, rect.y - enlargeY, rect.width + enlargeX*2, rect.height + enlargeY*2); //save mat for mouth mc.mouthMat = mc.grayFrame.submat(mc.mouthRect); */ /*Localization by enlarging: mouth rectangle can be defined as third lower part of face rect with enlarging over 1/5 of face lower part: Mouth_rect = faceY + faceHeight*3/2 + faceHeight/5 */ int heightFace = mc.faceRect.height; int mouthHeight = heightFace * 1 / 3 + heightFace / 5; int tmp = mc.faceRect.y + heightFace * 2 / 3 + mouthHeight; int mouthEndY = tmp < mc.origFrame.width() ? tmp : mc.origFrame.width(); mc.mouthRect = new Rect(new Point(mc.faceRect.x, mc.faceRect.y + heightFace * 2 / 3), new Point(mc.faceRect.x + mc.faceRect.width, mouthEndY)); mc.mouthMat = mc.grayFrame.submat(mc.mouthRect); //show results Core.rectangle(mc.origFrame, mc.mouthRect.tl(), mc.mouthRect.br(), new Scalar(0, 0, 255)); // Core.rectangle(mc.origFrame, mc.faceRect.tl(), mc.faceRect.br(), new Scalar(0,0,255)); return true; }
From source file:logic.localizator.EyeBrowsLocalizator.java
@Override public boolean localize(MatContainer mc) { Rect eyePairRect = mc.eyePairRect;//non global rectangle int width = eyePairRect.width; int height = eyePairRect.height; //build eyebrown search rectangle int x, y, w, h; double shiftH = 0.13, shiftV = 0.1; Point browPoint1UpLft = null, browPoint2UpLft = null, browPointDwnRght1 = null, browPointDwnRght2 = null; double browROIHeight = eyePairRect.y; /* /*from w w w . j av a2 s . c o m*/ if(mc.irisPointsArr[0].y > mc.irisPointsArr[1].y) { browPoint1 = new Point(mc.irisPointsArr[0].x - eyePairW * shiftH * 2, mc.irisPointsArr[1].y - eyePairH * shiftV); browPoint2 = new Point(mc.irisPointsArr[1].x + eyePairW * shiftH * 2, mc.irisPointsArr[1].y - browROIHeight ); } else { browPoint1 = new Point(mc.irisPointsArr[0].x - eyePairW * shiftH * 2, mc.irisPointsArr[0].y - eyePairH * shiftV); browPoint2 = new Point(mc.irisPointsArr[1].x + eyePairW * shiftH * 2, mc.irisPointsArr[0].y - browROIHeight); } Point middlePointDown = new Point(browPoint1.x + (browPoint2.x - browPoint1.x)/2, browPoint2.y); Point middlePointUp = new Point(browPoint1.x + (browPoint2.x - browPoint1.x)/2, browPoint1.y); mc.eyeBrowRectArr[0] = new Rect(browPoint1, middlePointDown); mc.eyeBrowRectArr[1] = new Rect(middlePointUp, browPoint2); mc.eyeBrowMatArr[0] = mc.grayFrame.submat(mc.eyeBrowRectArr[0]); mc.eyeBrowMatArr[1] = mc.grayFrame.submat(mc.eyeBrowRectArr[1]); */ //define eyebrow searching rectangle browPoint1UpLft = new Point(mc.faceRect.x + eyePairRect.x, mc.faceRect.y + eyePairRect.y - height / 2); browPointDwnRght1 = new Point(mc.faceRect.x + eyePairRect.x + width / 2, mc.faceRect.y + eyePairRect.y + height / 2); browPoint2UpLft = new Point(mc.faceRect.x + eyePairRect.x + width / 2, mc.faceRect.y + eyePairRect.y - height / 2); browPointDwnRght2 = new Point(mc.faceRect.x + eyePairRect.x + width, mc.faceRect.y + eyePairRect.y + height / 2); mc.eyeBrowRectArr[0] = new Rect(browPoint1UpLft, browPointDwnRght1); mc.eyeBrowRectArr[1] = new Rect(browPoint2UpLft, browPointDwnRght2); //save Mat from eyeBrowRect mc.eyeBrowMatArr[0] = mc.grayFrame.submat(mc.eyeBrowRectArr[0]); mc.eyeBrowMatArr[1] = mc.grayFrame.submat(mc.eyeBrowRectArr[1]); //detect eyebrows if (!detectEyeBrowBoundRect(mc)) return false; 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;//from ww w . ja va 2 s . 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; }
From source file:logic.localizator.FaceLocalizator.java
@Override public boolean localize(MatContainer mc) { //Extract face MatOfRect faceRectMat = new MatOfRect(); faceCascade.detectMultiScale(mc.grayFrame, faceRectMat); Rect rMat[] = faceRectMat.toArray(); LOG.info("Detected faces = " + rMat.length); if (Parameters.isDetectSingleFace) { if (rMat.length != 1)//need just 1 face {/*from ww w . j a v a 2 s . c om*/ return false; } } LOG.trace("Face rect was detected"); mc.faceRect = rMat[0]; mc.grayFaceMat = mc.grayFrame.submat(rMat[0]); mc.colorFaceMat = mc.origFrame.submat(rMat[0]); //save face center mc.features.faceCenterPoint = new Point(rMat[0].x + rMat[0].width / 2, rMat[0].y + rMat[0].height / 2); return true; }
From source file:logic.localizator.NoseLocalizator.java
@Override public boolean localize(MatContainer mc) { //consider rectangle between eye pair and mouth int startX, startY, width, height; width = mc.mouthRect.width / 2;/*w w w.j a v a 2s . c om*/ startX = mc.mouthRect.x + width / 2; height = (int) Math.round(0.4 * (mc.mouthRect.y - mc.eyePairGlobalRect.y)); startY = mc.eyePairGlobalRect.y + mc.eyePairGlobalRect.height + height / 4; mc.noseRect = new Rect(startX, startY, width, height); //Extract Mat from botRect mc.noseMat = mc.grayFrame.submat(mc.noseRect); //save to features in container mc.features.noseCenterPoint = new Point(mc.noseRect.x + mc.noseRect.width / 2, mc.noseRect.y + mc.noseRect.height / 2); return true; }