1

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

1 Answer 1

1

It seems I was initializing objectpoints the wrong way. Changed X and Y and it works fine(See code and results)

for(int x=0; x<SIZE_X; ++x) 
{
    for(int y=0;  y<SIZE_Y; ++y)
    {
        points = new MatOfPoint3f(new Point3(y, x, 0));
        a.push_back(points);
    }
}

K1: -0.018826429817406057
K2: 0.004765861493124195
P1: -0.013705374382823956
P2: 0.004067969604879225
K3: -0.05266506928016909
Fx: 594.0637743671965
Cx: 657.3929211728023
Fy: 604.1989278105854
Cy: 572.8441406065865
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.