Skip to content

Commit 4ed8c5e

Browse files
NormandErwanalalek
authored andcommitted
Merge pull request #1108 from enormand:aruco-calibration-board-points
aruco: make public the getBoardObjectAndImagePoints function (#1108) * Made the private static getBoardObjectAndImagePoints function public to be used for calibration. * Switched the arguments detectedIds and detectedCorners, and objPoints and imgPoints on getBoardObjectandImagePoints function for consistency with calibrateCamera and calibrateCameraAruco functions. * Added the flag CV_EXPORTS_W to the getBoardObjectAndImagePoints function.
1 parent 29f9ddf commit 4ed8c5e

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

modules/aruco/include/opencv2/aruco.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,20 @@ CV_EXPORTS_W double calibrateCameraAruco(
535535
TermCriteria criteria = TermCriteria(TermCriteria::COUNT + TermCriteria::EPS, 30, DBL_EPSILON));
536536

537537

538+
/**
539+
* @brief Given a board configuration and a set of detected markers, returns the corresponding
540+
* image points and object points to call solvePnP
541+
*
542+
* @param board Marker board layout.
543+
* @param detectedCorners List of detected marker corners of the board.
544+
* @param detectedIds List of identifiers for each marker.
545+
* @param objPoints Vector of vectors of board marker points in the board coordinate space.
546+
* @param imgPoints Vector of vectors of the projections of board marker corner points.
547+
*/
548+
CV_EXPORTS_W void getBoardObjectAndImagePoints(const Ptr<Board> &board, InputArrayOfArrays detectedCorners,
549+
InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints);
550+
551+
538552
//! @}
539553
}
540554
}

modules/aruco/src/aruco.cpp

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -887,18 +887,13 @@ void estimatePoseSingleMarkers(InputArrayOfArrays _corners, float markerLength,
887887

888888

889889

890-
/**
891-
* @brief Given a board configuration and a set of detected markers, returns the corresponding
892-
* image points and object points to call solvePnP
893-
*/
894-
static void _getBoardObjectAndImagePoints(const Ptr<Board> &_board, InputArray _detectedIds,
895-
InputArrayOfArrays _detectedCorners,
896-
OutputArray _imgPoints, OutputArray _objPoints) {
890+
void getBoardObjectAndImagePoints(const Ptr<Board> &board, InputArrayOfArrays detectedCorners,
891+
InputArray detectedIds, OutputArray objPoints, OutputArray imgPoints) {
897892

898-
CV_Assert(_board->ids.size() == _board->objPoints.size());
899-
CV_Assert(_detectedIds.total() == _detectedCorners.total());
893+
CV_Assert(board->ids.size() == board->objPoints.size());
894+
CV_Assert(detectedIds.total() == detectedCorners.total());
900895

901-
size_t nDetectedMarkers = _detectedIds.total();
896+
size_t nDetectedMarkers = detectedIds.total();
902897

903898
vector< Point3f > objPnts;
904899
objPnts.reserve(nDetectedMarkers);
@@ -908,20 +903,20 @@ static void _getBoardObjectAndImagePoints(const Ptr<Board> &_board, InputArray _
908903

909904
// look for detected markers that belong to the board and get their information
910905
for(unsigned int i = 0; i < nDetectedMarkers; i++) {
911-
int currentId = _detectedIds.getMat().ptr< int >(0)[i];
912-
for(unsigned int j = 0; j < _board->ids.size(); j++) {
913-
if(currentId == _board->ids[j]) {
906+
int currentId = detectedIds.getMat().ptr< int >(0)[i];
907+
for(unsigned int j = 0; j < board->ids.size(); j++) {
908+
if(currentId == board->ids[j]) {
914909
for(int p = 0; p < 4; p++) {
915-
objPnts.push_back(_board->objPoints[j][p]);
916-
imgPnts.push_back(_detectedCorners.getMat(i).ptr< Point2f >(0)[p]);
910+
objPnts.push_back(board->objPoints[j][p]);
911+
imgPnts.push_back(detectedCorners.getMat(i).ptr< Point2f >(0)[p]);
917912
}
918913
}
919914
}
920915
}
921916

922917
// create output
923-
Mat(objPnts).copyTo(_objPoints);
924-
Mat(imgPnts).copyTo(_imgPoints);
918+
Mat(objPnts).copyTo(objPoints);
919+
Mat(imgPnts).copyTo(imgPoints);
925920
}
926921

927922

@@ -1243,7 +1238,7 @@ int estimatePoseBoard(InputArrayOfArrays _corners, InputArray _ids, const Ptr<Bo
12431238

12441239
// get object and image points for the solvePnP function
12451240
Mat objPoints, imgPoints;
1246-
_getBoardObjectAndImagePoints(board, _ids, _corners, imgPoints, objPoints);
1241+
getBoardObjectAndImagePoints(board, _corners, _ids, objPoints, imgPoints);
12471242

12481243
CV_Assert(imgPoints.total() == objPoints.total());
12491244

@@ -1544,8 +1539,8 @@ double calibrateCameraAruco(InputArrayOfArrays _corners, InputArray _ids, InputA
15441539
}
15451540
markerCounter += nMarkersInThisFrame;
15461541
Mat currentImgPoints, currentObjPoints;
1547-
_getBoardObjectAndImagePoints(board, thisFrameIds, thisFrameCorners, currentImgPoints,
1548-
currentObjPoints);
1542+
getBoardObjectAndImagePoints(board, thisFrameCorners, thisFrameIds, currentObjPoints,
1543+
currentImgPoints);
15491544
if(currentImgPoints.total() > 0 && currentObjPoints.total() > 0) {
15501545
processedImagePoints.push_back(currentImgPoints);
15511546
processedObjectPoints.push_back(currentObjPoints);

0 commit comments

Comments
 (0)