2

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.

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the reply. Probably option 1 would be feasible or I might go to option 2.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.