I have been struggling to calibrate my camera in Java, the parameters that I receive from calling
Calib3d.calibrateCamera(object_points, corners, gray.size(), cameraMatrix, distCoeffs, rvecs, tvecs);
are way off.
If I use the same image in Python (tutorial) the results are correct . I really don't know how to fix this problem.I really see no difference.(Maybe the way I am initializing object_points?)
Here is the java code
found_chess = Calib3d.findChessboardCorners(gray, patternSize, actual_corners, Calib3d.CALIB_CB_ADAPTIVE_THRESH + Calib3d.CALIB_CB_NORMALIZE_IMAGE);
if(found_chess)
{
corners.add(actual_corners);
//cornersubPix() irrelevant since all the corners are found in findChessBoard
//Imgproc.cornerSubPix(gray, actual_corners, new Size(SIZE_Y*2+1,SIZE_X*2+1), new Size(-1,-1), new TermCriteria(TermCriteria.EPS+TermCriteria.MAX_ITER,30,0.1));
MatOfPoint3f points;
Mat a = new MatOfPoint3f();
for(int y=0; y<SIZE_Y; ++y)
{
for(int x=0; x<SIZE_X; ++x)
{
points = new MatOfPoint3f(new Point3(x, y, 0));
a.push_back(points);
}
}
object_points.add(a);
Calib3d.calibrateCamera(object_points, corners, gray.size(), cameraMatrix, distCoeffs, rvecs, tvecs);
}
The Python code that I use can be found in here
I am only using one image, but shouldn't be the parameters the same. The chess_corners found are exactly the same.
Here are the parameters that I am getting in java(which are non-sense)
K1: 519.399710654873
K2: -42465.04562762376
P1: -11.363668181023353
P2: -1.5606689962722413
K3: -661829.1347551622
Fx: 8848.871073244098
Cx: 850.1589437229045
Fy: 9242.065368089003
Cy: 471.258611493399
I would really apreciate if someone could help me out . Thank you in advance