3

I would like to create a mobile app using Xamarin for both iOS and Android, and I would like to call a few OpenCV functions (for example, contour detection and perspective transform).

I generally understand the process of calling C++ functions from C#, but I don't know how to do this from the OpenCV binaries provided for iOS and Android. There's a fork of OpenCvSharp that supports Xamarin.Android, but it doesn't support Xamarin.iOS.

I'm not looking to port the entire OpenCV library to Xamarin (yet). I'm just looking to call a very small subset of functions.

1 Answer 1

3

For iOS you should provide binding for Objective-C yourself. Here is an example of how to do, code is NOT mine.

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());
2
  • I finally got around to doing this and after hours of trying it worked. However, an issue with this approach (which I've asked about here) is that my app ends up being >300 MB in size because opencv2.framework is that large.
    – redcurry
    Commented Feb 17, 2019 at 1:40
  • I think you need to change the [Export("version:")] to [Export("version")], else it crashes coz it expects parameters to be passed.
    – vin
    Commented Jun 24, 2020 at 7:28

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.