OCR Using Flutter

Jitesh Mohite
FlutterWorld
Published in
2 min readFeb 18, 2020

Optical character recognition is a process of conversion of typed images, printed text into the machine-encoded text, which means it will give us a text from images that contains the text.

This comes very handy with google mobile vision api, we just need to follow below steps

Step1: Add dependency in pubspec.yaml

dependencies:
flutter:
sdk: flutter
flutter_mobile_vision: ^0.1.3

Step 2:

For Android, you must do the following before you can use the plugin:

  • Add the camera permission to your AndroidManifest.xml
  • <uses-feature android:name="android.hardware.camera" />
  • <uses-permission android:name="android.permission.CAMERA" />
  • Add the OCR activity to your AndroidManifest.xml (after other activity nodes)
  • <activity android:name="io.github.edufolly.fluttermobilevision.ocr.OcrCaptureActivity" />

Note: You have to go manually at your application permission settings and then turn on camera permission, if you are doing this then only you can open camera from your application.

Step3: Write a code to open camera and take capture text. You will be getting text only when you tap on rectangular box which contains text inside.

Future<Null> _read() async {
List<OcrText> texts = [];
try {
texts = await FlutterMobileVision.read(
camera: _cameraOcr,
waitTap: true,
);

setState(() {
_textValue = texts[0].value; // Getting first text block....
});
} on Exception {
texts.add(new OcrText('Failed to recognize text.'));
}
}

Screenshots:

Rectangular box containing the text

Please go through complete Sample at Github:

Youtube Video:

--

--

Jitesh Mohite
FlutterWorld

I am technology enthusiastic, want to learn things quickly and dive deep inside it. I always believe in developing logical things which makes impact on end user