0


I have built a Project with Opencv inside then using it in C#.
But i cant package my project include opencv libs into Dynamic DLL then calling it in C#.
Can somebody give me some hints? :(
My Code:

#include "opencv\cv.h"
#include "opencv\highgui.h"
using namespace cv;
extern "C" _declspec(dllexport) string OpenCVTest(string fileName)
{   

     Mat img = imread(fileName);    
     IplImage image = img;  
     cvShowImage("Hello world", &image);
     cvWaitKey(0);
     cvDestroyAllWindows();

     return "";
}
Huy Phan
  • 11
  • 1
  • 5

1 Answers1

0

You have to use Pinvoke technology which let you call c++ functions from c# code .

if you have such a function written in c++

extern "C" {

MYAPI void print_line(const char* str);

}

you can define a prototype for it in c#

[DllImport("NativeLib.dll")]
private static extern void print_line(string str);

and then you can use it in c# as a normal function

if you want to pass a std::string from c# then you must use a marshaller for it please refer to this

Custom Marshaler for PInvoke with std::string

Community
  • 1
  • 1
Yamen Ajjour
  • 1,422
  • 13
  • 32
  • But i cant import OpenCV Lib to C#. How can i package Opencv lib into my project C++ Dynamic DLL? – Huy Phan Jul 11 '14 at 06:51
  • you have to link your c++ library against opencv and offcourse these dlls have to be available to the c# exe upon execuation – Yamen Ajjour Jul 11 '14 at 06:55