在C#应用程序中调用opencv c ++代码 [英] calling opencv c++ code in C# application

查看:270
本文介绍了在C#应用程序中调用opencv c ++代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经开发了一个使用OpenCV的c ++程序.现在,我想用C#开发一个基于Windows窗体的应用程序. 由于C#仅能处理托管代码,因此几乎不可能直接在C#应用程序上运行OpenCV.我搜索了使用OpenCV创建C#应用程序的不同方法,其中一种是EmguCV,而我更感兴趣的另一种方法是在C#应用程序中导入c ++ .dll文件,并以此方式调用非托管函数.

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.

我首先在c ++中创建了简单的函数,并且能够通过导入dll在我的C#应用​​程序中使用coutcin.当我尝试在我的C ++应用程序中包含OpenCV头文件时,以及在编译时出现此错误,问题就来了

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

错误LNK1104:无法打开文件'tbb_debug.lib'

error LNK1104: cannot open file 'tbb_debug.lib'

以前有人做过,但是我无法弄清楚他如何在C#和C#中进行接口 在图片框中显示cv :: Mat格式的网络摄像头feed

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

问题是我有一个函数,该函数接受cv :: Mat变量并对其执行一些图像处理,然后返回处理后的矩阵.我想在我的C#应用​​程序中使用用C ++编写的函数.但是问题是当我在C ++中包含OpenCV库时,我无法创建dll.

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++.

所以请不要建议我使用EmguCV或任何其他.NET包装器 用于OpenCV.

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

我将Visual Studio 2010用于我的项目.

i am using Visual Studio 2010 for my Project.

推荐答案

我将显式导出将入口点包装在C ++头文件中的方法,然后使用P/Invoke引用它们:

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();

然后在C#中使用它们:

Then consume them in the C#:

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

我不会尝试引用OpenCV标头.

I wouldn't try to reference the OpenCV headers.

这篇关于在C#应用程序中调用opencv c ++代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