Reputation: 128
I want to create an OpenCV wrapper to use it in C#. I am using this link as a reference http://drthitirat.wordpress.com/2013/06/06/use-opencv-c-codes-in-a-vc-project-solution-of-creating-a-managed-clr-wrapper/ So far I have created a C++ console application that contains my image processing code. Also I created a C++/CLI class library in which I wrapped the OpenCV code, but when i try to build it I get a lot of unresolved externals errors about OpenCV functions used in the C++ code and I don't know how to fix it... Any idea how to fix the problem? Is there a simpler, easier way of using C++ OpenCV code in C#? I don't want to use Emgu or any other wrapper, my image processing code has to be in C++.
Upvotes: 5
Views: 9472
Reputation: 4074
How I solved the problem with opencv using visual studio 2012:
Remark A: I can assure that this solution worked. I used features like pattern detection and camshift with opencv 2.4.2.
Remark B: Another topic is how exactly marshalling should be made. In case of simple data types, there is no doubt in using c++/cli data types like UInt32 etc. But the question is if you want to pass more sophisticated objects like cv::Mat which do not have types direct equivalent in c++/cli. In that case, I made simplified version of such classes on c++/cli side.
Remark C: Don't mess architecture in different projects. If you are using e.g. x86, be consequent in all projects.
Remark D: Practically, the problem using c++ code in c# has two solutions: the one I described and the direct calling to c++ unmanaged code from c# managed code using dynamic on-the-fly marshalling. There are two major disadvantages: on-the-fly marshalling takes time and you do not really know how exactly do this between complex data types (namely, everything what is different than int or string). So c++/cli it is really a good option because you are able to mix managed and unmanaged code.
Remark E: This solution is general, it does not count only in opencv. I successfully used this making c++/cli wrappers to rotation stages (motor devices) which only have c++ drivers and used that drivers in c# code.
Regarding Remark C: Use a dependency walker like Depends (http://www.dependencywalker.com/) to see which dependencies are not consistent.
Upvotes: 9