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

Move contrib charuco to main objdetect #22986

Merged

Conversation

AleksandrPanov
Copy link
Contributor

@AleksandrPanov AleksandrPanov commented Dec 19, 2022

merge with opencv/opencv_contrib#3394

move Charuco API from contrib to main repo:

  • add CharucoDetector:
CharucoDetector::detectBoard(InputArray image, InputOutputArrayOfArrays markerCorners, InputOutputArray markerIds, 
                             OutputArray charucoCorners, OutputArray charucoIds) const // detect charucoCorners and/or markerCorners
CharucoDetector::detectDiamonds(InputArray image, InputOutputArrayOfArrays _markerCorners,
                                InputOutputArrayOfArrays _markerIds, OutputArrayOfArrays _diamondCorners,
                                OutputArray _diamondIds) const
  • add matchImagePoints() for CharucoBoard
  • remove contrib aruco dependencies from interactive-calibration tool
  • move almost all aruco tests to objdetect

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 another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the 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
**WIP**
build_image:Docs=docs-js:18.04
Xbuild_contrib:Docs=OFF

build_image:Custom=javascript
buildworker:Custom=linux-1

Copy link
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

I propose:

  • Do not use inheritance for Charuco. There is no so much in common, but Charuco class gets "detectMarkers", "refineMarkers", etc
  • It makes sense to add constructor with cv::Ptr<ArucoDetector>
  • m.b. extract Charuco interface to dedicated header file.

@AleksandrPanov
Copy link
Contributor Author

I propose:

  • Do not use inheritance for Charuco. There is no so much in common, but Charuco class gets "detectMarkers", "refineMarkers", etc
  • It makes sense to add constructor with cv::Ptr<ArucoDetector>
  • m.b. extract Charuco interface to dedicated header file.

I use inheritance for CharucoDetector to skip setters/getters realisations (getDictionary/setDictionary/getDetectorParameters/setDetectorParameters/...)

@AleksandrPanov AleksandrPanov changed the title add new CharucoDetector API from contrib Move contrib charuco to main objdetect Dec 19, 2022
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from f767839 to 8304d06 Compare December 19, 2022 21:50
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from f226e34 to 9de448c Compare December 20, 2022 07:52
apps/interactive-calibration/frameProcessor.cpp Outdated Show resolved Hide resolved
apps/interactive-calibration/frameProcessor.cpp Outdated Show resolved Hide resolved
modules/objdetect/src/aruco/aruco_detector.cpp Outdated Show resolved Hide resolved
modules/objdetect/src/aruco/aruco_detector.cpp Outdated Show resolved Hide resolved
modules/objdetect/src/aruco/aruco_detector.cpp Outdated Show resolved Hide resolved
@asmorkalov
Copy link
Contributor

alexander@paradox:/mnt/projects/Projects/OpenCV/opencv-build$ ./bin/opencv_interactive-calibration -t=charuco
Hot keys:
esc - exit application
s - save current data to .xml file
r - delete last frame
u - enable/disable applying undistortion
d - delete all frames
v - switch visualization
[ERROR:0@0.002] global persistence.cpp:505 open Can't open file: 'defaultConfig.xml' in read mode
Warning: Unable to open defaultConfig.xml Application started with default advanced parameters
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.6.0-dev) /mnt/projects/Projects/OpenCV/opencv-master/apps/interactive-calibration/main.cpp:107: error: (-213:The function/feature is not implemented) in function 'main'
> Aruco module is disabled in current build configuration. Consider usage of another calibration pattern
> 
Аварийный останов (стек памяти сброшен на диск)

There is old charuco check in main()

@asmorkalov
Copy link
Contributor

Also it makes sense to add Charuco dictionary name as command line parameter and remove it from extended config. It's more obvious and handy solution.

