1. Flutter
  2. Capturing an Image for OCR

Flutter

Capturing an Image for OCR

Vision SDK provides a simple way to capture images for further processing like OCR or just for saving in storage. All you need to do is follow the setup steps below.

Capture Image

Using the following code, you can get image as a Uint8List byte array in onImageCaptured callback, along with a list of ScannedCodeResult. The list will contain any barcodes that were available in that image. The list could be empty, if there were no barcodes found.

        class VisionSDKStatelessWidget extends StatelessWidget {
  const VisionSDKStatelessWidget({super.key, required this.listener});

  final PluginToFlutterCommunicator listener;

  @override
  Widget build(BuildContext context) {
    return VisionCameraWidget(
      listener: listener,
      onViewCreated: (FlutterToPluginCommunicator sender) {
        sender.setCaptureModeOCR();
        sender.startCamera();
      },
    );
  }
}

class Listener implements PluginToFlutterCommunicator {
  @override
  void onImageCaptured(Uint8List byteArrayImage, List<ScannedCodeResult> scannedCodeResults) {
    
  }
}

      

Note that, once onCodesReceived or onImageCaptured callbacks are called, VisionSDK will stop analyzing camera feed for text or barcodes/QR codes. This is to prevent extra processing and battery consumption. When client wants to start analyzing camera feed again, after consuming the results of previous scan, client needs to call the following function:

        sender.rescan()