How to use ArUco marker with the openCV support package of MATLAB and the Computer Vision System Toolbox. [R2017b]

27 次查看(过去 30 天)

采纳的回答

MathWorks Support Team
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.
For OpenCV 3 and above, the ArUco modules are part of the opencv_contrib _repository: https://github.com/opencv/opencv_contrib/tree/master/modules/aruco. Any module located in _opencv_contrib is not part of the core OpenCV library, and is therefore not build, linked or shipped with the OpenCV 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.
 

更多回答(0 个)

产品


版本

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by