How can I integrate Open-CV with Mathematica?
Please take a look at the file image_external.c.
that you can find in your installation with the command
FileNames["image_external.c", {$InstallationDirectory}, Infinity]
Therein, everything you want to know is described. When it comes down to compiling, then you need to ensure you have the development files for opencv
and libraw
installed and you know the places, where the header-files "cv.h"
, "highgui.h"
, "imgproc_c.h"
and "libraw.h"
are stored.
Then you can compile the image_external.c
example with a command similar to
Get["CCompilerDriver`"];
CreateLibrary[{"/home/patrick/tmp/ocv/image_external.c"},"imageLib",
"IncludeDirectories" -> { "/usr/include/opencv",
"/usr/include/opencv2/imgproc","/usr/include/libraw"}]
How-to for Mac OS X
Although the approach for OS X is similar, you have to adapt some things. Most importantly you need to know where the include files and the libraries for opencv
and libraw
are stored. If you don't have them, then you can install them with e.g. MacPorts. To find this out, there has always been a nice tool on Unix like systems: pkg-config
. Here is how you call it in a terminal to get the includes and libraries for opencv
:
pkg-config --cflags --libs opencv
Using this command, you can build your final Mathematica call in a minute. Here it is for my machine:
CreateLibrary[{"/Users/patrick/tmp/image_external.c"}, "imageLib",
"IncludeDirectories" -> {"/opt/local/include",
"/opt/local/include/opencv", "/opt/local/include/opencv2/imgproc",
"/opt/local/include/libraw"},
"LibraryDirectories" -> {"/opt/local/lib"},
"Libraries" -> {"opencv_calib3d", "opencv_contrib", "opencv_core",
"opencv_features2d", "opencv_flann", "opencv_gpu",
"opencv_highgui", "opencv_imgproc", "opencv_legacy", "opencv_ml",
"opencv_nonfree", "opencv_objdetect", "opencv_photo",
"opencv_stitching", "opencv_superres", "opencv_ts", "opencv_video",
"opencv_videostab", "raw", "stdc++"}]