document_scanner_flutter
document_scanner_flutter copied to clipboard
"Convert to Black & White" function - it is far to aggressive, smallest shadow is converted to all black
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;
}