cropImage function
Implementation
Future<File?> cropImage(File imageFile, DetectedObject object) async {
final parse = await img.decodeImageFile(imageFile.absolute.path);
if (parse == null) return null;
final result = img.copyCrop(
parse,
x: object.boundingBox.left.toInt(),
y: object.boundingBox.top.toInt(),
width: (object.boundingBox.right - object.boundingBox.left).toInt(),
height: (object.boundingBox.bottom - object.boundingBox.top).toInt(),
);
List<int> cropByte = [];
cropByte = img.encodeJpg(result);
final File imageFileCrop = await File(imageFile.absolute.path).writeAsBytes(cropByte);
return imageFileCrop;
}