Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Barcode detection with Xamarin / Vision framework

I want to detect bar codes using the new Vision API of iOS 11 with C# / Xamarin.

However, the VNDetectBarcodesRequest class of xamarin is abstract. Other request types, for example VNDetectRectanglesRequest are not. Is this part of the framework not implemented in Xamarin or am I missing something here?

Basically I want to adapt the rectangle detection sample (https://developer.xamarin.com/samples/monotouch/ios11/VisionRectangles/) to detect QR codes.

Thank you very much!

like image 234
Simon Avatar asked Feb 18 '26 10:02

Simon


1 Answers

Update: This bug is fixed, review xamarin-macios/issues/3140

That is a bug in the Xamarin generated bindings as it is correctly bound except for the incorrectly applied [Abstract] attribute.

Note: I created a Github issue: xamarin-macios/issues/3140

Since the binding otherwise is correct, you can work around by creating your own VNDetectBarcodesRequest subclass.

VNDetectBarcodesRequest Workaround

public class FixVNDetectBarcodesRequest : VNDetectBarcodesRequest
{
    public FixVNDetectBarcodesRequest(NSObjectFlag t) : base(t) { }

    public FixVNDetectBarcodesRequest(IntPtr handle) : base(handle) { }

    public FixVNDetectBarcodesRequest(VNRequestCompletionHandler completionHandler) : base(completionHandler) { }
}

Usage:

var detectBarcodesRequest = new FixVNDetectBarcodesRequest((request, error) =>
{
    //
});

Incorrect VNDetectBarcodesRequest binding:

[TV (11,0), Mac (10,13, onlyOn64: true), iOS (11,0)]
[Abstract]
[DisableDefaultCtor]
[BaseType (typeof (VNImageBasedRequest))]
interface VNDetectBarcodesRequest {

    [Export ("initWithCompletionHandler:")]
    [DesignatedInitializer]
    IntPtr Constructor ([NullAllowed] VNRequestCompletionHandler completionHandler);

    [Static]
    [Protected]
    [Export ("supportedSymbologies", ArgumentSemantic.Copy)]
    NSString [] WeakSupportedSymbologies { get; }

    [Static]
    [Wrap ("VNBarcodeSymbologyExtensions.GetValues (WeakSupportedSymbologies)")]
    VNBarcodeSymbology [] SupportedSymbologies { get; }

    [Protected]
    [Export ("symbologies", ArgumentSemantic.Copy)]
    NSString [] WeakSymbologies { get; set; }
}

re: vision.cs#L156

like image 154
SushiHangover Avatar answered Feb 19 '26 23:02

SushiHangover



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!