List of usage examples for org.opencv.core Mat create
public void create(int rows, int cols, int type)
From source file:com.trandi.opentld.tld.PatchGenerator.java
License:Apache License
/** * //from w ww .ja va2 s . co m * @param srcCenter * @param dstCenter * @param transform OUTPUT * @param inverse */ private void generateRandomTransform(Point srcCenter, Point dstCenter, Mat transform, boolean inverse) { MatOfDouble tempRand = new MatOfDouble(0d, 0d); Core.randu(tempRand, lambdaMin, lambdaMax); final double[] rands = tempRand.toArray(); final double lambda1 = rands[0]; final double lambda2 = rands[1]; Core.randu(tempRand, thetaMin, thetaMax); final double theta = tempRand.toArray()[0]; Core.randu(tempRand, phiMin, phiMax); final double phi = tempRand.toArray()[0]; // Calculate random parameterized affine transformation A, // A = T(patch center) * R(theta) * R(phi)' * S(lambda1, lambda2) * R(phi) * T(-pt) final double st = Math.sin(theta); final double ct = Math.cos(theta); final double sp = Math.sin(phi); final double cp = Math.cos(phi); final double c2p = cp * cp; final double s2p = sp * sp; final double A = lambda1 * c2p + lambda2 * s2p; final double B = (lambda2 - lambda1) * sp * cp; final double C = lambda1 * s2p + lambda2 * c2p; final double Ax_plus_By = A * srcCenter.x + B * srcCenter.y; final double Bx_plus_Cy = B * srcCenter.x + C * srcCenter.y; transform.create(2, 3, CvType.CV_64F); transform.put(0, 0, A * ct - B * st); transform.put(0, 1, B * ct - C * st); transform.put(0, 2, -ct * Ax_plus_By + st * Bx_plus_Cy + dstCenter.x); transform.put(1, 0, A * st + B * ct); transform.put(1, 1, B * st + C * ct); transform.put(1, 2, -st * Ax_plus_By - ct * Bx_plus_Cy + dstCenter.y); if (inverse) { Imgproc.invertAffineTransform(transform, transform); } }
From source file:de.vion.eyetracking.cameracalib.calibration.opencv.CameraCalibrator.java
private void calcBoardCornerPositions(Mat corners) { final int cn = 3; float positions[] = new float[this.mCornersSize * cn]; for (int i = 0; i < this.mPatternSize.height; i++) { for (int j = 0; j < this.mPatternSize.width * cn; j += cn) { positions[(int) (i * this.mPatternSize.width * cn + j + 0)] = (2 * (j / cn) + i % 2) * (float) this.mSquareSize; positions[(int) (i * this.mPatternSize.width * cn + j + 1)] = i * (float) this.mSquareSize; positions[(int) (i * this.mPatternSize.width * cn + j + 2)] = 0; }/*from ww w .ja va2 s . c o m*/ } corners.create(this.mCornersSize, 1, CvType.CV_32FC3); corners.put(0, 0, positions); }
From source file:de.vion.eyetracking.cameracalib.calibration.opencv.CameraCalibrator.java
private double computeReprojectionErrors(List<Mat> objectPoints, List<Mat> rvecs, List<Mat> tvecs, Mat perViewErrors) { MatOfPoint2f cornersProjected = new MatOfPoint2f(); double totalError = 0; double error; float viewErrors[] = new float[objectPoints.size()]; MatOfDouble distortionCoefficients = new MatOfDouble(this.mDistortionCoefficients); int totalPoints = 0; for (int i = 0; i < objectPoints.size(); i++) { MatOfPoint3f points = new MatOfPoint3f(objectPoints.get(i)); Calib3d.projectPoints(points, rvecs.get(i), tvecs.get(i), this.mCameraMatrix, distortionCoefficients, cornersProjected);//from w w w . j a va2 s . c o m error = Core.norm(this.mCornersBuffer.get(i), cornersProjected, Core.NORM_L2); int n = objectPoints.get(i).rows(); viewErrors[i] = (float) Math.sqrt(error * error / n); totalError += error * error; totalPoints += n; } perViewErrors.create(objectPoints.size(), 1, CvType.CV_32FC1); perViewErrors.put(0, 0, viewErrors); return Math.sqrt(totalError / totalPoints); }