kyamagu / mexopencv

Collection and a development kit of matlab mex functions for OpenCV library
http://kyamagu.github.io/mexopencv
Other
661 stars 319 forks source link

ArUco diamond pose appears incorrect #412

Closed changh95 closed 6 years ago

changh95 commented 6 years ago

First of all, big thanks to the developer for making mexopencv. Really helping my project!

I was ArUco markers for tracking purpose, and I happened to use ArUco Diamond patterns for tracking too. Generally, ArUco markers have x = red, y= green, z= blue. I assumed that ArUco Diamond should have a similar pattern, but apparently not.

As seen in the photo, x = blue, y= green, z=red. I don't think this is an error, since all I have edited from the sample is using 2 cameras, rather than 1.

Can we somehow fix this to the same fashion as single ArUco markers?

ArUco Diamond: image

Single ArUco (From OpenCV documentation): image

Many Thanks

amroamroamro commented 6 years ago

https://github.com/kyamagu/mexopencv/wiki/Gotchas#bgr-vs-rgb-color-format

The reason is different conventions; MATLAB images are normally RGB while OpenCV assumes BGR channel order. This interpretation also applies to color options in other drawing functions.

The solution is to simply flip RGB to BGR before passing the color image as input to Aruco drawing functions. Don't forget to flip back the channels before displaying the image with MATLAB's imshow and the like.

So it would go like this:

img = imread('..');
img = flip(img, 3);  %img = cv.cvtColor(img, 'RGB2BGR');
[corners, ids] = cv.detectMarkers(img, ..);
img = cv.drawDetectedMarkers(img, ..);
img = cv.drawAxis(img, ..);
img = flip(img, 3);  %img = cv.cvtColor(img, 'BGR2RGB');
imshow(img)

PS: Note that we tried to provide a convenience 'FlipChannels' option that does this automatically, but it's mostly only exposed in I/O functions like cv.imread and cv.imwrite.

changh95 commented 6 years ago

Thanks a lot @amroamroamro !

Just clarifying to anyone who's reading this thread:

I just checked the xyz convention my single ArUco marker, and I found out it has the same colour convention as the diamond ArUco marker.

This should mean that the data should be presented the same way between the single ArUCo marker and the diamond ArUco marker, which I was unsure previously therefore asked a question on.

It's just the difference in colour convention between MATLAB and OpenCV, which should not be a big problem for my project.