Coder Social home page Coder Social logo

opencv-markerprinter-wrong-charuco-board's Introduction

Reproduction of bug in OpenCV's MarkerPrinter tool

This repository demonstrates/reproduces a bug that leads to faulty Charuco boards generated by OpenCV's MarkerPrinter tool.

The MarkerPrinter tool can be found here: https://github.com/opencv/opencv_contrib/tree/4.x/modules/aruco/misc/pattern_generator

Example: Board generated by MarkerPrinter

Consider the following command:

python MarkerPrinter.py --charuco --file "./charuco.svg" --dictionary DICT_4X4_1000 --size_x 9 --size_y 6 --square_length 0.25 --marker_length 0.15 --border_bits 1

Look at the result. Note that the top-left square is a white square:

Image of a 9x6 Charuco board generated by MarkerPrinter

Example: Board generated by OpenCV

Compare this with the board generated/expected by OpenCV when using the same parameters (same dictionary, same board size etc):

python generate_board_with_opencv.py --pattern-size 9 6

Now the top-left square is a black square:

Image of a 9x6 Charuco board generated by OpenCV

Consequence

As a consequence, OpenCV will be unable to properly detect the Charuco board that was generated by the MarkerPrinter tool. OpenCV expects the top-left square to be black. Therefore many corners will not be detected at all and there will be all kinds of misdetections (mislabelled corners/markers etc).

Example of such a broken detection:

Example image of a faulty Charuco board detection

Workaround

If you, like me, don't want to print another Charuco board and repeat the image capturing, you might be interested in the workaround I used. In your code that uses OpenCV to detect the Charuco board, you can manually specify another Charuco marker order.

number_of_markers = 27
ids = np.array(range(number_of_markers)[::-1])  # reverse order
logger.info("Charuco marker IDs: %s", ids)
board = cv.aruco.CharucoBoard((PW, PH), square_length, marker_length, dictionary, ids)

By reversing the order of the IDs you're basically rotating the board by 180°. Then, the new top-left square will be a black square (like expected by OpenCV) and OpenCV will properly detect the charuco board and all its corners/markers.

If you apply this workaround to the example board from above, the result will then look like this:

Example image of a Charuco board detection fixed by the workaround

Note that the frameAxes are drawn in the bottom-right corner. Also note how the corner IDs are starting at 0 in the bottom-right corner. This is because, from OpenCV's perspective, the bottom-right corner now is actually the top-left corner (because the Charuco marker IDs have been specified in reverse order).

opencv-markerprinter-wrong-charuco-board's People

Contributors

rsnitsch avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.