Commit 13bc55a0 authored by Alexander Alekhin's avatar Alexander Alekhin

calib3d: clarify error messages in collectCalibrationData()

parent a011035e
...@@ -3115,28 +3115,30 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints, ...@@ -3115,28 +3115,30 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints,
Mat& npoints ) Mat& npoints )
{ {
int nimages = (int)objectPoints.total(); int nimages = (int)objectPoints.total();
int i, j = 0, ni = 0, total = 0; int total = 0;
CV_Assert(nimages > 0 && nimages == (int)imagePoints1.total() && CV_Assert(nimages > 0);
(!imgPtMat2 || nimages == (int)imagePoints2.total())); CV_CheckEQ(nimages, (int)imagePoints1.total(), "");
if (imgPtMat2)
CV_CheckEQ(nimages, (int)imagePoints2.total(), "");
for( i = 0; i < nimages; i++ ) for (int i = 0; i < nimages; i++)
{ {
Mat objectPoint = objectPoints.getMat(i); Mat objectPoint = objectPoints.getMat(i);
if (objectPoint.empty()) if (objectPoint.empty())
CV_Error(CV_StsBadSize, "objectPoints should not contain empty vector of vectors of points"); CV_Error(CV_StsBadSize, "objectPoints should not contain empty vector of vectors of points");
ni = objectPoint.checkVector(3, CV_32F); int numberOfObjectPoints = objectPoint.checkVector(3, CV_32F);
if( ni <= 0 ) if (numberOfObjectPoints <= 0)
CV_Error(CV_StsUnsupportedFormat, "objectPoints should contain vector of vectors of points of type Point3f"); CV_Error(CV_StsUnsupportedFormat, "objectPoints should contain vector of vectors of points of type Point3f");
Mat imagePoint1 = imagePoints1.getMat(i); Mat imagePoint1 = imagePoints1.getMat(i);
if (imagePoint1.empty()) if (imagePoint1.empty())
CV_Error(CV_StsBadSize, "imagePoints1 should not contain empty vector of vectors of points"); CV_Error(CV_StsBadSize, "imagePoints1 should not contain empty vector of vectors of points");
int ni1 = imagePoint1.checkVector(2, CV_32F); int numberOfImagePoints = imagePoint1.checkVector(2, CV_32F);
if( ni1 <= 0 ) if (numberOfImagePoints <= 0)
CV_Error(CV_StsUnsupportedFormat, "imagePoints1 should contain vector of vectors of points of type Point2f"); CV_Error(CV_StsUnsupportedFormat, "imagePoints1 should contain vector of vectors of points of type Point2f");
CV_Assert( ni == ni1 ); CV_CheckEQ(numberOfObjectPoints, numberOfImagePoints, "Number of object and image points must be equal");
total += ni; total += numberOfObjectPoints;
} }
npoints.create(1, (int)nimages, CV_32S); npoints.create(1, (int)nimages, CV_32S);
...@@ -3144,7 +3146,7 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints, ...@@ -3144,7 +3146,7 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints,
imgPtMat1.create(1, (int)total, CV_32FC2); imgPtMat1.create(1, (int)total, CV_32FC2);
Point2f* imgPtData2 = 0; Point2f* imgPtData2 = 0;
if( imgPtMat2 ) if (imgPtMat2)
{ {
imgPtMat2->create(1, (int)total, CV_32FC2); imgPtMat2->create(1, (int)total, CV_32FC2);
imgPtData2 = imgPtMat2->ptr<Point2f>(); imgPtData2 = imgPtMat2->ptr<Point2f>();
...@@ -3153,28 +3155,30 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints, ...@@ -3153,28 +3155,30 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints,
Point3f* objPtData = objPtMat.ptr<Point3f>(); Point3f* objPtData = objPtMat.ptr<Point3f>();
Point2f* imgPtData1 = imgPtMat1.ptr<Point2f>(); Point2f* imgPtData1 = imgPtMat1.ptr<Point2f>();
for( i = 0; i < nimages; i++, j += ni ) for (int i = 0, j = 0; i < nimages; i++)
{ {
Mat objpt = objectPoints.getMat(i); Mat objpt = objectPoints.getMat(i);
Mat imgpt1 = imagePoints1.getMat(i); Mat imgpt1 = imagePoints1.getMat(i);
ni = objpt.checkVector(3, CV_32F); int numberOfObjectPoints = objpt.checkVector(3, CV_32F);
npoints.at<int>(i) = ni; npoints.at<int>(i) = numberOfObjectPoints;
for (int n = 0; n < ni; ++n) for (int n = 0; n < numberOfObjectPoints; ++n)
{ {
objPtData[j + n] = objpt.ptr<Point3f>()[n]; objPtData[j + n] = objpt.ptr<Point3f>()[n];
imgPtData1[j + n] = imgpt1.ptr<Point2f>()[n]; imgPtData1[j + n] = imgpt1.ptr<Point2f>()[n];
} }
if( imgPtData2 ) if (imgPtData2)
{ {
Mat imgpt2 = imagePoints2.getMat(i); Mat imgpt2 = imagePoints2.getMat(i);
int ni2 = imgpt2.checkVector(2, CV_32F); int numberOfImage2Points = imgpt2.checkVector(2, CV_32F);
CV_Assert( ni == ni2 ); CV_CheckEQ(numberOfObjectPoints, numberOfImage2Points, "Number of object and image(2) points must be equal");
for (int n = 0; n < ni2; ++n) for (int n = 0; n < numberOfImage2Points; ++n)
{ {
imgPtData2[j + n] = imgpt2.ptr<Point2f>()[n]; imgPtData2[j + n] = imgpt2.ptr<Point2f>()[n];
} }
} }
j += numberOfObjectPoints;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment