Issues with binding to Google Mobile Vision for iOS

Hi,

I try to do a binding for Google Mobile Vision for iOS. Everything look good and my project build with the binding.

But when i try to get a detector, i always get a null object.

I already try different dictionary (with and without any value).

var textDetector = GMVDetector.DetectorOfType(Constants.GMVDetectorTypeText, new NSDictionary());

Did anybody already done a binding with success for Google Mobile Vision ?
Did you have any idea what i can look for ?

Posts

  • RichardMasseRichardMasse USMember ✭✭

    For your information,

    My solution was to create a framework with cocoapods in Xcode (objectiv-c) and create a binding to this framework in my xamarin project.
    It's working great. I was able to do OCR and Barcode in iOS with Google Mobile Vision.

  • lalitbokdelalitbokde USMember

    Hi Rechard, Can you please elaborate the steps what you did ? or the link to refer ? I am getting the same issue var textDetector = GMVDetector.DetectorOfType(Constants.GMVDetectorTypeText, new NSDictionary()); with null value.
    but not getting the exact solution for it.

  • RichardMasseRichardMasse USMember ✭✭

    Hello,

    I don't have any link to refer. You have to create a framework in Xcode and include . You need to learn how to create a framework in xcode with objective-C. When your framework was done you can use it in Xamarin like other library (with binding project)

    For my need, i simply add this line of code in my framework.

    (NSString *)detectTextInImage:(UIImage *)image {

    textDetector = [GMVDetector detectorOfType:GMVDetectorTypeText options:nil];
    
    UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
    GMVImageOrientation orientation = [GMVUtility
                                       imageOrientationFromOrientation:deviceOrientation
                                       withCaptureDevicePosition:AVCaptureDevicePositionBack
                                       defaultDeviceOrientation: UIDeviceOrientationPortrait];
    NSDictionary *options = @{ GMVDetectorImageOrientation : @(orientation) };
    
    NSArray<GMVFeature *> *features = [textDetector featuresInImage:image options:options];
    
    //NSLog(@"Detected %lu textes.", (unsigned long)features.count);
    
    result = @"";
    
    for (GMVTextBlockFeature *textBlock in features) {
        //NSLog(@"lang: %@ value: %@", textBlock.language, textBlock.value);
    
        // For each text block, iterate over each line.
        for (GMVTextLineFeature *textLine in textBlock.lines) {
            //NSLog(@"lang: %@ value: %@", textLine.language, textLine.value);
    
            // For each line, iterate over each word.
            for (GMVTextElementFeature *textElement in textLine.elements) {
                NSLog(@"value: %@", textElement.value);
                result = [result stringByAppendingString: textElement.value];
            }
        }
    }
    
    return result;
    

    }

    • (NSString *)detectBarcodeInImage:(UIImage *)image {

      NSDictionary *options = @{ GMVDetectorTypeBarcode : @( GMVDetectorBarcodeFormatCode128 | GMVDetectorBarcodeFormatPDF417) };

      barcodeDetector = [GMVDetector detectorOfType:GMVDetectorTypeBarcode options:options];

      NSArray *features = [barcodeDetector featuresInImage:image options:nil];

      //NSLog(@Detected %lu textes., (unsigned long)features.count);

      result = @"";

      for (GMVBarcodeFeature *barcode in features) {
      //NSLog(@lang: %@ value: %@", textBlock.language, textBlock.value);
      result = [result stringByAppendingString: barcode.rawValue];
      }

      return result;
      }

Sign In or Register to comment.