mirror of
https://github.com/opencv/opencv_contrib.git
synced 2025-10-20 04:25:42 +08:00
Board refactoring.
This commit is contained in:
@@ -154,8 +154,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create board object
|
// create board object
|
||||||
Ptr<aruco::GridBoard> gridboard =
|
Ptr<aruco::GridBoard> gridboard = new aruco::GridBoard(Size(markersX, markersY), markerLength, markerSeparation, dictionary);
|
||||||
aruco::GridBoard::create(markersX, markersY, markerLength, markerSeparation, dictionary);
|
|
||||||
Ptr<aruco::Board> board = gridboard.staticCast<aruco::Board>();
|
Ptr<aruco::Board> board = gridboard.staticCast<aruco::Board>();
|
||||||
|
|
||||||
// collected frames for calibration
|
// collected frames for calibration
|
||||||
@@ -176,7 +175,7 @@ int main(int argc, char *argv[]) {
|
|||||||
detector.detectMarkers(image, corners, ids, rejected);
|
detector.detectMarkers(image, corners, ids, rejected);
|
||||||
|
|
||||||
// refind strategy to detect more markers
|
// refind strategy to detect more markers
|
||||||
if(refindStrategy) detector.refineDetectedMarkers(image, board, corners, ids, rejected);
|
if(refindStrategy) detector.refineDetectedMarkers(image, *board, corners, ids, rejected);
|
||||||
|
|
||||||
// draw results
|
// draw results
|
||||||
image.copyTo(imageCopy);
|
image.copyTo(imageCopy);
|
||||||
|
@@ -154,8 +154,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// create charuco board object
|
// create charuco board object
|
||||||
Ptr<aruco::CharucoBoard> charucoboard =
|
Ptr<aruco::CharucoBoard> charucoboard = new aruco::CharucoBoard(Size(squaresX, squaresY), squareLength, markerLength, dictionary);
|
||||||
aruco::CharucoBoard::create(squaresX, squaresY, squareLength, markerLength, dictionary);
|
|
||||||
Ptr<aruco::Board> board = charucoboard.staticCast<aruco::Board>();
|
Ptr<aruco::Board> board = charucoboard.staticCast<aruco::Board>();
|
||||||
|
|
||||||
// collect data from each frame
|
// collect data from each frame
|
||||||
|
@@ -115,12 +115,11 @@ int main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ptr<aruco::GridBoard> board = aruco::GridBoard::create(markersX, markersY, float(markerLength),
|
aruco::GridBoard board(Size(markersX, markersY), float(markerLength), float(markerSeparation), dictionary);
|
||||||
float(markerSeparation), dictionary);
|
|
||||||
|
|
||||||
// show created board
|
// show created board
|
||||||
Mat boardImage;
|
Mat boardImage;
|
||||||
board->generateImage(imageSize, boardImage, margins, borderBits);
|
board.generateImage(imageSize, boardImage, margins, borderBits);
|
||||||
|
|
||||||
if(showImage) {
|
if(showImage) {
|
||||||
imshow("board", boardImage);
|
imshow("board", boardImage);
|
||||||
|
@@ -115,12 +115,11 @@ int main(int argc, char *argv[]) {
|
|||||||
imageSize.width = squaresX * squareLength + 2 * margins;
|
imageSize.width = squaresX * squareLength + 2 * margins;
|
||||||
imageSize.height = squaresY * squareLength + 2 * margins;
|
imageSize.height = squaresY * squareLength + 2 * margins;
|
||||||
|
|
||||||
Ptr<aruco::CharucoBoard> board = aruco::CharucoBoard::create(squaresX, squaresY, (float)squareLength,
|
aruco::CharucoBoard board(Size(squaresX, squaresY), (float)squareLength, (float)markerLength, dictionary);
|
||||||
(float)markerLength, dictionary);
|
|
||||||
|
|
||||||
// show created board
|
// show created board
|
||||||
Mat boardImage;
|
Mat boardImage;
|
||||||
board->generateImage(imageSize, boardImage, margins, borderBits);
|
board.generateImage(imageSize, boardImage, margins, borderBits);
|
||||||
|
|
||||||
if(showImage) {
|
if(showImage) {
|
||||||
imshow("board", boardImage);
|
imshow("board", boardImage);
|
||||||
|
@@ -150,8 +150,7 @@ int main(int argc, char *argv[]) {
|
|||||||
markerSeparation);
|
markerSeparation);
|
||||||
|
|
||||||
// create board object
|
// create board object
|
||||||
Ptr<aruco::GridBoard> gridboard =
|
Ptr<aruco::GridBoard> gridboard = new aruco::GridBoard(Size(markersX, markersY), markerLength, markerSeparation, dictionary);
|
||||||
aruco::GridBoard::create(markersX, markersY, markerLength, markerSeparation, dictionary);
|
|
||||||
Ptr<aruco::Board> board = gridboard.staticCast<aruco::Board>();
|
Ptr<aruco::Board> board = gridboard.staticCast<aruco::Board>();
|
||||||
|
|
||||||
double totalTime = 0;
|
double totalTime = 0;
|
||||||
@@ -172,7 +171,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
// refind strategy to detect more markers
|
// refind strategy to detect more markers
|
||||||
if(refindStrategy)
|
if(refindStrategy)
|
||||||
detector.refineDetectedMarkers(image, board, corners, ids, rejected, camMatrix,
|
detector.refineDetectedMarkers(image, *board, corners, ids, rejected, camMatrix,
|
||||||
distCoeffs);
|
distCoeffs);
|
||||||
|
|
||||||
// estimate board pose
|
// estimate board pose
|
||||||
|
@@ -145,8 +145,7 @@ int main(int argc, char *argv[]) {
|
|||||||
float axisLength = 0.5f * ((float)min(squaresX, squaresY) * (squareLength));
|
float axisLength = 0.5f * ((float)min(squaresX, squaresY) * (squareLength));
|
||||||
|
|
||||||
// create charuco board object
|
// create charuco board object
|
||||||
Ptr<aruco::CharucoBoard> charucoboard =
|
Ptr<aruco::CharucoBoard> charucoboard = new aruco::CharucoBoard(Size(squaresX, squaresY), squareLength, markerLength, dictionary);
|
||||||
aruco::CharucoBoard::create(squaresX, squaresY, squareLength, markerLength, dictionary);
|
|
||||||
Ptr<aruco::Board> board = charucoboard.staticCast<aruco::Board>();
|
Ptr<aruco::Board> board = charucoboard.staticCast<aruco::Board>();
|
||||||
|
|
||||||
double totalTime = 0;
|
double totalTime = 0;
|
||||||
|
@@ -15,9 +15,9 @@ static inline void createBoard()
|
|||||||
{
|
{
|
||||||
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
|
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
|
||||||
//! [createBoard]
|
//! [createBoard]
|
||||||
cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(5, 7, 0.04f, 0.02f, dictionary);
|
cv::aruco::CharucoBoard board(cv::Size(5, 7), 0.04f, 0.02f, dictionary);
|
||||||
cv::Mat boardImage;
|
cv::Mat boardImage;
|
||||||
board->generateImage(cv::Size(600, 500), boardImage, 10, 1);
|
board.generateImage(cv::Size(600, 500), boardImage, 10, 1);
|
||||||
//! [createBoard]
|
//! [createBoard]
|
||||||
cv::imwrite("BoardImage.jpg", boardImage);
|
cv::imwrite("BoardImage.jpg", boardImage);
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ static inline void detectCharucoBoardWithCalibrationPose()
|
|||||||
} else {
|
} else {
|
||||||
//! [dictboard]
|
//! [dictboard]
|
||||||
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
|
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
|
||||||
cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(5, 7, 0.04f, 0.02f, dictionary);
|
cv::Ptr<cv::aruco::CharucoBoard> board = new cv::aruco::CharucoBoard(cv::Size(5, 7), 0.04f, 0.02f, dictionary);
|
||||||
cv::Ptr<cv::aruco::DetectorParameters> params = cv::makePtr<cv::aruco::DetectorParameters>();
|
cv::Ptr<cv::aruco::DetectorParameters> params = cv::makePtr<cv::aruco::DetectorParameters>();
|
||||||
//! [dictboard]
|
//! [dictboard]
|
||||||
while (inputVideo.grab()) {
|
while (inputVideo.grab()) {
|
||||||
@@ -90,7 +90,7 @@ static inline void detectCharucoBoardWithoutCalibration()
|
|||||||
cv::VideoCapture inputVideo;
|
cv::VideoCapture inputVideo;
|
||||||
inputVideo.open(0);
|
inputVideo.open(0);
|
||||||
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
|
cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250);
|
||||||
cv::Ptr<cv::aruco::CharucoBoard> board = cv::aruco::CharucoBoard::create(5, 7, 0.04f, 0.02f, dictionary);
|
cv::Ptr<cv::aruco::CharucoBoard> board = new cv::aruco::CharucoBoard(cv::Size(5, 7), 0.04f, 0.02f, dictionary);
|
||||||
|
|
||||||
cv::Ptr<cv::aruco::DetectorParameters> params = cv::makePtr<cv::aruco::DetectorParameters>();
|
cv::Ptr<cv::aruco::DetectorParameters> params = cv::makePtr<cv::aruco::DetectorParameters>();
|
||||||
params->cornerRefinementMethod = cv::aruco::CORNER_REFINE_NONE;
|
params->cornerRefinementMethod = cv::aruco::CORNER_REFINE_NONE;
|
||||||
|
@@ -26,7 +26,7 @@ void refineDetectedMarkers(InputArray _image, const Ptr<Board> &_board,
|
|||||||
const Ptr<DetectorParameters> &_params) {
|
const Ptr<DetectorParameters> &_params) {
|
||||||
RefineParameters refineParams(minRepDistance, errorCorrectionRate, checkAllOrders);
|
RefineParameters refineParams(minRepDistance, errorCorrectionRate, checkAllOrders);
|
||||||
ArucoDetector detector(_board->getDictionary(), *_params, refineParams);
|
ArucoDetector detector(_board->getDictionary(), *_params, refineParams);
|
||||||
detector.refineDetectedMarkers(_image, _board, _detectedCorners, _detectedIds, _rejectedCorners, _cameraMatrix,
|
detector.refineDetectedMarkers(_image, *_board, _detectedCorners, _detectedIds, _rejectedCorners, _cameraMatrix,
|
||||||
_distCoeffs, _recoveredIdxs);
|
_distCoeffs, _recoveredIdxs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -383,14 +383,13 @@ void detectCharucoDiamond(InputArray _image, InputArrayOfArrays _markerCorners,
|
|||||||
// current id is assigned to [0], so it is the marker on the top
|
// current id is assigned to [0], so it is the marker on the top
|
||||||
tmpIds[0] = currentId;
|
tmpIds[0] = currentId;
|
||||||
// create Charuco board layout for diamond (3x3 layout)
|
// create Charuco board layout for diamond (3x3 layout)
|
||||||
Ptr<CharucoBoard> _charucoDiamondLayout = CharucoBoard::create(3, 3, squareMarkerLengthRate, 1., *dictionary,
|
Ptr<CharucoBoard> _charucoDiamondLayout = new CharucoBoard(Size(3, 3), squareMarkerLengthRate, 1., *dictionary, tmpIds);
|
||||||
tmpIds);
|
|
||||||
|
|
||||||
// try to find the rest of markers in the diamond
|
// try to find the rest of markers in the diamond
|
||||||
vector< int > acceptedIdxs;
|
vector< int > acceptedIdxs;
|
||||||
RefineParameters refineParameters(minRepDistance, -1.f, false);
|
RefineParameters refineParameters(minRepDistance, -1.f, false);
|
||||||
ArucoDetector detector(*dictionary, DetectorParameters(), refineParameters);
|
ArucoDetector detector(*dictionary, DetectorParameters(), refineParameters);
|
||||||
detector.refineDetectedMarkers(grey, _charucoDiamondLayout, currentMarker, currentMarkerId, candidates,
|
detector.refineDetectedMarkers(grey, *_charucoDiamondLayout, currentMarker, currentMarkerId, candidates,
|
||||||
noArray(), noArray(), acceptedIdxs);
|
noArray(), noArray(), acceptedIdxs);
|
||||||
|
|
||||||
// if found, we have a diamond
|
// if found, we have a diamond
|
||||||
@@ -456,9 +455,9 @@ void drawCharucoDiamond(const Ptr<Dictionary> &dictionary, Vec4i ids, int square
|
|||||||
for(int i = 0; i < 4; i++)
|
for(int i = 0; i < 4; i++)
|
||||||
tmpIds[i] = ids[i];
|
tmpIds[i] = ids[i];
|
||||||
// create a charuco board similar to a charuco marker and print it
|
// create a charuco board similar to a charuco marker and print it
|
||||||
Ptr<CharucoBoard> board = CharucoBoard::create(3, 3, (float)squareLength, (float)markerLength, *dictionary, tmpIds);
|
CharucoBoard board(Size(3, 3), (float)squareLength, (float)markerLength, *dictionary, tmpIds);
|
||||||
Size outSize(3 * squareLength + 2 * marginSize, 3 * squareLength + 2 * marginSize);
|
Size outSize(3 * squareLength + 2 * marginSize, 3 * squareLength + 2 * marginSize);
|
||||||
board->generateImage(outSize, _img, marginSize, borderBits);
|
board.generateImage(outSize, _img, marginSize, borderBits);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user