title: Camera Calibration in Java OpenCv
body: <p>I have been struggling to calibrate my camera in Java, the parameters that I receive from calling</p>
  
  <pre><code>Calib3d.calibrateCamera(object_points, corners, gray.size(), cameraMatrix, distCoeffs, rvecs, tvecs);
  </code></pre>
  
  <p>are way off.</p>
  
  <p>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?)</p>
  
  <p>Here is the java code</p>
  
  <pre><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&lt;SIZE_Y; ++y) 
          {
              for(int x=0; x&lt;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);
   }
  </code></pre>
  
  <p>The Python code that I use can be found in <a href="http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_calib3d/py_calibration/py_calibration.html" rel="nofollow">here</a></p>
  
  <p>I am only using one image, but shouldn't be the parameters the same. The chess_corners found are exactly the same.</p>
  
  <p>Here are the parameters that I am getting in java(which are non-sense)</p>
  
  <pre><code>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 
  </code></pre>
  
  <p>I would really apreciate if someone could help me out .
  Thank you in advance</p>