how to call opencv c++ codes by xamarin c# code?

钢 屈 371 Reputation points
2021-05-06T14:10:59.097+00:00

I have some opencv c++ codes.
I want to call opencv c++ codes at xamarin c# codes.
How should I do?

Developer technologies .NET Xamarin
Developer technologies C++
0 comments No comments
{count} votes

Accepted answer
  1. JessieZhang-MSFT 7,716 Reputation points Microsoft External Staff
    2021-05-07T01:49:52.007+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    Since the opencv code has to be compiled to native code for each platform, so we have to have a separate library for each platform.

    In IOS,you can create a static framework using Xcode and write opencv functions using C++. Then you need to bind (map) the static framework to Xamarin using a binding project.

    Here is an example of how to do: https://github.com/trinnguyen/xamarin.ios-opencv .

    Here is an article describing the steps: https://chamoda.com/how-to-use-opencv-with-xamarin-ios/

    [BaseType(typeof(NSObject))]  
    interface OpenCV  
    {  
      
        [Export("version:")]  
        NSString Version();  
      
    }  
      
    private OpenCV OpenCV = new OpenCV();  
      
    Console.WriteLine(OpenCV.Version());  
    

    Here is a similar thread, you can check :https://stackoverflow.com/questions/13493149/calling-opencv-c-code-in-c-sharp-application

    You can also check microsoft tutorial here: Bring Some C++ to Xamarin Apps | The Xamarin Show

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.