diff --git a/modules/aruco/include/opencv2/aruco.hpp b/modules/aruco/include/opencv2/aruco.hpp index e36ef61dd..792f8f4bc 100644 --- a/modules/aruco/include/opencv2/aruco.hpp +++ b/modules/aruco/include/opencv2/aruco.hpp @@ -535,6 +535,20 @@ CV_EXPORTS_W double calibrateCameraAruco( TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON)); +/** + * @brief Given a board configuration and a set of detected markers, returns the corresponding + * image points and object points to call solvePnP + * + * @param board Marker board layout. + * @param detectedCorners List of detected marker corners of the board. + * @param detectedIds List of identifiers for each marker. + * @param objPoints Vector of vectors of board marker points in the board coordinate space. + * @param imgPoints Vector of vectors of the projections of board marker corner points. +*/ +CV_EXPORTS_W void getBoardObjectAndImagePoints(const Ptr &board, InputArrayOfArrays detectedCorners, + InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints); + + //! @} } } diff --git a/modules/aruco/src/aruco.cpp b/modules/aruco/src/aruco.cpp index 27f86bef9..a4874e019 100644 --- a/modules/aruco/src/aruco.cpp +++ b/modules/aruco/src/aruco.cpp @@ -887,18 +887,13 @@ void estimatePoseSingleMarkers(InputArrayOfArrays _corners, float markerLength, -/** - * @brief Given a board configuration and a set of detected markers, returns the corresponding - * image points and object points to call solvePnP - */ -static void _getBoardObjectAndImagePoints(const Ptr &_board, InputArray _detectedIds, - InputArrayOfArrays _detectedCorners, - OutputArray _imgPoints, OutputArray _objPoints) { +void getBoardObjectAndImagePoints(const Ptr &board, InputArrayOfArrays detectedCorners, + InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints) { - CV_Assert(_board->ids.size() == _board->objPoints.size()); - CV_Assert(_detectedIds.total() == _detectedCorners.total()); + CV_Assert(board->ids.size() == board->objPoints.size()); + CV_Assert(detectedIds.total() == detectedCorners.total()); - size_t nDetectedMarkers = _detectedIds.total(); + size_t nDetectedMarkers = detectedIds.total(); vector< Point3f > objPnts; objPnts.reserve(nDetectedMarkers); @@ -908,20 +903,20 @@ static void _getBoardObjectAndImagePoints(const Ptr &_board, InputArray _ // look for detected markers that belong to the board and get their information for(unsigned int i = 0; i < nDetectedMarkers; i++) { - int currentId = _detectedIds.getMat().ptr< int >(0)[i]; - for(unsigned int j = 0; j < _board->ids.size(); j++) { - if(currentId == _board->ids[j]) { + int currentId = detectedIds.getMat().ptr< int >(0)[i]; + for(unsigned int j = 0; j < board->ids.size(); j++) { + if(currentId == board->ids[j]) { for(int p = 0; p < 4; p++) { - objPnts.push_back(_board->objPoints[j][p]); - imgPnts.push_back(_detectedCorners.getMat(i).ptr< Point2f >(0)[p]); + objPnts.push_back(board->objPoints[j][p]); + imgPnts.push_back(detectedCorners.getMat(i).ptr< Point2f >(0)[p]); } } } } // create output - Mat(objPnts).copyTo(_objPoints); - Mat(imgPnts).copyTo(_imgPoints); + Mat(objPnts).copyTo(objPoints); + Mat(imgPnts).copyTo(imgPoints); } @@ -1243,7 +1238,7 @@ int estimatePoseBoard(InputArrayOfArrays _corners, InputArray _ids, const Ptr 0 && currentObjPoints.total() > 0) { processedImagePoints.push_back(currentImgPoints); processedObjectPoints.push_back(currentObjPoints);