There is no toolbox that can do this in MATLAB directly. But it is possible to get this functionality through OpenCV interface support package: https://www.mathworks.com/discovery/matlab-opencv.html Generally, the Computer Vision System Toolbox OpenCV Interface allows it to bring existing OpenCV files and projects into MATLAB using the MEX Interface. It is however possible, to build OpenCV with the _opencv_contrib _modules outside of MATLAB and its installation, and link against it while creating a MEX file. This procedure gives access to the functions of the _opencv_contrib _module of interest. The general steps are as follows:
OpenCV
- download the source code of OpenCV 3.1 from here: <https://github.com/opencv/opencv/tree/3.1.0>
- download the opencv_contrib repository from here: <https://github.com/opencv/opencv_contrib/tree/3.1.0>
- Install openCV on your machine following the instructions here: <https://github.com/opencv/opencv_contrib/blob/master/README.md>
- Note down where the libraries are built, and where the header files are copied.
MATLAB Computer Vision System Toolbox
- install the Computer Vision System Toolbox, e.g. from MATLAB Desktop -> AddOns dropdown -> GetAddons (you can check if this toolbox is covered by your license typing ver in the Command Window)
- install the OpenCV Interface support package following the instructions here: <https://www.mathworks.com/help/vision/ug/opencv-interface.html#buxwnlt>
- (optional) video on “Using OpenCV with MATLAB (<http://youtu.be/BasC2jkgyaM>)”
ArUco
Use the attached getaruco.cpp file as an example, and run the following in the MATLAB Command Window:
>> mexOpenCV getaruco.cpp -L~/opencv310/lib/ -lopencv_aruco.3.1.0 -I/usr/local/include
It is important to replace the paths according to your OpenCV installation. Flag explanation
-L looks in directory for library files
-l links with a library file
-I adds include directory of header files
This should generate a MEX file called getaruco.mex* (* replaced by the OS identifier). Now you can use getaruco() like any other MATLAB function. In the provided example, to create a 1000-by-1000 uint8 image, with a markerId of 12, and border bits size 1, use
>> im = getaruco(1000, 12, 1);
You can then access any class from the ArUco module, by changing the mexFunction() in the getaruco.cpp file. It is suggested to create getArucoFunctionOne.cpp, getArucoFunctionTwo.cpp,etc. for different ArUco functions.
Please note that MATLAB does not link against the highgui, videoio or imgcodecs libraries, so things like imshow in OpenCV are not available.