aruco.drawAxis() gone?

An example code can be found here: ArUco Marker Tracking with OpenCV | by Ali Yasin Eser | Medium

I used to use it without issues. I haven’t used OpenCV/Aruco for over a year and have changed PCs since then.

Today I installed OpenCV and Aruco for Python and tried to run my old code which included a aruco.drawAxis() call. I’m told it doesn’t exist, yet I can’t find what has replaced it?

Side question, what documentation should I use if I use Python? The C++ API reference doesn’t seem to map 1:1 to Python and is confusing to a non-C++ dev.

1 Like

try cv::drawFrameAxes

C++ does map 1:1 to python, unless some C++ API hasn’t been prepared for the mapping, then it’s simply missing.

aruco is contrib, not part of the main repo. someone has been changing a lot of stuff in the aruco module recently. the axes drawing code got moved out of there… you can tell how fresh it is by the broken english of the documentation for that API.

1 Like

Well, one slightly confusing part to me is the API reference has tons of modules, but in Python most methods I used so far seem to be directly under “cv” and “aruco” so it requires some guessing work to know in what module each method is in the API reference, unless you solely rely on the search tool.

Anyway, thank you, I should have thought of the possibility that it was simply moved.
My code does not show any results any more in a separate window as it used to with older versions but it also does not raise any errors. Any ideas what is going on?

etval, rvec, tvec = aruco.estimatePoseBoard( corners, ids, board, camera_matrix, dist_coeffs, None, None )

frame = cv2.drawFrameAxes( img, camera_matrix, dist_coeffs, rvec, tvec, length=0.003 )
frame = aruco.drawDetectedMarkers( img, corners, ids )

cv2.imshow("Frame", frame)
  • open API docs
  • API docs state the fully qualified signature for C++ and python

that code would always have created/shown one window.

do not use the return values of drawing functions. they alter the image (first argument) and return that, so it’s pointless.

in your code, img is frame (identity)

if your code misbehaves, debug it. that means singlestepping and inspecting variables.

I want to see the drawn markers. If aruco.drawDetectedMarkers() alters the image and returns that, then it sounds like I want to show what it has returned, which seems like what I’m doing.
The code doesn’t raise any errors so I don’t know what to debug, as it worked with previous versions.

I tried to say the exact opposite of what you understood. whatever you understood, take the opposite, and that’s what I meant.

or scratch all that and DO NOT try to assign the result of those calls to anything. it’s pointless. it’s the SAME object you passed in.

SAME meaning this:

clear now?

if you can’t debug your code, at least present a MRE so others can debug it.

Please bear with me.
Are you saying these calls mutate the object passed as an argument, and there’s no need to assign the return value to the same reference? If these are methods that mutate an object I’d expect them to return nothing, but they return a numpy.ndarray, so it feels like they are designed to work either way. Maybe you just mean it is redundant since both ways work and I should use the shorter code?

In any case this doesn’t make a difference.
MRE for this is not quite minimum, as I can’t just share the code, I need to also share images and json files the code uses. Do you want that? Forum doesn’t let me post more than 2 links at a time.

The code does seem to work, if I save the img to a file ( https://i.imgur.com/GABemwk.png ). The issue is cv2.imshow("Frame", img) opens for one frame and closes. If I do something like input() after the code to prevent the window from quickly closing, I see the window is actually blank, the image is not actually displayed on it.

yes, exactly.

there is absolutely no point in assigning the return value because you already have that. the only time it would make sense is if you do not have a reference to what you passed in, say like highlighted = cv.rectangle(source.copy(), ...) (to keep source clean, make a copy, draw on it, and keep a ref)

what you see is a consequence of how the Python API is generated, from the C++ API.

the C++ APIs don’t return anything.

yes, data would be good to have… if that is required to reproduce the issue. you can throw multiple images onto imgur, or one per post right here. JSON would also fit in a post, if it’s not megabytes of it. for other non-image data, people tend to use google drive, dropbox, or similar services.

some issues don’t need data attached, if the “data” can be generated in source. if you can reproduce the issue with dummy data, that’s perfectly fine. the important thing is to give people something they can run, see the issue for themselves, and explore/debug it.

your code so far only contains one imshow, but no waitkey at all. do you mean to tell me that code is misbehaving? I assumed you’d still be holding back some code, which is the actual code you have trouble with.

if what you posted is the MRE, then clearly you’re missing a waitKey. in that case, I’d recommend reviewing some of the tutorials on docs.opencv.org that demonstrate imshow… and a MRE for that issue wouldn’t need any data at all because you can reproduce that effect with nothing but img = np.zeros((512, 512, 3), 'uint8'); ... the “minimal” in MRE means simplifying the problem, which also means simplifying the required data

1 Like

You are right, I wasn’t using waitkey(), but I was using Python’s own input(), and it is ran after the imgshow() function is called, so it is odd that Python’s official input() wouldn’t work and would result in imgshow() not having an image loaded in the window yet.

Regarding linking images and data files, I think your forum makes it a bit annoying for people trying to help. Let me explain. I prepared an MRE which included two json files and one image file. The issue is the forum prevents new users from having more than one link.

You could argue that the json file contents could be embedded in the post itself, but that requires the person trying to help to create a new file and copy paste the content from the post inside them manually. Sure, it may not seem a big deal but extra ~10 seconds may be detracting enough for someone with already limited free time to browse these forums.
Adding ability to attach small files to the post itself would make it easier for everyone.

those things have nothing at all to do with each other.

python’s input() reads from the terminal (stdin). that involves NO GUI at all.

OpenCV’s imshow() announces a picture to be shown in a window owned by OpenCV. waitKey() causes event processing, which is VITAL to all GUI operations.

The point is both wait for user input, so if the image was properly loaded before the interpreter reached input(), it would work.

… what? I think your model of how (python) code executes is deeply flawed. nothing happens concurrently. nothing happens out of order.

I have uploaded the updated code in python on my github page.(GitHub - Ritabrata-Chakraborty/ArUco)