List of usage examples for org.opencv.core MatOfFloat toArray
public float[] toArray()
From source file:ch.zhaw.facerecognitionlibrary.Helpers.FaceDetection.java
License:Open Source License
public Eyes getEyes(Mat img) { double halfWidth = img.cols() / 2; double height = img.rows(); double[] values = new double[4]; values[0] = 0;/* w w w. j a va 2s .co m*/ values[1] = 0; values[2] = halfWidth; values[3] = height; Rect rightHalf = new Rect(values); values[0] = halfWidth; Rect leftHalf = new Rect(values); MatOfRect rightEyes = new MatOfRect(); MatOfRect leftEyes = new MatOfRect(); Mat rightHalfImg = img.submat(rightHalf); rightEyeDetector.detectMultiScale(rightHalfImg, rightEyes); Mat leftHalfImg = img.submat(leftHalf); leftEyeDetector.detectMultiScale(leftHalfImg, leftEyes); if (rightEyes.empty() || leftEyes.empty() || rightEyes.toArray().length > 1 || leftEyes.toArray().length > 1) { return null; } Rect rightEye = rightEyes.toArray()[0]; Rect leftEye = leftEyes.toArray()[0]; MatOfFloat rightPoint = new MatOfFloat(rightEye.x + rightEye.width / 2, rightEye.y + rightEye.height / 2); MatOfFloat leftPoint = new MatOfFloat(img.cols() / 2 + leftEye.x + leftEye.width / 2, leftEye.y + leftEye.height / 2); MatOfFloat diff = new MatOfFloat(); Core.subtract(leftPoint, rightPoint, diff); double angle = Core.fastAtan2(diff.toArray()[1], diff.toArray()[0]); double dist = Core.norm(leftPoint, rightPoint, Core.NORM_L2); Eyes eyes = new Eyes(dist, rightPoint, leftPoint, angle); return eyes; }
From source file:com.trandi.opentld.tld.LKTracker.java
License:Apache License
/** * @return Pair of new, FILTERED, last and current POINTS, or null if it hasn't managed to track anything. */// ww w.j a v a 2 s.com Pair<Point[], Point[]> track(final Mat lastImg, final Mat currentImg, Point[] lastPoints) { final int size = lastPoints.length; final MatOfPoint2f currentPointsMat = new MatOfPoint2f(); final MatOfPoint2f pointsFBMat = new MatOfPoint2f(); final MatOfByte statusMat = new MatOfByte(); final MatOfFloat errSimilarityMat = new MatOfFloat(); final MatOfByte statusFBMat = new MatOfByte(); final MatOfFloat errSimilarityFBMat = new MatOfFloat(); //Forward-Backward tracking Video.calcOpticalFlowPyrLK(lastImg, currentImg, new MatOfPoint2f(lastPoints), currentPointsMat, statusMat, errSimilarityMat, WINDOW_SIZE, MAX_LEVEL, termCriteria, 0, LAMBDA); Video.calcOpticalFlowPyrLK(currentImg, lastImg, currentPointsMat, pointsFBMat, statusFBMat, errSimilarityFBMat, WINDOW_SIZE, MAX_LEVEL, termCriteria, 0, LAMBDA); final byte[] status = statusMat.toArray(); float[] errSimilarity = new float[lastPoints.length]; //final byte[] statusFB = statusFBMat.toArray(); final float[] errSimilarityFB = errSimilarityFBMat.toArray(); // compute the real FB error (relative to LAST points not the current ones... final Point[] pointsFB = pointsFBMat.toArray(); for (int i = 0; i < size; i++) { errSimilarityFB[i] = Util.norm(pointsFB[i], lastPoints[i]); } final Point[] currPoints = currentPointsMat.toArray(); // compute real similarity error errSimilarity = normCrossCorrelation(lastImg, currentImg, lastPoints, currPoints, status); //TODO errSimilarityFB has problem != from C++ // filter out points with fwd-back error > the median AND points with similarity error > median return filterPts(lastPoints, currPoints, errSimilarity, errSimilarityFB, status); }
From source file:syncleus.dann.data.video.LKTracker.java
License:Apache License
/** * @return Pair of new, FILTERED, last and current POINTS, or null if it hasn't managed to track anything. *///from w ww . j a v a 2 s . c o m public Pair<Point[], Point[]> track(final Mat lastImg, final Mat currentImg, Point[] lastPoints) { final int size = lastPoints.length; final MatOfPoint2f currentPointsMat = new MatOfPoint2f(); final MatOfPoint2f pointsFBMat = new MatOfPoint2f(); final MatOfByte statusMat = new MatOfByte(); final MatOfFloat errSimilarityMat = new MatOfFloat(); final MatOfByte statusFBMat = new MatOfByte(); final MatOfFloat errSimilarityFBMat = new MatOfFloat(); //Forward-Backward tracking Video.calcOpticalFlowPyrLK(lastImg, currentImg, new MatOfPoint2f(lastPoints), currentPointsMat, statusMat, errSimilarityMat, WINDOW_SIZE, MAX_LEVEL, termCriteria, 0, LAMBDA); Video.calcOpticalFlowPyrLK(currentImg, lastImg, currentPointsMat, pointsFBMat, statusFBMat, errSimilarityFBMat, WINDOW_SIZE, MAX_LEVEL, termCriteria, 0, LAMBDA); final byte[] status = statusMat.toArray(); float[] errSimilarity = new float[lastPoints.length]; //final byte[] statusFB = statusFBMat.toArray(); final float[] errSimilarityFB = errSimilarityFBMat.toArray(); // compute the real FB error (relative to LAST points not the current ones... final Point[] pointsFB = pointsFBMat.toArray(); for (int i = 0; i < size; i++) { errSimilarityFB[i] = TLDUtil.norm(pointsFB[i], lastPoints[i]); } final Point[] currPoints = currentPointsMat.toArray(); // compute real similarity error errSimilarity = normCrossCorrelation(lastImg, currentImg, lastPoints, currPoints, status); //TODO errSimilarityFB has problem != from C++ // filter out points with fwd-back error > the median AND points with similarity error > median return filterPts(lastPoints, currPoints, errSimilarity, errSimilarityFB, status); }