# Difference between Java and Python

Hello! I have a strange problem and I am not able to resolve it myself. I am trying to do a 3D camera pose estimation using findChessboardCorners() and solvePnPRansac(). It really is a simple program that basically:

1. reads image from disk with imread()
2. finds chessboard corners with findChessboardCorners()
3. compute sub-pixel corners with cornerSubPix()
4. estimate pose with solvePnPRansac()
5. project points to image using projectPoints()


I wrote two versions of the above algorithm, one using Python and one with Java binding. Each uses OpenCV version 3.0.0. However, I get totally different results from solvePnPRansac with Python and Java. I confirmed that all the other data (computed corners etc.) are exactly the same up to this point. Solving PnP gives two different rotation and translation matrices.

This is resulting image in Python:

and Java:

Of course, bottom plane should be aligned with the chessboard, but in Java it clearly isn't. Can you give me some hints what can be wrong with that? I am including source code, in case you don't have any general suggestions.

## Java source

Mat image = new Mat();

Mat mtx = calib.first;
MatOfDouble dist = calib.second;

TermCriteria criteria = new TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER, 30, 0.001);

ArrayList<Point3> p = new ArrayList<Point3>();
for(int i = 0; i < 6; i++) {
for(int j = 0; j < 9; j++) {
}
}
MatOfPoint3f objp = new MatOfPoint3f(p.toArray(new Point3[1]));

ArrayList<Point3> pp = new ArrayList<Point3>();
MatOfPoint3f axis = new MatOfPoint3f(pp.toArray(new Point3[1]));

Mat gray = new Mat();
Imgproc.cvtColor(image, gray, Imgproc.COLOR_BGR2GRAY);

MatOfPoint2f corners = new MatOfPoint2f();
boolean ret = Calib3d.findChessboardCorners(gray, new Size(9, 6), corners);

if(ret) {
Calib3d.drawChessboardCorners(image, new Size(9, 6), corners, true);
Imgproc.cornerSubPix(gray, corners, new Size(11, 11), new Size(-1, -1), criteria);

Mat rvecs = new Mat();
Mat tvecs = new Mat();

Calib3d.solvePnPRansac(objp, corners, mtx, dist, rvecs, tvecs);

MatOfPoint2f imgpts = new MatOfPoint2f();
Calib3d.projectPoints(axis, rvecs, tvecs, mtx, dist, imgpts);
Point[] points = imgpts.toArray();

List<MatOfPoint> bottom = new ArrayList<MatOfPoint>();
Imgproc.drawContours(image, bottom, -1, new Scalar(200, 150, 10), -3);

List<MatOfPoint> top = new ArrayList<MatOfPoint>();
Imgproc.drawContours(image, bottom, -1, new Scalar(200, 150, 10), -3);
}


## Python code

image = cv2.imread('<something>')
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001 ...