title: opencv stereo calibration result
body: <p>As if i have two web camera,mark as <code>cam1</code>,<code>cam2</code>.And i want to calibrate them to get the transformation between them.</p>
  
  <p>I used <code>cv::stereoCalibrate()</code> to calibrate.</p>
  
  <p>After i got the transformation from <code>cam1</code> to <code>cam2</code>,mark as <code>R</code>,<code>T</code>.I want to check the accuracy of the calibration result.</p>
  
  <p>So i used <code>cam1</code> and <code>cam2</code> to take a picture of a chessboard,mark as <code>pic1</code>,<code>pic2</code>.I got the <code>cam1</code>'s extrinsic parameters by <code>cv::solvePnP()</code>.And i drew the <code>cam1</code>'s world coordinate system by <code>cv::projectPoints()</code> in <code>pic1</code>.</p>
  
  <p>Then,i think the <code>cam2</code>'s rotation matrix=<code>cam1</code>'s rotation matrix * <code>R</code>.And the <code>cam2</code>'s translation matrix=<code>cam1</code>'s translation matrix + <code>T</code>.</p>
  
  <p>I calculated the <code>cam2</code>'s extrinsic parameters by the above thought.And also drew the <code>cam2</code>'s world coordinate system by <code>cv::projectPoints()</code> in <code>pic2</code>.</p>
  
  <p>But the <code>pic2</code>'s origin was not in right position.</p>
  
  <p>Here is part of the code i used.</p>
  
  <pre><code>void check_res(const vector&lt;string&gt; &amp;imgs_nm,const Mat &amp;R,const Mat &amp;T,const Mat &amp;cam_c,const Mat &amp;cam_h,const Mat &amp;dist_c,const Mat &amp;dist_h)
  {
      int imgs_cnt=imgs_nm.size()/2;
      vector&lt;Point3f&gt; obj_pts;
      for(int i=0;i&lt;boardDimensions.height;i++)
          for(int j=0;j&lt;boardDimensions.width;j++)
              obj_pts.push_back(Point3f(i*CHESS_LEN,j*CHESS_LEN,0.f));
      for(int i=0;i&lt;imgs_cnt;i++)
      {
          vector&lt;Point2f&gt; c_cners,h_cners;
          Mat imgc_gray,imgh_gray;
          Mat imgc=imread(imgs_nm[i*2],1);
          Mat imgc_rz=imgc.clone();
  
          bool c_found,h_found;
          c_found=HasChessBoard(imgc_rz,imgc_gray,c_cners);
          if(c_found)
              cv::cornerSubPix(imgc_gray, c_cners, cv::Size(11, 11), cv::Size(-1, -1),cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
          Mat imgh=imread(imgs_nm[i*2+1],1);
          h_found=HasChessBoard(imgh,imgh_gray,h_cners);
          if(h_found)
              cv::cornerSubPix(imgh_gray, h_cners, cv::Size(11, 11), cv::Size(-1, -1),cv::TermCriteria(CV_TERMCRIT_EPS + CV_TERMCRIT_ITER, 30, 0.1));
          Mat rvec_c,rvec_h,tvec_c,tvec_h;
          cv::solvePnP(obj_pts,c_cners,cam_c,dist_c,rvec_c,tvec_c);
          cv::solvePnP(obj_pts,h_cners,cam_h,dist_h,rvec_h,tvec_h);
          Mat rrvec_c,rrvec_h;
          cv::Rodrigues(rvec_c,rrvec_c);
          cv::Rodrigues(rvec_h,rrvec_h);
          Mat r1=rrvec_c*R;
          Mat t1=tvec_c+T;
  
          Mat img1=imgh.clone();
          draw_chess(imgh,rrvec_h,tvec_h,cam_h,dist_h);
          imshow("pic1",imgh);
          draw_chess(img1,r1,t1,cam_h,dist_h);
          imshow("pic2",img1);
  
  
          char resc=waitKey(0);
          if(resc=='q')
              exit(1);
  
      }
  }
  </code></pre>
  
  <p>And below is the result i tested by using the sample in <code>opencv</code>.</p>
  
  <p><a href="https://i.stack.imgur.com/POLJD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/POLJD.jpg" alt="enter image description here"></a></p>
  
  <p>I don't think it was low calibration accuracy,because i use the <code>opencv</code>'s   sample and the <code>cv::stereoCalibrate()</code> return rms less than 1 pixel.</p>
  
  <p>Any advice is appreciated.
  Thank you!</p>