Mat& npoints )
{
int nimages = (int)objectPoints.total();
- int i, j = 0, ni = 0, total = 0;
- CV_Assert(nimages > 0 && nimages == (int)imagePoints1.total() &&
- (!imgPtMat2 || nimages == (int)imagePoints2.total()));
+ int total = 0;
+ CV_Assert(nimages > 0);
+ 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);
if (objectPoint.empty())
CV_Error(CV_StsBadSize, "objectPoints should not contain empty vector of vectors of points");
- ni = objectPoint.checkVector(3, CV_32F);
- if( ni <= 0 )
+ int numberOfObjectPoints = objectPoint.checkVector(3, CV_32F);
+ if (numberOfObjectPoints <= 0)
CV_Error(CV_StsUnsupportedFormat, "objectPoints should contain vector of vectors of points of type Point3f");
Mat imagePoint1 = imagePoints1.getMat(i);
if (imagePoint1.empty())
CV_Error(CV_StsBadSize, "imagePoints1 should not contain empty vector of vectors of points");
- int ni1 = imagePoint1.checkVector(2, CV_32F);
- if( ni1 <= 0 )
+ int numberOfImagePoints = imagePoint1.checkVector(2, CV_32F);
+ if (numberOfImagePoints <= 0)
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);
imgPtMat1.create(1, (int)total, CV_32FC2);
Point2f* imgPtData2 = 0;
- if( imgPtMat2 )
+ if (imgPtMat2)
{
imgPtMat2->create(1, (int)total, CV_32FC2);
imgPtData2 = imgPtMat2->ptr<Point2f>();
Point3f* objPtData = objPtMat.ptr<Point3f>();
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 imgpt1 = imagePoints1.getMat(i);
- ni = objpt.checkVector(3, CV_32F);
- npoints.at<int>(i) = ni;
- for (int n = 0; n < ni; ++n)
+ int numberOfObjectPoints = objpt.checkVector(3, CV_32F);
+ npoints.at<int>(i) = numberOfObjectPoints;
+ for (int n = 0; n < numberOfObjectPoints; ++n)
{
objPtData[j + n] = objpt.ptr<Point3f>()[n];
imgPtData1[j + n] = imgpt1.ptr<Point2f>()[n];
}
- if( imgPtData2 )
+ if (imgPtData2)
{
Mat imgpt2 = imagePoints2.getMat(i);
- int ni2 = imgpt2.checkVector(2, CV_32F);
- CV_Assert( ni == ni2 );
- for (int n = 0; n < ni2; ++n)
+ int numberOfImage2Points = imgpt2.checkVector(2, CV_32F);
+ CV_CheckEQ(numberOfObjectPoints, numberOfImage2Points, "Number of object and image(2) points must be equal");
+ for (int n = 0; n < numberOfImage2Points; ++n)
{
imgPtData2[j + n] = imgpt2.ptr<Point2f>()[n];
}
}
+
+ j += numberOfObjectPoints;
}
}