6

I have developed a c++ program which uses OpenCV. Now i want to develop a windows form based application in C#. As C# can only handle managed code it is nearly impossible to run OpenCV directly on C# application. I have searched for different ways to create C# application using OpenCV, one of which is EmguCV and the other method that i am much more interested in is importing the c++ .dll file in C# application and calling the unmanaged functions this way.

I started by creating simple functions in c++ and i was able to use cout and cin in my C# application by importing the dll. The problem comes when i try to include OpenCV header files in my c++ application and when i compile i get this error

error LNK1104: cannot open file 'tbb_debug.lib'

Some one has done this before but i cant figure out how he interface c++ with C# in Displaying webcam feed in cv::Mat format in a picturebox

The Question is that i have function which takes in a cv::Mat variable and performs some image processing on it and returns the processed matrix. i want to use that function written in c++ in my C# application. but the problem is that i am unable to create the dll when i include OpenCV library in c++.

So please Don't Suggest me to use EmguCV or any other .NET wrappers for OpenCV.

i am using Visual Studio 2010 for my Project.

Community
  • 1
  • 1
Mujahid Daud Khan
  • 1,983
  • 1
  • 14
  • 23
  • What is the question? You've already mentioned, that you can create a DLL and access it by P/Invoke. You may also use C++/CLI to write an assembly, which accesses native headers and use native libraries. As for the link error, you provided not enough information for us to tell, what is wrong. – Spook Nov 21 '12 at 12:28
  • i have edited the post, when i try to write any method that uses OpenCV i get an error that i have posted above so the dll cannot be created but when i used only cout and cin no error came up and the dll was created sucessfully – Mujahid Daud Khan Nov 21 '12 at 12:34

2 Answers2

3

I would explicitly export methods that wrap your entry points in a C++ header, and then use P/Invoke to reference them:

extern "C" __declspec(dllexport) BOOL DoSomething();

Then consume them in the C#:

[DllImport("MyOpenCVWrapper.dll")]
private static extern bool DoSomething();

I wouldn't try to reference the OpenCV headers.

frogatto
  • 28,539
  • 11
  • 83
  • 129
tillerstarr
  • 2,616
  • 1
  • 21
  • 35
1

Although it might not be what you're looking for, I did that task with C++/CLI and exposed it through an assembly. It was straight forward and worked pretty well. Blog article here.

plinth
  • 48,267
  • 11
  • 78
  • 120