@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from 9de448c to 2eeae14 Compare December 20, 2022 09:12
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from eb0d580 to 5be4c66 Compare December 20, 2022 11:47
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from dd0f91e to 0b8e274 Compare December 20, 2022 14:52
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from 1919f7d to 56d17ff Compare December 20, 2022 22:07
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from c59db63 to f4041a2 Compare December 21, 2022 00:36
@AleksandrPanov AleksandrPanov marked this pull request as ready for review December 21, 2022 00:49
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from d1a7317 to 100cc55 Compare December 21, 2022 07:40
@@ -134,7 +128,7 @@ bool calib::parametersController::loadFromParser(cv::CommandLineParser &parser)
}
else if(templateType.find("charuco", 0) == 0) {
mCapParams.board = chAruco;
mCapParams.boardSize = cv::Size(6, 8);
mCapParams.boardSize = cv::Size(5, 7);
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to touch it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After fix the vars h/w is setting num corners for CharucoBard (like in chessboard)
After fix CharucoBoard create looks like this:
cv::aruco::CharucoBoard::create(mBoardSize.width + 1, mBoardSize.height + 1, capParams.charucoSquareLength,
capParams.charucoMarkerSize, mArucoDictionary);

mCapParams.boardSize = cv::Size(5, 7); was fixed to support compatibility with old default parameters

@asmorkalov
Copy link
Contributor

@alalek The PR is almost ready for merge. Could you take a look?

namespace aruco {

//! @addtogroup aruco
//! @{
Copy link
Member

Choose a reason for hiding this comment

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

Documentation is still broken since #22368 .

There is no aruco group: http://pullrequest.opencv.org/buildbot/export/pr/22986/docs/d5/d54/group__objdetect.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

* @param imgPoints Vector of vectors of the projections of board marker corner points.
*/
CV_WRAP void matchImagePoints(InputArrayOfArrays detectedCorners, InputArray detectedIds,
OutputArray objPoints, OutputArray imgPoints) const override;
protected:
struct CharucoImpl;
Copy link
Member

Choose a reason for hiding this comment

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

class CV_EXPORTS_W CharucoBoard : public Board {

How many PImpl fields in this class with such inheritance?

Must be one (for the discussion above).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you suggest make PImpl fields as private and prevent class inheritors using this field? In the ImageCollection (imgcodecs), Model (dnn), IntelligentScissorsMB classes PImpl fields set as protected and can be used by the class's inheritors.

Copy link
Member

Choose a reason for hiding this comment

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

private

Where is it suggested?


They must reuse the single "impl" field instead of adding a new one.

See Model (dnn) inheritance pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fields GridImpl and CharucoImpl were removed from GridBoard, CharucoBoard

Copy link
Member

Choose a reason for hiding this comment

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

So, change in virtual void matchImagePoints() is not needed anymore.


BTW, too many unnecessary Ptr<> in implementation, especially without NULL checks.
Reference should be used instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

change most Ptr<> to reference

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, do you want me to remove the virtuality for the function matchImagePoints() and generateImage()? Do you want me to use virtuality into Pimpl implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want this kind of code to work correctly:

    cv::Ptr<cv::aruco::Board> board = cv::aruco::CharucoBoard::create(3, 3);
    std::vector<cv::Point2f> a1;
    std::vector<int> a2;
    std::vector<cv::Point2f> a3;
    std::vector<cv::Point2f> a4;
    board->matchImagePoints(a1, a2, a3, a4);

without virtual in matchImagePoints() I need to create func virtual void pimplMatchImagePoints() and call this from main Boards classes

Should I do it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 13 to 14
/** @defgroup objdetect_aruco
* ArUco Marker Detection
Copy link
Contributor

Choose a reason for hiding this comment

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

/build/precommit_docs/4.x/opencv/modules/objdetect/include/opencv2/objdetect/aruco_detector.hpp:13: warning: missing title after \defgroup objdetect_aruco

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

No dots in headers

Copy link
Contributor

Choose a reason for hiding this comment

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

"ArUco" will better

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 move_contrib_charuco_to_main_objdetect branch from 63b8512 to ffe588f Compare December 22, 2022 16:11
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from fdeb045 to 1f214f2 Compare December 22, 2022 18:58
@AleksandrPanov AleksandrPanov force-pushed the move_contrib_charuco_to_main_objdetect branch from 6b6d1b9 to 0ed1de9 Compare December 23, 2022 09:23
@alalek
Copy link
Member

alalek commented Dec 27, 2022

@asmorkalov Is there final approval?

protected:
Board(Ptr<BoardImpl> impl);
template<typename T> T& as() { CV_Assert(boardImpl); return static_cast<T&>(*boardImpl); }
template<typename T> const T& as() const { CV_Assert(boardImpl); return static_cast<const T&>(*boardImpl); }
Copy link
Member

Choose a reason for hiding this comment

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

This could be thrown away from public headers:

See TextRecognitionModel_Impl::from(impl)

@asmorkalov
Copy link
Contributor

@alalek Ready for review

@asmorkalov asmorkalov merged commit 1210348 into opencv:4.x Dec 28, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…uco_to_main_objdetect

merge with opencv/opencv_contrib#3394

move Charuco API from contrib to main repo:

- add CharucoDetector:
```
CharucoDetector::detectBoard(InputArray image, InputOutputArrayOfArrays markerCorners, InputOutputArray markerIds, 
                             OutputArray charucoCorners, OutputArray charucoIds) const // detect charucoCorners and/or markerCorners
CharucoDetector::detectDiamonds(InputArray image, InputOutputArrayOfArrays _markerCorners,
                                InputOutputArrayOfArrays _markerIds, OutputArrayOfArrays _diamondCorners,
                                OutputArray _diamondIds) const
```

- add `matchImagePoints()` for `CharucoBoard`
- remove contrib aruco dependencies from interactive-calibration tool
- move almost all aruco tests to objdetect

### Pull Request Readiness Checklist

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants