From ebc255b0256a937ef437a6fe3a478a6e1e7c9065 Mon Sep 17 00:00:00 2001 From: atinfinity Date: Mon, 8 May 2017 12:06:57 +0900 Subject: [PATCH] fixed sample code in tutorial --- .../aruco_board_detection.markdown | 24 +++++----- .../aruco_calibration.markdown | 18 ++++---- .../aruco_detection/aruco_detection.markdown | 31 ++++++------- .../charuco_detection.markdown | 44 +++++++++---------- .../charuco_diamond_detection.markdown | 18 ++++---- 5 files changed, 68 insertions(+), 67 deletions(-) diff --git a/modules/aruco/tutorials/aruco_board_detection/aruco_board_detection.markdown b/modules/aruco/tutorials/aruco_board_detection/aruco_board_detection.markdown index c4eeb40a4c..0b88b067ed 100644 --- a/modules/aruco/tutorials/aruco_board_detection/aruco_board_detection.markdown +++ b/modules/aruco/tutorials/aruco_board_detection/aruco_board_detection.markdown @@ -30,7 +30,7 @@ The aruco module allows the use of Boards. The main class is the ```cv::aruco::B class Board { public: std::vector > objPoints; - cv::aruco::Dictionary dictionary; + cv::Ptr dictionary; std::vector ids; }; ``` @@ -57,10 +57,10 @@ The aruco module provides a specific function, ```estimatePoseBoard()```, to per cv::Mat cameraMatrix, distCoeffs; readCameraParameters(cameraMatrix, distCoeffs); // assume we have a function to create the board object - cv::aruco::Board board = createBoard(); + cv::Ptr board = cv::aruco::Board::create(); ... - vector< int > markerIds; - vector< vector > markerCorners; + std::vector markerIds; + std::vector> markerCorners; cv::aruco::detectMarkers(inputImage, board.dictionary, markerCorners, markerIds); // if at least one marker detected if(markerIds.size() > 0) { @@ -137,9 +137,9 @@ After creating a Grid Board, we probably want to print it and use it. A function of a ```GridBoard``` is provided in ```cv::aruco::GridBoard::draw()```. For example: ``` c++ - cv::aruco::GridBoard board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary); + cv::Ptr board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary); cv::Mat boardImage; - board.draw( cv::Size(600, 500), boardImage, 10, 1 ); + board->draw( cv::Size(600, 500), boardImage, 10, 1 ); ``` - The first parameter is the size of the output image in pixels. In this case 600x500 pixels. If this is not proportional @@ -170,8 +170,8 @@ Finally, a full example of board detection: // camera parameters are read from somewhere readCameraParameters(cameraMatrix, distCoeffs); - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); - cv::aruco::GridBoard board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary); while (inputVideo.grab()) { cv::Mat image, imageCopy; @@ -256,10 +256,10 @@ internal bits are not analyzed at all and only the corner distances are evaluate This is an example of using the ```refineDetectedMarkers()``` function: ``` c++ - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); - cv::aruco::GridBoard board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary); - vector< int > markerIds; - vector< vector > markerCorners, rejectedCandidates; + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr board = cv::aruco::GridBoard::create(5, 7, 0.04, 0.01, dictionary); + std::vector markerIds; + std::vector> markerCorners, rejectedCandidates; cv::aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, cv::aruco::DetectorParameters(), rejectedCandidates); cv::aruco::refineDetectedMarkersinputImage, board, markerCorners, markerIds, rejectedCandidates); diff --git a/modules/aruco/tutorials/aruco_calibration/aruco_calibration.markdown b/modules/aruco/tutorials/aruco_calibration/aruco_calibration.markdown index e9f6e36efd..617dc553a0 100644 --- a/modules/aruco/tutorials/aruco_calibration/aruco_calibration.markdown +++ b/modules/aruco/tutorials/aruco_calibration/aruco_calibration.markdown @@ -33,18 +33,18 @@ visible in all the viewpoints. The function to calibrate is ```calibrateCameraCharuco()```. Example: ``` c++ - aruco::CharucoBoard board = ... // create charuco board + cv::Ptr board = ... // create charuco board cv::Size imgSize = ... // camera image size - std::vector< std::vector > allCharucoCorners; - std::vector< std::vector > allCharucoIds; + std::vector> allCharucoCorners; + std::vector> allCharucoIds; // Detect charuco board from several viewpoints and fill allCharucoCorners and allCharucoIds ... ... // After capturing in several viewpoints, start calibration cv::Mat cameraMatrix, distCoeffs; - std::vector< Mat > rvecs, tvecs; + std::vector rvecs, tvecs; int calibrationFlags = ... // Set calibration flags (same than in calibrateCamera() function) double repError = cv::aruco::calibrateCameraCharuco(allCharucoCorners, allCharucoIds, board, imgSize, cameraMatrix, distCoeffs, rvecs, tvecs, calibrationFlags); @@ -81,19 +81,19 @@ requires the detections of an ArUco board from different viewpoints. Example of ```calibrateCameraAruco()``` use: ``` c++ - aruco::Board board = ... // create aruco board + cv::Ptr board = ... // create aruco board cv::Size imgSize = ... // camera image size - std::vector< std::vector< cv::Point2f > > allCornersConcatenated; - std::vector< int > allIdsConcatenated; - std::vector< int > markerCounterPerFrame; + std::vector> allCornersConcatenated; + std::vector allIdsConcatenated; + std::vector markerCounterPerFrame; // Detect aruco board from several viewpoints and fill allCornersConcatenated, allIdsConcatenated and markerCounterPerFrame ... ... // After capturing in several viewpoints, start calibration cv::Mat cameraMatrix, distCoeffs; - std::vector< Mat > rvecs, tvecs; + std::vector rvecs, tvecs; int calibrationFlags = ... // Set calibration flags (same than in calibrateCamera() function) double repError = cv::aruco::calibrateCameraAruco(allCornersConcatenated, allIdsConcatenated, markerCounterPerFrame, board, imgSize, cameraMatrix, distCoeffs, rvecs, tvecs, calibrationFlags); diff --git a/modules/aruco/tutorials/aruco_detection/aruco_detection.markdown b/modules/aruco/tutorials/aruco_detection/aruco_detection.markdown index 0470beb5a7..f049a3becb 100644 --- a/modules/aruco/tutorials/aruco_detection/aruco_detection.markdown +++ b/modules/aruco/tutorials/aruco_detection/aruco_detection.markdown @@ -71,7 +71,7 @@ For example, lets analyze the following call: ``` c++ cv::Mat markerImage; - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); cv::aruco::drawMarker(dictionary, 23, 200, markerImage, 1); ``` @@ -156,10 +156,10 @@ An example of marker detection: ``` c++ cv::Mat inputImage; ... - vector< int > markerIds; - vector< vector > markerCorners, rejectedCandidates; - cv::aruco::DetectorParameters parameters; - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + std::vector markerIds; + std::vector> markerCorners, rejectedCandidates; + cv::Ptr parameters; + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); cv::aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds, parameters, rejectedCandidates); ``` @@ -204,7 +204,7 @@ camera: ``` c++ cv::VideoCapture inputVideo; inputVideo.open(0); - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); while (inputVideo.grab()) { cv::Mat image, imageCopy; inputVideo.retrieve(image); @@ -263,9 +263,9 @@ information). The aruco module provides a function to estimate the poses of all the detected markers: ``` c++ - Mat cameraMatrix, distCoeffs; + cv::Mat cameraMatrix, distCoeffs; ... - vector< Vec3d > rvecs, tvecs; + std::vector rvecs, tvecs; cv::aruco::estimatePoseSingleMarkers(corners, 0.05, cameraMatrix, distCoeffs, rvecs, tvecs); ``` @@ -303,7 +303,7 @@ A basic full example for pose estimation from single markers: // camera parameters are read from somewhere readCameraParameters(cameraMatrix, distCoeffs); - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); while (inputVideo.grab()) { cv::Mat image, imageCopy; @@ -311,14 +311,14 @@ A basic full example for pose estimation from single markers: image.copyTo(imageCopy); std::vector ids; - std::vector > corners; + std::vector> corners; cv::aruco::detectMarkers(image, dictionary, corners, ids); // if at least one marker detected if (ids.size() > 0) { cv::aruco::drawDetectedMarkers(imageCopy, corners, ids); - vector< Mat > rvecs, tvecs; + std::vector rvecs, tvecs; cv::aruco::estimatePoseSingleMarkers(corners, 0.05, cameraMatrix, distCoeffs, rvecs, tvecs); // draw axis for each marker for(int i=0; i dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); ``` DICT_6X6_250 is an example of predefined dictionary of markers with 6x6 bits and a total of 250 @@ -390,7 +390,7 @@ The dictionary can be generated automatically to adjust to the desired number of the inter-marker distance is optimized: ``` c++ - cv::aruco::Dictionary dictionary = cv::aruco::generateCustomDictionary(36, 5); + cv::Ptr dictionary = cv::aruco::generateCustomDictionary(36, 5); ``` This will generate a customized dictionary composed by 36 markers of 5x5 bits. The process can take several @@ -432,7 +432,7 @@ Fortunately, a marker can be easily transformed to this form using the static me For example: ``` c++ - Dictionary dictionary; + cv::aruco::Dictionary dictionary; // markers of 6x6 bits dictionary.markerSize = 6; // maximum number of bit corrections @@ -440,10 +440,11 @@ For example: // lets create a dictionary of 100 markers for(int i=0; i<100; i++) + { // assume generateMarkerBits() generate a new marker in binary format, so that // markerBits is a 6x6 matrix of CV_8UC1 type, only containing 0s and 1s cv::Mat markerBits = generateMarkerBits(); - cv::Mat markerCompressed = getByteListFromBits(markerBits); + cv::Mat markerCompressed = cv::aruco::Dictionary::getByteListFromBits(markerBits); // add the marker as a new row dictionary.bytesList.push_back(markerCompressed); } diff --git a/modules/aruco/tutorials/charuco_detection/charuco_detection.markdown b/modules/aruco/tutorials/charuco_detection/charuco_detection.markdown index b443da09c7..7273550d3d 100644 --- a/modules/aruco/tutorials/charuco_detection/charuco_detection.markdown +++ b/modules/aruco/tutorials/charuco_detection/charuco_detection.markdown @@ -60,9 +60,9 @@ Once we have our ```CharucoBoard``` object, we can create an image to print it. ```CharucoBoard::draw()``` method: ``` c++ - cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); + cv::Ptr board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); cv::Mat boardImage; - board.draw( cv::Size(600, 500), boardImage, 10, 1 ); + board->draw( cv::Size(600, 500), boardImage, 10, 1 ); ``` - The first parameter is the size of the output image in pixels. In this case 600x500 pixels. If this is not proportional @@ -94,8 +94,8 @@ in the board. So, a detected ChArUco board consists in: -- ```vector charucoCorners``` : list of image positions of the detected corners. -- ```vector charucoIds``` : ids for each of the detected corners in ```charucoCorners```. +- ```std::vector charucoCorners``` : list of image positions of the detected corners. +- ```std::vector charucoIds``` : ids for each of the detected corners in ```charucoCorners```. The detection of the ChArUco corners is based on the previous detected markers. So that, first markers are detected, and then ChArUco corners are interpolated from markers. @@ -107,11 +107,11 @@ The function that detect the ChArUco corners is ```cv::aruco::interpolateCorners cv::Mat cameraMatrix, distCoeffs; // camera parameters are read from somewhere readCameraParameters(cameraMatrix, distCoeffs); - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); - cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); ... - vector< int > markerIds; - vector< vector > markerCorners; + std::vector markerIds; + std::vector> markerCorners; cv::aruco::detectMarkers(inputImage, board.dictionary, markerCorners, markerIds); // if at least one marker detected @@ -136,13 +136,13 @@ are optional. A similar example without these parameters would be: ``` c++ cv::Mat inputImage; - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); - cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); ... - vector< int > markerIds; - vector< vector > markerCorners; - DetectorParameters params; - params.doCornerRefinement = false; + std::vector markerIds; + std::vector> markerCorners; + cv::Ptr params; + params->doCornerRefinement = false; cv::aruco::detectMarkers(inputImage, board.dictionary, markerCorners, markerIds, params); // if at least one marker detected @@ -203,11 +203,11 @@ Finally, this is a full example of ChArUco detection (without using calibration cv::VideoCapture inputVideo; inputVideo.open(0); - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); - cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); - DetectorParameters params; - params.doCornerRefinement = false; + cv::Ptr params; + params->doCornerRefinement = false; while (inputVideo.grab()) { cv::Mat image, imageCopy; @@ -215,7 +215,7 @@ Finally, this is a full example of ChArUco detection (without using calibration image.copyTo(imageCopy); std::vector ids; - std::vector > corners; + std::vector> corners; cv::aruco::detectMarkers(image, dictionary, corners, ids, params); // if at least one marker detected @@ -286,8 +286,8 @@ A full example of ChArUco detection with pose estimation: // camera parameters are read from somewhere readCameraParameters(cameraMatrix, distCoeffs); - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); - cv::aruco::CharucoBoard board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr board = cv::aruco::CharucoBoard::create(5, 7, 0.04, 0.02, dictionary); while (inputVideo.grab()) { cv::Mat image, imageCopy; @@ -295,7 +295,7 @@ A full example of ChArUco detection with pose estimation: image.copyTo(imageCopy); std::vector ids; - std::vector > corners; + std::vector> corners; cv::aruco::detectMarkers(image, dictionary, corners, ids); // if at least one marker detected diff --git a/modules/aruco/tutorials/charuco_diamond_detection/charuco_diamond_detection.markdown b/modules/aruco/tutorials/charuco_diamond_detection/charuco_diamond_detection.markdown index 9f56cc2e93..62bbc66aed 100644 --- a/modules/aruco/tutorials/charuco_diamond_detection/charuco_diamond_detection.markdown +++ b/modules/aruco/tutorials/charuco_diamond_detection/charuco_diamond_detection.markdown @@ -46,7 +46,7 @@ For instance: ``` c++ cv::Mat diamondImage; - cv::aruco::Dictionary dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); + cv::Ptr dictionary = cv::aruco::getPredefinedDictionary(cv::aruco::DICT_6X6_250); cv::aruco::drawCharucoDiamond(dictionary, cv::Vec4i(45,68,28,74), 200, 120, markerImage); ``` @@ -78,14 +78,14 @@ After detecting markers, diamond are detected using the ```detectCharucoDiamond( ... - std::vector< int > markerIds; - std::vector< std::vector< cv::Point2f > > markerCorners; + std::vector markerIds; + std::vector> markerCorners; // detect ArUco markers cv::aruco::detectMarkers(inputImage, dictionary, markerCorners, markerIds); - std::vector< cv::Vec4i > diamondIds; - std::vector< std::vector< cv::Point2f > > diamondCorners; + std::vector diamondIds; + std::vector> diamondCorners; // detect diamon diamonds cv::aruco::detectCharucoDiamond(inputImage, markerCorners, markerIds, squareLength / markerLength, diamondCorners, diamondIds); @@ -107,8 +107,8 @@ corners and ids: ``` c++ ... - std::vector< cv::Vec4i > diamondIds; - std::vector< std::vector< cv::Point2f > > diamondCorners; + std::vector diamondIds; + std::vector> diamondCorners; cv::aruco::detectCharucoDiamond(inputImage, markerCorners, markerIds, squareLength / markerLength, diamondCorners, diamondIds); cv::aruco::drawDetectedDiamonds(inputImage, diamondCorners, diamondIds); @@ -134,8 +134,8 @@ i.e. using the ```estimatePoseSingleMarkers()``` function. For instance: ``` c++ ... - std::vector< cv::Vec4i > diamondIds; - std::vector< std::vector< cv::Point2f > > diamondCorners; + std::vector diamondIds; + std::vector> diamondCorners; // detect diamon diamonds cv::aruco::detectCharucoDiamond(inputImage, markerCorners, markerIds, squareLength / markerLength, diamondCorners, diamondIds);