Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ArUco tutorial #3126

Merged
merged 1 commit into from
Dec 20, 2021

Conversation

AleksandrPanov
Copy link
Contributor

@AleksandrPanov AleksandrPanov commented Dec 2, 2021

Some ArUco tutorial examples (Detection of ArUco Boards and Detection of ChArUco Corners) aren't reproduced:

  • gboriginal.png // need custom dictionary to detect markers
  • choriginal.png // need custom dictionary and custom board configuration to detect markers
  • diamondmarkers.png // need custom dictionary and custom detector parameters to detect all markers

This PR:

  • fix detection of gboriginal.png and diamondmarkers.png by using custom dictionary from original lib (file tutorial_dict.yml) and custom detector parameters (the required flags have been added to the examples).
  • detection of choriginal.png can't be fixed easy. So, images of ChArUco board are recaptured:
New ChArUco board images

choriginal

chaxis

chocclusion_original

chocclusion_axis

Also this PR:

  • Add to ArUco API: readDetectorParameters() and readDictionary().
  • Add samples_utility.hpp with readCameraParameters(), saveCameraParams().
  • Add tests of tutorial to avoid regression: can_find_singlemarkersoriginal, can_find_gboriginal, can_find_choriginal, can_find_chocclusion, can_find_diamondmarkers.
  • Add custom dictionary tutorial_dict.yml and tutorial_camera_params.yml.
  • Add ChArUco calibration samples:
calibration samples

img_00

img_01

img_02

img_03

  • Add tutorial_camera_charuco.yml (created by calibrate_camera_charuco.cpp and calibration samples).
  • Add prev/next links.
  • Check and update flags for samples.
  • Add some snippets.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@AleksandrPanov AleksandrPanov force-pushed the update_ArUco_tutorial branch 9 times, most recently from 5fd0f91 to deaa392 Compare December 8, 2021 13:40
@AleksandrPanov AleksandrPanov added category: documentation Documentation fix or update, does not affect code category: samples category: aruco labels Dec 8, 2021
@AleksandrPanov AleksandrPanov force-pushed the update_ArUco_tutorial branch 3 times, most recently from 13ff2da to 2c618f8 Compare December 8, 2021 16:41
@AleksandrPanov AleksandrPanov marked this pull request as ready for review December 8, 2021 16:43
@AleksandrPanov AleksandrPanov force-pushed the update_ArUco_tutorial branch 2 times, most recently from 894f98d to e2a3014 Compare December 10, 2021 09:00
@AleksandrPanov AleksandrPanov marked this pull request as draft December 10, 2021 09:58
@AleksandrPanov AleksandrPanov force-pushed the update_ArUco_tutorial branch 2 times, most recently from 5b6b44f to 3d855aa Compare December 10, 2021 14:48
@AleksandrPanov AleksandrPanov marked this pull request as ready for review December 10, 2021 16:02
@AleksandrPanov
Copy link
Contributor Author

@alalek, @asmorkalov, @mshabunin, could you review this PR?

@AleksandrPanov AleksandrPanov force-pushed the update_ArUco_tutorial branch 4 times, most recently from 03fc10f to 9f2b371 Compare December 14, 2021 22:45
@asmorkalov
Copy link
Contributor

@alalek could you look and merge.

@@ -0,0 +1,110 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Samples doesn't have license header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

// of this distribution and at http://opencv.org/license.html.

#ifndef _SAMPLES_UTILITY_HPP_
#define _SAMPLES_UTILITY_HPP_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need guard here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#include <opencv2/calib3d.hpp>
#include <ctime>

inline bool readCameraParameters(std::string filename, cv::Mat &camMatrix, cv::Mat &distCoeffs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline -> static

Copy link
Contributor Author

@AleksandrPanov AleksandrPanov Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI throw warning to static functions:
warning: defined but not used [-Wunused-function]
what to do in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because not every sample uses all functions from samples_utility.hpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I should use static inline?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These attached messages comes from tests compilation, not sample code.

Anonymous namespace may help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anonymous namespace didn't help ((( (warnings are still there due to tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed
include of aruco_samples_utility.hpp is removed from tests

@@ -44,6 +44,7 @@ the use of this software, even if advised of the possibility of such damage.
#include <vector>
#include <iostream>
#include <ctime>
#include "samples_utility.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"samples_utility.hpp" -> "aruco_samples_utility.hpp"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -36,7 +23,7 @@ void createBoard()
}

//! [detwcp]
void detectCharucoBoardWithCalibrationPose()
inline void detectCharucoBoardWithCalibrationPose()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static

Copy link
Contributor Author

@AleksandrPanov AleksandrPanov Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add static inline to avoid warning: defined but not used [-Wunused-function]

@@ -36,8 +36,9 @@ or tort (including negligence or otherwise) arising in any way out of
the use of this software, even if advised of the possibility of such damage.
*/


#include <opencv2/core/utils/logger.defines.hpp>
#include "test_precomp.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

precomp must go first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#include "test_precomp.hpp"
#include "../samples/samples_utility.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test should not rely on samples code.
Samples code should not be over-complicated by tests specific.

Copy link
Contributor Author

@AleksandrPanov AleksandrPanov Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need functions from samples_utility.hpp to advoid code duplication in tests.

Copy link
Contributor Author

