public static void glGetProjectionMatrix( CameraParameters cp, Size orgImgSize, Size size, double proj_matrix[], double gnear, double gfar, boolean invert) throws CPException, ExtParamException { if (cp.isValid() == false) throw new CPException("invalid camera parameters MarkerDetector::glGetProjectionMatrix"); // Deterime the resized info double Ax = (double) (size.width) / (double) (orgImgSize.width); double Ay = (double) (size.height) / (double) (orgImgSize.height); // get the cameraMatrix float[] camMat = new float[9]; cp.getCameraMatrix().get(0, 0, camMat); double _fx = camMat[0] * Ax; double _cx = camMat[2] * Ax; double _fy = camMat[4] * Ay; double _cy = camMat[5] * Ay; double[][] cparam = { {_fx, 0, _cx, 0}, {0, _fy, _cy, 0}, {0, 0, 1, 0} }; argConvGLcpara2(cparam, size.width, size.height, gnear, gfar, proj_matrix, invert); }
public static void draw3dAxis( Mat frame, CameraParameters cp, Scalar color, double height, Mat Rvec, Mat Tvec) { // Mat objectPoints = new Mat(4,3,CvType.CV_32FC1); MatOfPoint3f objectPoints = new MatOfPoint3f(); Vector<Point3> points = new Vector<Point3>(); points.add(new Point3(0, 0, 0)); points.add(new Point3(height, 0, 0)); points.add(new Point3(0, height, 0)); points.add(new Point3(0, 0, height)); objectPoints.fromList(points); MatOfPoint2f imagePoints = new MatOfPoint2f(); Calib3d.projectPoints( objectPoints, Rvec, Tvec, cp.getCameraMatrix(), cp.getDistCoeff(), imagePoints); List<Point> pts = new Vector<Point>(); Converters.Mat_to_vector_Point(imagePoints, pts); Core.line(frame, pts.get(0), pts.get(1), color, 2); Core.line(frame, pts.get(0), pts.get(2), color, 2); Core.line(frame, pts.get(0), pts.get(3), color, 2); Core.putText(frame, "X", pts.get(1), Core.FONT_HERSHEY_SIMPLEX, 0.5, color, 2); Core.putText(frame, "Y", pts.get(2), Core.FONT_HERSHEY_SIMPLEX, 0.5, color, 2); Core.putText(frame, "Z", pts.get(3), Core.FONT_HERSHEY_SIMPLEX, 0.5, color, 2); }
public static void myProjectionMatrix( CameraParameters cp, Size size, double proj_matrix[], double gnear, double gfar) throws CPException, ExtParamException { if (cp.isValid() == false) throw new CPException("Invalid camera parameters"); double w = size.width; double h = size.height; // get the cameraMatrix float[] camMat = new float[9]; cp.getCameraMatrix().get(0, 0, camMat); proj_matrix[0] = 2 * camMat[0] / w; proj_matrix[1] = 0; proj_matrix[2] = 0; proj_matrix[3] = 0; proj_matrix[4] = 0; proj_matrix[5] = -2 * camMat[4] / h; proj_matrix[6] = 0; proj_matrix[7] = 0; proj_matrix[8] = 1 - 2 * camMat[2] / w; proj_matrix[9] = 2 * camMat[5] / h - 1; proj_matrix[10] = (-gfar - gnear) / (gfar - gnear); proj_matrix[11] = -1; proj_matrix[12] = 0; proj_matrix[13] = 0; proj_matrix[14] = -2 * gfar * gnear / (gfar - gnear); proj_matrix[15] = 0; }