Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Convert to Black & White" function - it is far to aggressive, smallest shadow is converted to all black #13

Open
AhabLives opened this issue Jan 10, 2022 · 0 comments

Comments

@AhabLives
Copy link

AhabLives commented Jan 10, 2022

I am using the flutter package document_scanner_flutter 0.2.5. I would like to edit the "Convert to Black & White" function - it is far to aggressive, any shadow on document is converted to all black. I can not seem to find this exact function with in the package.
I would like to update the "B & W" function with code below (But I can not seem to find it).
Any help you could provide in decreasing the exposure or aggressive shadow conversion in B & W - would be greatly appreciated.


 static Future<Uint8List?> toBlackAndWhite(Uint8List picture) async {
    final appDir = await getTemporaryDirectory();
    File pictureFile = File('${appDir.path}/image_open.jpg');
    await pictureFile.writeAsBytes(picture);

    var res = await Cv2.gaussianBlur(
      pathFrom: CVPathFrom.GALLERY_CAMERA,
      pathString: pictureFile.path,
      kernelSize: [3, 3],
      sigmaX: 0,
    );

    if (res == null) return null;
    await pictureFile.writeAsBytes(res);

    res = await Cv2.adaptiveThreshold(
      pathFrom: CVPathFrom.GALLERY_CAMERA,
      pathString: pictureFile.path,
      maxValue: 255,
      adaptiveMethod: Cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
      thresholdType: Cv2.THRESH_BINARY,
      blockSize: 7,
      constantValue: 2,
    );

    if (res == null) return null;
    await pictureFile.writeAsBytes(res);

    res = await Cv2.medianBlur(
      pathFrom: CVPathFrom.GALLERY_CAMERA,
      pathString: pictureFile.path,
      kernelSize: 3,
    );

    return res;
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant