Reputation:
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.
Upvotes: 2
Views: 853
Reputation: 14011
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#.
Upvotes: 0
Reputation: 35126
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
Upvotes: 2