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]