Giter Club home page Giter Club logo

Comments (6)

shekhar-chauhan avatar shekhar-chauhan commented on June 12, 2024

I'd be more than happy to take over the issue if someone can do a basic code walkthrough for me, regarding what all places do I need to look into and such.

from opencv.

crackwitz avatar crackwitz commented on June 12, 2024

I have no specific ideas about what causes this to happen. I'd recommend starting at the failing assertion. I'd recommend setting up your environment so you can edit the code in that module, and setting up a little test program (Python or C++) to provoke the issue.

You don't need permission to work on this. If you want to, go ahead. Every amount of investigation is very welcome. I'm only reporting the issue so me "giving permission" means little.

from opencv.

amitsingh19975 avatar amitsingh19975 commented on June 12, 2024

I just looked into the code and from what I can see, detectMarkers generates detected_corners, a tuple of arrays. The shape of the array is 4x2 (Matrix of 4 rows and 2 cols). However, the function CharucoBoardImpl::matchImagePoints expects the Matrix of 1x2.

CV_Assert((int)detectedCharucoVecMat[i].total() * detectedCharucoVecMat[i].channels() == 2);

Possible fixes:

  • Change the Python code to generate a new compatible detected_corners object
temp = []
for i in range(4):
    row = np.array([], dtype=np.float32)
    for c in detected_corners:
        assert len(c[0]) == 4
        row = np.append(row, c[0][i])
    row = row.reshape(24, 1, 2)
    temp.append(tuple(row))

print(f"{len(detected_ids)} detected")

for i in range(len(temp)):
    (obj_points, img_points) = board.matchImagePoints(
        detectedCorners=temp[i],
        detectedIds=detected_ids)
    print(f"obj_points: {obj_points}")
  • Fix it in the code. Add a loop to make it generic to support the Matrix of n x 2

from opencv.

crackwitz avatar crackwitz commented on June 12, 2024

I wrote the Python code emulating a C++ example in the docs (think I linked to it earlier). I did not try to run the C++ example.

Either I did the language translation wrong, or that example itself is broken.

The input to one of these functions is a list of arucos and their four corners each.

I do not think that this function merely expects a reshaping of that. I think that code wants something else, which is the checkerboard corners, not the marker corners.

That is why I opened this issue.

If it were as simple as reshaping, which I tried (and that too failed with an assertion), even that would have to be documented and/or fixed.

Maybe this is something that can only be handled by @AleksandrPanov because he's the most knowledgeable w.r.t. the aruco module.

from opencv.

amitsingh19975 avatar amitsingh19975 commented on June 12, 2024

I wrote the Python code emulating a C++ example in the docs (think I linked to it earlier). I did not try to run the C++ example.

Either I did the language translation wrong, or that example itself is broken.

The input to one of these functions is a list of arucos and their four corners each.

I do not think that this function merely expects a reshaping of that. I think that code wants something else, which is the checkerboard corners, not the marker corners.

That is why I opened this issue.

If it were as simple as reshaping, which I tried (and that too failed with an assertion), even that would have to be documented and/or fixed.

Maybe this is something that can only be handled by @AleksandrPanov because he's the most knowledgeable w.r.t. the aruco module.

From the API's point of view, I can tell it expects a corner but not all four altogether. I tested this and I'm getting the same object point for all three corners. Maybe there is a step in between detecting the markers and getting the image point.

I also saw the drawDetectedMarkers and it picks the first point from all 4 corners.

Note: I'll test C++ example code and come back to you again.

from opencv.

amitsingh19975 avatar amitsingh19975 commented on June 12, 2024

I looked into examples relating to matchImagePoints and detectMarkers, and found something interesting.

The (only) class that is handling all four detected markers is GridBoard; however, CharucoBoard is putting a restriction on the number of markers to 1 per point.

Example 1 (GridBoard) => detect_board.cpp:

aruco::GridBoard board(Size(markersX, markersY), markerLength, markerSeparation, dictionary);
...
detector.detectMarkers(image, corners, ids, rejected);
...
board.matchImagePoints(corners, ids, objPoints, imgPoints);

Example 2 => aruco_detect_board_charuco.py

board = cv.aruco.CharucoBoard(board_size, square_len, marker_len, aruco_dict)
charuco_detector = cv.aruco.CharucoDetector(board) // This is different in your example
charuco_corners, charuco_ids, marker_corners, marker_ids = charuco_detector.detectBoard(image) // here they are using detectBoard rather than detectMarkers
...
obj_points, img_points = board.matchImagePoints(charuco_corners, charuco_ids)

In this example, detectBoard does both detectMarkers and interpolateCornersCharucoApproxCalib/interpolateCornersCharucoLocalHom because of this your markers are converted to a matrix of 1 x 2.

void detectBoard(InputArray image, OutputArray charucoCorners, OutputArray charucoIds,

from opencv.

Related Issues (20)

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.