normalizeBuffer method

Future<NormalizedImage?> normalizeBuffer(
  1. Uint8List bytes,
  2. int width,
  3. int height,
  4. int stride,
  5. int format,
  6. dynamic points,
  7. int rotation,
  8. ColorMode color,
)

Normalize documents. bytes - bytes of the image. width - width of the image. height - height of the image. stride - stride of the image. format - format of the image. points - points of the document. Returns a NormalizedImage.

Implementation

Future<NormalizedImage?> normalizeBuffer(
    Uint8List bytes,
    int width,
    int height,
    int stride,
    int format,
    dynamic points,
    int rotation,
    ColorMode color) async {
  List<dynamic> jsOffsets = points.map((Offset offset) {
    return {'x': offset.dx, 'y': offset.dy};
  }).toList();

  NormalizedImage? image;
  if (_cvr != null) {
    try {
      dynamic rawSettings = await handleThenable(
          _cvr!.getSimplifiedSettings("NormalizeDocument_Default"));
      dynamic params = dartify(rawSettings);
      params['roi']['points'] = jsOffsets;
      params['roiMeasuredInPercentage'] = 0;
      params['documentSettings']['colourMode'] = color.index;

      await handleThenable(
          _cvr!.updateSettings("NormalizeDocument_Default", jsify(params)));
    } catch (e) {
      return image;
    }

    final dsImage = jsify({
      'bytes': bytes,
      'width': width,
      'height': height,
      'stride': stride,
      'format': format,
      'orientation': rotation
    });

    NormalizedResult normalizedResult = await handleThenable(
            _cvr!.capture(dsImage, "NormalizeDocument_Default"))
        as NormalizedResult;

    image = _createNormalizedImage(normalizedResult);
  }

  return image;
}