Pranav Vempati
Pranav Vempati

Reputation: 569

Firebase Vision analogue in Google MLKit

Firebase MLKit on iOS supported a Vision class, primarily used to obtain a Firebase vision object in the following manner:

let vision = Vision.vision()

A VisionTextRecognizer instance from the Firebase MLKit API (which also seemingly has no analogue in the Google-MLKit API) can be obtained from the vision object like so:

var recognizer : VisionTextRecognizer = vision.OnDeviceTextRecognizer()

Given the Firebase Mlkit API is deprecated, I'm looking to move the project to the Google-MlKit API and update the codebase accordingly. The migration guide provides a reference to the renamed and functionally equivalent facilities in GoogleMLKit. I cannot find an equivalent for the deprecated Vision and VisionTextRecognizer classes - are these supported in GoogleMLKit?

Upvotes: 0

Views: 378

Answers (2)

Pranav Vempati
Pranav Vempati

Reputation: 569

As an addendum to the accepted answer, you might encounter the following after an upgrade to MLKit.

If your project relies on a specific version of Protocol Buffers during the upgrade, MLKit might demand a newer version, or compilation errors may point to a missing file in the Protocol buffer headers. It turns out that simply upgrading the relevant pods did not suffice in my case, and I explicitly had to pull in Protobuf-C++ in the Podfile.

Upvotes: 0

Dong Chen
Dong Chen

Reputation: 882

There is no Vision class in the new Google ML Kit, as mentioned in the Migration Guide:

Domain entry point classes (Vision, NaturalLanguage) no longer exist. They have been replaced by task specific classes. Replace calls to their various factory methods for getting detectors with direct calls to each detector's factory method.


To get an instance of the on-device text recognizer, you can simply do the following:

var recognizer : TextRecognizer = TextRecognizer.textRecognizer()

Or

let recognizer = TextRecognizer.textRecognizer()

Or chain it directly into the inference call:

var recognizedText: Text
do {
  recognizedText = try TextRecognizer.textRecognizer().results(in: image)
} catch let error {
  // Handle the error
}

See a working example in ML Kit quickstart vision sample app.

Upvotes: 1

Related Questions