@AleksandrPanov AleksandrPanov Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also some ArUco samples just don't work (in 3.4/4.x). Maybe using functions in a test will allow CI to check workability of samples.

I understand, that "test should not rely on samples code". But I don't know how check workability of samples in this case.

Copy link
Contributor Author

@AleksandrPanov AleksandrPanov Dec 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alalek I can do this:

  1. add readDetectorParameters() to ArUco API
  2. add readDictionary() to ArUco API
  3. remove aruco_samples_utility.hpp
  4. just reinsert readCameraParameters() and saveCameraParams() to samples/tests code.

Would it be ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense (using cv::FileNode instead of std::string).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alalek it should look something like this?

template<typename T>
inline void readParameter(FileNode node, T& parameter)
{
    if (!node.empty())
        node >> parameter;
}

/**
  * @brief Read a new set of DetectorParameters from FileStorage.
  */
Ptr<DetectorParameters> DetectorParameters::readDetectorParameters(const Ptr<FileStorage>& pfs)
{
    CV_Assert(!pfs.empty());
    const FileStorage& fs = *pfs;
    Ptr<DetectorParameters> params = DetectorParameters::create();
    readParameter(fs["adaptiveThreshWinSizeMin"], params->adaptiveThreshWinSizeMin);
    readParameter(fs["adaptiveThreshWinSizeMax"], params->adaptiveThreshWinSizeMax);
    readParameter(fs["adaptiveThreshWinSizeStep"], params->adaptiveThreshWinSizeStep);
    readParameter(fs["adaptiveThreshConstant"], params->adaptiveThreshConstant);
    readParameter(fs["minMarkerPerimeterRate"], params->minMarkerPerimeterRate);
    readParameter(fs["maxMarkerPerimeterRate"], params->maxMarkerPerimeterRate);
    readParameter(fs["polygonalApproxAccuracyRate"], params->polygonalApproxAccuracyRate);
    readParameter(fs["minCornerDistanceRate"], params->minCornerDistanceRate);
    readParameter(fs["minDistanceToBorder"], params->minDistanceToBorder);
    readParameter(fs["minMarkerDistanceRate"], params->minMarkerDistanceRate);
    readParameter(fs["cornerRefinementMethod"], params->cornerRefinementMethod);
    readParameter(fs["cornerRefinementWinSize"], params->cornerRefinementWinSize);
    readParameter(fs["cornerRefinementMaxIterations"], params->cornerRefinementMaxIterations);
    readParameter(fs["cornerRefinementMinAccuracy"], params->cornerRefinementMinAccuracy);
    readParameter(fs["markerBorderBits"], params->markerBorderBits);
    readParameter(fs["perspectiveRemovePixelPerCell"], params->perspectiveRemovePixelPerCell);
    readParameter(fs["perspectiveRemoveIgnoredMarginPerCell"], params->perspectiveRemoveIgnoredMarginPerCell);
    readParameter(fs["maxErroneousBitsInBorderRate"], params->maxErroneousBitsInBorderRate);
    readParameter(fs["minOtsuStdDev"], params->minOtsuStdDev);
    readParameter(fs["errorCorrectionRate"], params->errorCorrectionRate);
    return params;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileNode node

const reference.


Ptr<FileStorage>&

FileNode instead of FileStorage as mentioned before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

TEST(CV_ArucoTutorial, can_find_singlemarkersoriginal)
{
string img_path = samples::findFile("../opencv_contrib/modules/aruco/tutorials/aruco_detection/images"
"/singlemarkersoriginal.jpg", true, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

samples::findFile

Test code should not use samples data.

../opencv_contrib/modules

Wrong way.


Check "text" module tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed!)
check opencv_contrib/modules/aruco/CMakeLists.txt

@AleksandrPanov AleksandrPanov force-pushed the update_ArUco_tutorial branch 2 times, most recently from 48d852d to 63ad95a Compare December 15, 2021 14:41
@@ -98,6 +98,44 @@ Ptr<DetectorParameters> DetectorParameters::create() {
return params;
}

template<typename T>
inline void readParameter(FileNode node, T& parameter)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static inline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#include <ctime>

namespace {
inline static bool readCameraParameters(std::string filename, cv::Mat &camMatrix, cv::Mat &distCoeffs) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid indentation in namespaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#include "test_precomp.hpp"
#include "../samples/samples_utility.hpp"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FileNode node

const reference.


Ptr<FileStorage>&

FileNode instead of FileStorage as mentioned before.

return 0;
}
FileStorage fs(parser.get<string>("dp"), FileStorage::READ);
detectorParams = aruco::DetectorParameters::readDetectorParameters(fs["aruco_detector_params"]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fs.root()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@AleksandrPanov AleksandrPanov force-pushed the update_ArUco_tutorial branch 2 times, most recently from c3e1180 to 5bbda1c Compare December 17, 2021 16:56
@AleksandrPanov
Copy link
Contributor Author

@alalek, thx for review ^_^
As I think, all issues were fixed

…tion photos, add tests, add aruco_samples_utility.hpp
@AleksandrPanov
Copy link
Contributor Author

@alalek could you check?

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@opencv-pushbot opencv-pushbot merged commit e0db5fd into opencv:3.4 Dec 20, 2021
@alalek alalek mentioned this pull request Dec 22, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
@AleksandrPanov AleksandrPanov deleted the update_ArUco_tutorial branch March 18, 2022 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants