代码笔记

1. camera标定:

class DepthCalibration
{
private:
  const std::string path;

  std::vector<cv::Point3f> board;
  std::vector<std::vector<cv::Point2f> > points;
  std::vector<std::string> images;

  cv::Size size;

  cv::Mat cameraMatrix, distortion, rotation, translation;
  cv::Mat mapX, mapY;

  double fx, fy, cx, cy;

  std::ofstream plot;

public:
  DepthCalibration(const std::string &path, const cv::Size &boardDims, const float boardSize)
    : path(path), size(512, 424)
  {
	  cout << "path=" << path <<endl;
	  cout << "size=" << size <<endl;
	  board.resize(boardDims.width * boardDims.height);
	  cout << "board=" << board<<endl;
	  cout << "board=" << boardDims.width * boardDims.height <<endl;
    for(size_t r = 0, i = 0; r < (size_t)boardDims.height; ++r)
    {
      for(size_t c = 0; c < (size_t)boardDims.width; ++c, ++i)
      {
        board[i] = cv::Point3f(c * boardSize, r * boardSize, 0);
        cout << "c=" << c <<endl;
        cout << "r=" << r <<endl;
        cout << "board====" << board <<endl;
      }
    }
  }

};

int main(int argc, char **argv)
{

	std::string path = "./";
	std::string arg="chess9x11x0.02";

	float boardSize = 0.108;
	cv::Size boardDims = cv::Size(7, 6);

	const size_t start = 5;
	const size_t end = arg.size();
    const size_t leftX = arg.find('x');
    const size_t rightX = arg.rfind('x');
    int width = atoi(arg.substr(start, leftX - start).c_str());
    int height = atoi(arg.substr(leftX + 1, rightX - leftX + 1).c_str());
    boardSize = atof(arg.substr(rightX + 1, end - rightX + 1).c_str());
    boardDims = cv::Size(width, height);


    cout << "path=" << path <<endl;
	cout << "leftx=" << leftX <<endl;
	cout << "rightx=" << rightX <<endl;
	cout << "width=" << width <<endl;
	cout << "height=" << height <<endl;
	cout << "boardSize=" << boardSize <<endl;
	cout << "boardDims=" << boardDims <<endl;

	 DepthCalibration calib(path, boardDims, boardSize);
	 cout << "path=" << path <<endl;
	 cout << "boardDims=" << boardDims <<endl;

	return 0;
}


输出值:
board====[0, 0, 0;
  0.02, 0, 0;
  0.039999999, 0, 0;
  0.059999999, 0, 0;
  0.079999998, 0, 0;
  0.099999994, 0, 0;
  0.12, 0, 0;
  0.14, 0, 0;
  0.16, 0, 0;
  0, 0.02, 0;
  0.02, 0.02, 0;
  0.039999999, 0.02, 0;
  0.059999999, 0.02, 0;
  0.079999998, 0.02, 0;
  0.099999994, 0.02, 0;
  0.12, 0.02, 0;
  0.14, 0.02, 0;
  0.16, 0.02, 0;
  0, 0.039999999, 0;
  0.02, 0.039999999, 0;
  0.039999999, 0.039999999, 0;
  0.059999999, 0.039999999, 0;
  0.079999998, 0.039999999, 0;
  0.099999994, 0.039999999, 0;
  0.12, 0.039999999, 0;
  0.14, 0.039999999, 0;
  0.16, 0.039999999, 0;
  0, 0.059999999, 0;
  0.02, 0.059999999, 0;
  0.039999999, 0.059999999, 0;
  0.059999999, 0.059999999, 0;
  0.079999998, 0.059999999, 0;
  0.099999994, 0.059999999, 0;
  0.12, 0.059999999, 0;
  0.14, 0.059999999, 0;
  0.16, 0.059999999, 0;
  0, 0.079999998, 0;
  0.02, 0.079999998, 0;
  0.039999999, 0.079999998, 0;
  0.059999999, 0.079999998, 0;
  0.079999998, 0.079999998, 0;
  0.099999994, 0.079999998, 0;
  0.12, 0.079999998, 0;
  0.14, 0.079999998, 0;
  0.16, 0.079999998, 0;
  0, 0.099999994, 0;
  0.02, 0.099999994, 0;
  0.039999999, 0.099999994, 0;
  0.059999999, 0.099999994, 0;
  0.079999998, 0.099999994, 0;
  0.099999994, 0.099999994, 0;
  0.12, 0.099999994, 0;
  0.14, 0.099999994, 0;
  0.16, 0.099999994, 0;
  0, 0.12, 0;
  0.02, 0.12, 0;
  0.039999999, 0.12, 0;
  0.059999999, 0.12, 0;
  0.079999998, 0.12, 0;
  0.099999994, 0.12, 0;
  0.12, 0.12, 0;
  0.14, 0.12, 0;
  0.16, 0.12, 0;
  0, 0.14, 0;
  0.02, 0.14, 0;
  0.039999999, 0.14, 0;
  0.059999999, 0.14, 0;
  0.079999998, 0.14, 0;
  0.099999994, 0.14, 0;
  0.12, 0.14, 0;
  0.14, 0.14, 0;
  0.16, 0.14, 0;
  0, 0.16, 0;
  0.02, 0.16, 0;
  0.039999999, 0.16, 0;
  0.059999999, 0.16, 0;
  0.079999998, 0.16, 0;
  0.099999994, 0.16, 0;
  0.12, 0.16, 0;
  0.14, 0.16, 0;
  0.16, 0.16, 0;
  0, 0.17999999, 0;
  0.02, 0.17999999, 0;
  0.039999999, 0.17999999, 0;
  0.059999999, 0.17999999, 0;
  0.079999998, 0.17999999, 0;
  0.099999994, 0.17999999, 0;
  0.12, 0.17999999, 0;
  0.14, 0.17999999, 0;
  0.16, 0.17999999, 0;
  0, 0.19999999, 0;
  0.02, 0.19999999, 0;
  0.039999999, 0.19999999, 0;
  0.059999999, 0.19999999, 0;
  0.079999998, 0.19999999, 0;
  0.099999994, 0.19999999, 0;
  0.12, 0.19999999, 0;
  0.14, 0.19999999, 0;
  0.16, 0.19999999, 0]
path=./
boardDims=[9 x 11]




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值