1

I have gotten someone else's code from at least a year ago, I don't have any information about which version of OpenCv they used, I am guessing maybe OpenCV 3. I am using OpenCV 4 and I need to "translate" their code to OpenCV 4.

Let's start with

from cv2 import aruco

They (old code I got) used the aruco.detectMarkers command similar to this:

corners, ids, rejectedImgPoints = aruco.detectMarkers(
    gray,
    aruco_dictionary,
    parameters,
    cameraMatrix,
    distCoeff
)

However, in the new Open CV 4, the inputs for "aruco.detectMarkers" are only these three: image (gray), aruco_dictionary and parameters so this command fails. I can get it to work by calling it as:

corners, ids, rejectedImgPoints = aruco.detectMarkers(
    gray,
    aruco_dictionary,
    parameters
    )

So camera matrix and distortion coefficients are not an input. However, if I am not giving the camera matrix and distortion coefficients as an input, am I not loosing some input information? Will that give me a different output than they have originally gotten using their command?

I can't find any documentation for the older version of the aruco.detectMarkers function to compare these two.

Judita
  • 13
  • 4
  • 1
    Docs say "Note The function does not correct lens distortion or takes it into account. It's recommended to undistort input image with corresponging camera model, if camera parameters are known" https://docs.opencv.org/4.x/d9/d6a/group__aruco.html#ga061ee5b694d30fa2258dd4f13dc98129 – Micka Jun 27 '22 at 18:22
  • @Micka What you have pointed out refers to version `4.6.0-dev`. [This link](https://docs.opencv.org/4.5.5/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa) gets what the OP is looking for in version `4.5.5`. Same can be found in version `4.4.0`: https://docs.opencv.org/4.4.0/d9/d6a/group__aruco.html#gab9159aa69250d8d3642593e508cb6baa – Jeru Luke Jun 27 '22 at 18:43
  • welcome! please take the [tour], if you haven't yet. – Christoph Rackwitz Jun 27 '22 at 21:05
  • @JeruLuke would you recommend to a beginner (good programming experience but beginner in python, openCV and computer vision) to use 4.5.5 or 4.6.0? I am a bit afraid of using a dev version since there might be bugs and other stuff that comes with dev versions. – Judita Jun 28 '22 at 09:19
  • those aren't dev versions. they're proper releases. use the most current release. there are no bugs in the current release that affect you. a misphrasing in the docs is inconvenient but not a bug. -- that "someone else's code" was buggy, relying on something in OpenCV that wasn't meant to be used like that. – Christoph Rackwitz Jun 28 '22 at 09:21
  • @Judita You can use `4.5.5`, it is stable. Moreover, Christoph has given good advice – Jeru Luke Jun 28 '22 at 10:11

1 Answers1

1

You need to use two functions:

  • detectMarkers, gives you the quad and id for every marker it finds in the picture
  • estimatePoseSingleMarkers (or the same for boards...) will recover the poses of the passed in marker quads, given the camera matrix and distortion coefficients, and length (applies to all given markers).

Do not explicitly undistort the picture.

Opencv v4.6.0 got a bunch of changes to the aruco code. It also seems to have removed some misguided implementation options, so that is good. detectMarkers is not supposed to undistort the picture or the points. That's what estimatePose... is already doing.

The additional "Note" in the v4.6.0 docs is simply wrong. You might wanna open an issue about that.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • So does this mean that the old function for detecting markers (in opencv 3 and up to 4.5.5. as mentioned above in a comment) is not good and the one from 4.6.0. without distortion parameters and camera matrix is better because one would want to rather take care of dist and camera matrix themselves before applying detectMarkers? – Judita Jun 28 '22 at 09:16
  • your question in that comment appears completely backwards, suggesting that you understood the opposite of what I meant to convey. the "old" function was merely reduced to what it was *always meant to do*. it is still involved, as I said. I don't know how to state this any plainer. `detectMarkers` is supposed to find the corners of markers. nothing more. any undistortion is supposed to be handled by `estimatePose*` – Christoph Rackwitz Jun 28 '22 at 09:19
  • sorry but I still understand your comment the same as my comment. So if the "old" function is reduced to what it was always meant to do (only find the coners of markers), then what was the purpose of camera matrix and distortion coefficients in the old input? – Judita Jun 28 '22 at 09:25
  • the purpose of those arguments seems to have been applying undistortion to the corner points... but that would conflict with the subsequent functions _also_ doing undistortion. it is simply unsafe to allow this to be done in multiple places because the APIs can't ensure that it is done exactly once. – Christoph Rackwitz Jun 28 '22 at 09:34