gpt4 book ai didi

c++ - OpenCV 相机校准,断言失败 0 && ni==ni1>

转载 作者:行者123 更新时间:2023-11-28 06:28:07 25 4
gpt4 key购买 nike

我正在尝试使用 openCV 执行相机校准。在来自 openCV 示例的相同示例数据上,这很好用,但我的源代码生成错误:

Assertion failed <ni > 0 && ni==ni1>... collectCallibrationData..    calibration.cpp line 3193"
objectPoints and imagePoints are the same size. Changing other inputs dont affect error code.

谁能帮我处理一下?代码如下:

void main()//enter code here
{
//initial operations, declatarions etc
int *Asize; float *APoints;
float AAPoints[]= {/* My Array */};
int AAsize[] = {4,54,2}; //My array size
Asize = AAsize; APoints = AAPoints; // will be called as dll that is why this wierd attribution
int page = *(Asize); int row = *(Asize+1); int col = *(Asize +2);
Point3f pointBuf;
vector<vector<Point3f>> imagePoints;
vector<Point3f> vectBuf;
Size boardSize;
boardSize.height = 6; boardSize.width = 9;
Mat cameraMatrix, distCoeffs;
float squareSize=50;


//change 1d array to vector<vector<point3f>>
for (int i = 0; i<page; i++)
{
for (int j = 0; j<row; j++)
{
pointBuf.x = *(APoints + (i*(row*col))+j*2);
pointBuf.y = *(APoints + (i*(row*col))+j*2+1);
pointBuf.z = 0;
vectBuf.push_back(pointBuf);
}
imagePoints.push_back(vectBuf);
vectBuf.clear();
}

// create objectPoint vector<vector<Points3f>>
vector<vector<Point3f>> objectPoints;
vectBuf.clear();
for( int i = 0; i < boardSize.height; ++i )
{
for( int j = 0; j < boardSize.width; ++j )
vectBuf.push_back(Point3f(float( j*squareSize ), float( i*squareSize ), 0));
}
objectPoints.resize(imagePoints.size(),vectBuf);

//initialize starting variables for calibration
cameraMatrix = Mat::eye(3, 3, CV_64F);
distCoeffs = Mat::zeros(1, 1, CV_64F);
cameraMatrix.at<double>(0,0) = 1.0;
vector<Mat> rvecs, tvecs;
Size imageSize; imageSize.width = 2040; imageSize.height = 2040;


double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs);
}

最佳答案

使用cv::calibrateCamera() 有问题.它需要 std::vector<std::vector<cv::Point3f>>作为第一个参数和 std::vector<std::vector<cv::Point2f>>作为第二个。

例如:

cv::Size imageSize(2040, 2040);
cv::Mat cameraMatrix, distCoeffs;
std::vector<cv::Mat> rvecs, tvecs;
std::vector<std::vector<cv::Point2f> > imagePoints;
std::vector<std::vector<cv::Point3f> > objectPoints;

// Fill imagePoints and objectPoints
...

cv::calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix, distCoeffs, rvecs, tvecs);

关于c++ - OpenCV 相机校准,断言失败 <ni> 0 && ni==ni1>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28159502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com