从 OpenCV /C++ 传回图像到 .NET C#
我必须编写一些代码来用 C# 读回在 OpenCV/C++ 中处理的图像。 C# 不理解 OpenCV 图像格式,因此我必须先进行某种转换,然后才能在 .NET 中编写包装器。将图像从 C 返回到 C# 的最佳方法是什么?也就是说,我应该公开 C# 中可读的原始字节和图像尺寸,还是有更好的方法?
感谢您的回复。
I have to write some code to read back an image in C# which is processed in OpenCV/C++. C# does not understand OpenCV image formats so I have to do some sort of conversions before I can write a wrapper in .NET. What would be the best approach to return the image from C to C#? That is, should I expose the raw bytes and image dimensions that would be readable in C# or is there any better approach?
Thanks for the reply.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编写 C++/CLI 包装器,用于创建位图并将其返回到 .NET 客户端。
或者
如果您不希望图像大于几个 MB 并且没有严格的性能要求。如果是并行调用,那么您也可以通过将图像保存到内存位图来返回字节*
,或者
如果在您的场景中有意义,那么调用者还可以指定处理后可以保存图像的文件路径。然而,这不太可重用。
或者
您可以将图像写入 ILockBytes 并返回指向它的指针。 .NET 客户端可以从中读取。这是 Windows 特定的
Write a C++/CLI wrapper that creates a Bitmap and returns it to .NET client.
OR
If you don't expect image to be larger than few MBs and there are no strict performance requirements in terms of no. of parallel calls then you might as well return the byte* by saving the image to an inmemory bitmap
OR
If it makes sense in your scenario then the caller can also specify a file path where the image can be saved after processing. This is however not very reusable.
OR
You can write the image to ILockBytes and return pointer to that. .NET client can read from that. This is Windows specific
或者,如果您只想专门使用 C#,则应该查看 EmguCV。他们已经封装了大部分库以便与 C# 一起使用。
Or, if you just wanted to use C# exclusively, you should check out EmguCV. They have wrapped most of the library for use with C#.