[英]Creating an C++/CLI OpenCV wrapper to use in C#
I want to create an OpenCV wrapper to use it in C#. 我想创建一个OpenCV包装器以在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.
我使用此链接作为参考http://drthitirat.wordpress.com/2013/06/06/use-opencv-c-codes-in-a-vc-project-solution-of-creating-a-managed- clr-wrapper /到目前为止,我已经创建了一个包含我的图像处理代码的C ++控制台应用程序。 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?
我还创建了一个C ++ / CLI类库,其中包含了OpenCV代码,但是当我尝试构建它时,我得到了许多关于C ++代码中使用的OpenCV函数的未解决的外部错误,我不知道如何解决它...知道如何解决这个问题吗? Is there a simpler, easier way of using C++ OpenCV code in C#?
在C#中使用C ++ OpenCV代码有一种更简单,更简单的方法吗? I don't want to use Emgu or any other wrapper, my image processing code has to be in C++.
我不想使用Emgu或任何其他包装器,我的图像处理代码必须使用C ++。
How I solved the problem with opencv using visual studio 2012: 我如何使用visual studio 2012解决opencv的问题:
Remark A: I can assure that this solution worked. 备注A:我可以保证这个解决方案有效。 I used features like pattern detection and camshift with opencv 2.4.2.
我使用了opencv 2.4.2等模式检测和camshift等功能。
Remark B: Another topic is how exactly marshalling should be made. 备注B:另一个主题是如何进行准确的编组。 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.
在简单数据类型的情况下,毫无疑问使用像UInt32等c ++ / cli数据类型。但问题是,如果你想传递更复杂的对象,如cv :: Mat,它们在c ++ / cli中没有直接等价的类型。 In that case, I made simplified version of such classes on c++/cli side.
在那种情况下,我在c ++ / cli方面制作了这类的简化版本。
Remark C: Don't mess architecture in different projects. 备注C:不要在不同的项目中混淆架构。 If you are using eg x86, be consequent in all projects.
如果您使用的是x86,则可以在所有项目中使用。
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. 备注D:实际上,在c#中使用c ++代码的问题有两个解决方案:我描述的那个和使用动态动态编组从c#托管代码直接调用c ++非托管代码。 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).
有两个主要的缺点:即时编组需要时间,你不知道复杂数据类型之间的确切做法(即,与int或字符串不同的一切)。 So c++/cli it is really a good option because you are able to mix managed and unmanaged code.
所以c ++ / cli它真的是一个很好的选择,因为你可以混合托管和非托管代码。
Remark E: This solution is general, it does not count only in opencv. 备注E:此解决方案是通用的,它不仅仅在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.
我成功地将这个制作c ++ / cli包装器用于旋转阶段(电机设备),它只有c ++驱动程序并在c#代码中使用了这些驱动程序。
Regarding Remark C: Use a dependency walker like Depends ( http://www.dependencywalker.com/ ) to see which dependencies are not consistent. 关于备注C:使用Depends( http://www.dependencywalker.com/ )之类的依赖性walker来查看哪些依赖项不一致。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.