From 13bc55a015b93cc4fbebf0083cb01fb5c3513225 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 9 Dec 2019 18:24:36 +0300 Subject: [PATCH] calib3d: clarify error messages in collectCalibrationData() --- modules/calib3d/src/calibration.cpp | 42 ++++++++++++++++------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index 7a426e530d..9c640540f7 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -3115,28 +3115,30 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints, 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); @@ -3144,7 +3146,7 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints, imgPtMat1.create(1, (int)total, CV_32FC2); Point2f* imgPtData2 = 0; - if( imgPtMat2 ) + if (imgPtMat2) { imgPtMat2->create(1, (int)total, CV_32FC2); imgPtData2 = imgPtMat2->ptr(); @@ -3153,28 +3155,30 @@ static void collectCalibrationData( InputArrayOfArrays objectPoints, Point3f* objPtData = objPtMat.ptr(); Point2f* imgPtData1 = imgPtMat1.ptr(); - 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(i) = ni; - for (int n = 0; n < ni; ++n) + int numberOfObjectPoints = objpt.checkVector(3, CV_32F); + npoints.at(i) = numberOfObjectPoints; + for (int n = 0; n < numberOfObjectPoints; ++n) { objPtData[j + n] = objpt.ptr()[n]; imgPtData1[j + n] = imgpt1.ptr()[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()[n]; } } + + j += numberOfObjectPoints; } }