// Path: openCVTutorial1CameraPreview/src/main/java/es/ava/aruco/exceptions/CPException.java
// public class CPException extends Exception{
// 
// 	private static final long serialVersionUID = 1L;
// 	private String message;
// 
// 	public CPException(String string) {
// 		message = string;
// 	}
// 	
// 	public String getMessage(){
// 		return message;
// 	}
// }
// 
// Path: openCVTutorial1CameraPreview/src/main/java/es/ava/aruco/exceptions/ExtParamException.java
// public class ExtParamException extends Exception{
// 
// 	private static final long serialVersionUID = 1L;
// 	private String message;
// 	
// 	public ExtParamException(String string){
// 		message = string;
// 	}
// 	
// 	public String getMessage(){
// 		return message;
// 	}
// }


import android.util.Log;
import java.util.List;
import java.util.Vector;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.MatOfPoint3f;
import org.opencv.core.Point;
import org.opencv.core.Point3;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.utils.Converters;
import es.ava.aruco.exceptions.CPException;
import es.ava.aruco.exceptions.ExtParamException;
		// get the matrix corresponding to the rotation vector
		Mat R = new Mat(3,3,CvType.CV_64FC1);
		Calib3d.Rodrigues(rotation, R);
	    
		// create the matrix to rotate 90° around the X axis
	    // 1, 0, 0
	    // 0 cos -sin
	    // 0 sin cos
		double[] rot = {
				1, 0,  0,
				0, 0, -1,
				0, 1, 0
		};
		// multiply both matrix
		Mat res = new Mat(3,3, CvType.CV_64FC1);
		double[] prod = new double[9];
		double[] a = new double[9];
		R.get(0, 0, a);
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++){
            	prod[3*i+j] = 0;
                for(int k=0;k<3;k++){
                	prod[3*i+j] += a[3*i+k]*rot[3*k+j];
                }
            }
        // convert the matrix to a vector with rodrigues back
        res.put(0, 0, prod);
		Calib3d.Rodrigues(res, rotation);
	}
	
// Path: openCVTutorial1CameraPreview/src/main/java/es/ava/aruco/exceptions/CPException.java
// public class CPException extends Exception{
// 
// 	private static final long serialVersionUID = 1L;
// 	private String message;
// 
// 	public CPException(String string) {
// 		message = string;
// 	}
// 	
// 	public String getMessage(){
// 		return message;
// 	}
// }
// 
// Path: openCVTutorial1CameraPreview/src/main/java/es/ava/aruco/exceptions/ExtParamException.java
// public class ExtParamException extends Exception{
// 
// 	private static final long serialVersionUID = 1L;
// 	private String message;
// 	
// 	public ExtParamException(String string){
// 		message = string;
// 	}
// 	
// 	public String getMessage(){
// 		return message;
// 	}
// }


// Path: openCVTutorial1CameraPreview/src/main/java/es/ava/aruco/Utils.java
import android.util.Log;
import java.util.List;
import java.util.Vector;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint2f;
import org.opencv.core.MatOfPoint3f;
import org.opencv.core.Point;
import org.opencv.core.Point3;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;
import org.opencv.utils.Converters;
import es.ava.aruco.exceptions.CPException;
import es.ava.aruco.exceptions.ExtParamException;

		// get the matrix corresponding to the rotation vector
		Mat R = new Mat(3,3,CvType.CV_64FC1);
		Calib3d.Rodrigues(rotation, R);
	    
		// create the matrix to rotate 90° around the X axis
	    // 1, 0, 0
	    // 0 cos -sin
	    // 0 sin cos
		double[] rot = {
				1, 0,  0,
				0, 0, -1,
				0, 1, 0
		};
		// multiply both matrix
		Mat res = new Mat(3,3, CvType.CV_64FC1);
		double[] prod = new double[9];
		double[] a = new double[9];
		R.get(0, 0, a);
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++){
            	prod[3*i+j] = 0;
                for(int k=0;k<3;k++){
                	prod[3*i+j] += a[3*i+k]*rot[3*k+j];
                }
            }
        // convert the matrix to a vector with rodrigues back
        res.put(0, 0, prod);
		Calib3d.Rodrigues(res, rotation);
	}
	
	protected static void glGetModelViewMatrix(double[] modelview_matrix, Mat Rvec, Mat Tvec)throws ExtParamException{