List of usage examples for org.opencv.core Core fastAtan2
public static float fastAtan2(float y, float x)
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 v a 2s .c o 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; }