Commit 40f1ac51 authored by szk1509's avatar szk1509 Committed by Alexander Alekhin

Merge pull request #973 from szk1509:master

new corner refinement method :: using the contour-lines (#973)

* doCornerRefinement to CornerRefinementMethod :: detected contours points are used to detect the corners

* some little corrections

* samples edited

* documented :)

* tabs corrected

* Docu corrections

* refinement for all candidates

* refinement for all candidates :: copy paste error corrected

* comment
parent 4ed8c5eb
...@@ -76,7 +76,11 @@ namespace aruco { ...@@ -76,7 +76,11 @@ namespace aruco {
//! @addtogroup aruco //! @addtogroup aruco
//! @{ //! @{
enum CornerRefineMethod{
CORNER_REFINE_NONE, // default corners
CORNER_REFINE_SUBPIX, // refine the corners using subpix
CORNER_REFINE_CONTOUR // refine the corners using the contour-points
};
/** /**
* @brief Parameters for the detectMarker process: * @brief Parameters for the detectMarker process:
...@@ -100,7 +104,8 @@ namespace aruco { ...@@ -100,7 +104,8 @@ namespace aruco {
* - minMarkerDistanceRate: minimum mean distance beetween two marker corners to be considered * - minMarkerDistanceRate: minimum mean distance beetween two marker corners to be considered
* similar, so that the smaller one is removed. The rate is relative to the smaller perimeter * similar, so that the smaller one is removed. The rate is relative to the smaller perimeter
* of the two markers (default 0.05). * of the two markers (default 0.05).
* - doCornerRefinement: do subpixel refinement or not * - cornerRefinementMethod: corner refinement method. (CORNER_REFINE_NONE, no refinement.
* CORNER_REFINE_SUBPIX, do subpixel refinement. CORNER_REFINE_CONTOUR use contour-Points)
* - cornerRefinementWinSize: window size for the corner refinement process (in pixels) (default 5). * - cornerRefinementWinSize: window size for the corner refinement process (in pixels) (default 5).
* - cornerRefinementMaxIterations: maximum number of iterations for stop criteria of the corner * - cornerRefinementMaxIterations: maximum number of iterations for stop criteria of the corner
* refinement process (default 30). * refinement process (default 30).
...@@ -137,7 +142,7 @@ struct CV_EXPORTS_W DetectorParameters { ...@@ -137,7 +142,7 @@ struct CV_EXPORTS_W DetectorParameters {
CV_PROP_RW double minCornerDistanceRate; CV_PROP_RW double minCornerDistanceRate;
CV_PROP_RW int minDistanceToBorder; CV_PROP_RW int minDistanceToBorder;
CV_PROP_RW double minMarkerDistanceRate; CV_PROP_RW double minMarkerDistanceRate;
CV_PROP_RW bool doCornerRefinement; CV_PROP_RW int cornerRefinementMethod;
CV_PROP_RW int cornerRefinementWinSize; CV_PROP_RW int cornerRefinementWinSize;
CV_PROP_RW int cornerRefinementMaxIterations; CV_PROP_RW int cornerRefinementMaxIterations;
CV_PROP_RW double cornerRefinementMinAccuracy; CV_PROP_RW double cornerRefinementMinAccuracy;
...@@ -165,6 +170,10 @@ struct CV_EXPORTS_W DetectorParameters { ...@@ -165,6 +170,10 @@ struct CV_EXPORTS_W DetectorParameters {
* @param parameters marker detection parameters * @param parameters marker detection parameters
* @param rejectedImgPoints contains the imgPoints of those squares whose inner code has not a * @param rejectedImgPoints contains the imgPoints of those squares whose inner code has not a
* correct codification. Useful for debugging purposes. * correct codification. Useful for debugging purposes.
* @param cameraMatrix optional input 3x3 floating-point camera matrix
* \f$A = \vecthreethree{f_x}{0}{c_x}{0}{f_y}{c_y}{0}{0}{1}\f$
* @param distCoeff optional vector of distortion coefficients
* \f$(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6],[s_1, s_2, s_3, s_4]])\f$ of 4, 5, 8 or 12 elements
* *
* Performs marker detection in the input image. Only markers included in the specific dictionary * Performs marker detection in the input image. Only markers included in the specific dictionary
* are searched. For each detected marker, it returns the 2D position of its corner in the image * are searched. For each detected marker, it returns the 2D position of its corner in the image
...@@ -175,7 +184,7 @@ struct CV_EXPORTS_W DetectorParameters { ...@@ -175,7 +184,7 @@ struct CV_EXPORTS_W DetectorParameters {
*/ */
CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners, CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &dictionary, OutputArrayOfArrays corners,
OutputArray ids, const Ptr<DetectorParameters> &parameters = DetectorParameters::create(), OutputArray ids, const Ptr<DetectorParameters> &parameters = DetectorParameters::create(),
OutputArrayOfArrays rejectedImgPoints = noArray()); OutputArrayOfArrays rejectedImgPoints = noArray(), InputArray cameraMatrix= noArray(), InputArray distCoeff= noArray());
...@@ -196,6 +205,7 @@ CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &diction ...@@ -196,6 +205,7 @@ CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &diction
* Each element in rvecs corresponds to the specific marker in imgPoints. * Each element in rvecs corresponds to the specific marker in imgPoints.
* @param tvecs array of output translation vectors (e.g. std::vector<cv::Vec3d>). * @param tvecs array of output translation vectors (e.g. std::vector<cv::Vec3d>).
* Each element in tvecs corresponds to the specific marker in imgPoints. * Each element in tvecs corresponds to the specific marker in imgPoints.
* @param _objPoints array of object points of all the marker corners
* *
* This function receives the detected markers and returns their pose estimation respect to * This function receives the detected markers and returns their pose estimation respect to
* the camera individually. So for each marker, one rotation and translation vector is returned. * the camera individually. So for each marker, one rotation and translation vector is returned.
...@@ -209,7 +219,7 @@ CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &diction ...@@ -209,7 +219,7 @@ CV_EXPORTS_W void detectMarkers(InputArray image, const Ptr<Dictionary> &diction
*/ */
CV_EXPORTS_W void estimatePoseSingleMarkers(InputArrayOfArrays corners, float markerLength, CV_EXPORTS_W void estimatePoseSingleMarkers(InputArrayOfArrays corners, float markerLength,
InputArray cameraMatrix, InputArray distCoeffs, InputArray cameraMatrix, InputArray distCoeffs,
OutputArray rvecs, OutputArray tvecs); OutputArray rvecs, OutputArray tvecs, OutputArray _objPoints = noArray());
......
...@@ -90,7 +90,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter ...@@ -90,7 +90,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter
fs["minCornerDistanceRate"] >> params->minCornerDistanceRate; fs["minCornerDistanceRate"] >> params->minCornerDistanceRate;
fs["minDistanceToBorder"] >> params->minDistanceToBorder; fs["minDistanceToBorder"] >> params->minDistanceToBorder;
fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate; fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate;
fs["doCornerRefinement"] >> params->doCornerRefinement; fs["cornerRefinementMethod"] >> params->cornerRefinementMethod;
fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize; fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize;
fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations; fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations;
fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy; fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy;
......
...@@ -90,7 +90,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter ...@@ -90,7 +90,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter
fs["minCornerDistanceRate"] >> params->minCornerDistanceRate; fs["minCornerDistanceRate"] >> params->minCornerDistanceRate;
fs["minDistanceToBorder"] >> params->minDistanceToBorder; fs["minDistanceToBorder"] >> params->minDistanceToBorder;
fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate; fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate;
fs["doCornerRefinement"] >> params->doCornerRefinement; fs["cornerRefinementMethod"] >> params->cornerRefinementMethod;
fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize; fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize;
fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations; fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations;
fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy; fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy;
......
...@@ -93,7 +93,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter ...@@ -93,7 +93,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter
fs["minCornerDistanceRate"] >> params->minCornerDistanceRate; fs["minCornerDistanceRate"] >> params->minCornerDistanceRate;
fs["minDistanceToBorder"] >> params->minDistanceToBorder; fs["minDistanceToBorder"] >> params->minDistanceToBorder;
fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate; fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate;
fs["doCornerRefinement"] >> params->doCornerRefinement; fs["cornerRefinementMethod"] >> params->cornerRefinementMethod;
fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize; fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize;
fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations; fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations;
fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy; fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy;
...@@ -145,7 +145,7 @@ int main(int argc, char *argv[]) { ...@@ -145,7 +145,7 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
} }
detectorParams->doCornerRefinement = true; // do corner refinement in markers detectorParams->cornerRefinementMethod = aruco::CORNER_REFINE_SUBPIX; // do corner refinement in markers
String video; String video;
if(parser.has("v")) { if(parser.has("v")) {
......
...@@ -93,7 +93,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter ...@@ -93,7 +93,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter
fs["minCornerDistanceRate"] >> params->minCornerDistanceRate; fs["minCornerDistanceRate"] >> params->minCornerDistanceRate;
fs["minDistanceToBorder"] >> params->minDistanceToBorder; fs["minDistanceToBorder"] >> params->minDistanceToBorder;
fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate; fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate;
fs["doCornerRefinement"] >> params->doCornerRefinement; fs["cornerRefinementMethod"] >> params->cornerRefinementMethod;
fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize; fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize;
fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations; fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations;
fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy; fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy;
......
...@@ -94,7 +94,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter ...@@ -94,7 +94,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter
fs["minCornerDistanceRate"] >> params->minCornerDistanceRate; fs["minCornerDistanceRate"] >> params->minCornerDistanceRate;
fs["minDistanceToBorder"] >> params->minDistanceToBorder; fs["minDistanceToBorder"] >> params->minDistanceToBorder;
fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate; fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate;
fs["doCornerRefinement"] >> params->doCornerRefinement; fs["cornerRefinementMethod"] >> params->cornerRefinementMethod;
fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize; fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize;
fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations; fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations;
fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy; fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy;
......
...@@ -88,7 +88,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter ...@@ -88,7 +88,7 @@ static bool readDetectorParameters(string filename, Ptr<aruco::DetectorParameter
fs["minCornerDistanceRate"] >> params->minCornerDistanceRate; fs["minCornerDistanceRate"] >> params->minCornerDistanceRate;
fs["minDistanceToBorder"] >> params->minDistanceToBorder; fs["minDistanceToBorder"] >> params->minDistanceToBorder;
fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate; fs["minMarkerDistanceRate"] >> params->minMarkerDistanceRate;
fs["doCornerRefinement"] >> params->doCornerRefinement; fs["cornerRefinementMethod"] >> params->cornerRefinementMethod;
fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize; fs["cornerRefinementWinSize"] >> params->cornerRefinementWinSize;
fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations; fs["cornerRefinementMaxIterations"] >> params->cornerRefinementMaxIterations;
fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy; fs["cornerRefinementMinAccuracy"] >> params->cornerRefinementMinAccuracy;
...@@ -127,7 +127,7 @@ int main(int argc, char *argv[]) { ...@@ -127,7 +127,7 @@ int main(int argc, char *argv[]) {
return 0; return 0;
} }
} }
detectorParams->doCornerRefinement = true; // do corner refinement in markers detectorParams->cornerRefinementMethod = aruco::CORNER_REFINE_SUBPIX; // do corner refinement in markers
int camId = parser.get<int>("ci"); int camId = parser.get<int>("ci");
......
This diff is collapsed.
...@@ -299,7 +299,7 @@ void CV_ArucoRefine::run(int) { ...@@ -299,7 +299,7 @@ void CV_ArucoRefine::run(int) {
vector< int > ids; vector< int > ids;
Ptr<aruco::DetectorParameters> params = aruco::DetectorParameters::create(); Ptr<aruco::DetectorParameters> params = aruco::DetectorParameters::create();
params->minDistanceToBorder = 3; params->minDistanceToBorder = 3;
params->doCornerRefinement = true; params->cornerRefinementMethod = aruco::CORNER_REFINE_SUBPIX;
params->markerBorderBits = markerBorder; params->markerBorderBits = markerBorder;
aruco::detectMarkers(img, dictionary, corners, ids, params, rejected); aruco::detectMarkers(img, dictionary, corners, ids, params, rejected);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment