makePredictionWithModule method
Future<void>
makePredictionWithModule({
- required ModelClass modelClass,
- required ModelSize modelSize,
- required Uint8List byteArrayImage,
- required List<
ScannedCodeResult> barcodes,
Performs OCR prediction using models loaded via ModelManager.
This method allows dynamic switching between different OCRModules without creating new OnDeviceOCRManager instances. Use this when models were loaded using the new ModelManager API.
modelClass - The model class to use for prediction
modelSize - The model size to use for prediction
byteArrayImage - The image to perform OCR on
barcodes - List of detected barcodes (can be empty)
Returns the OCR result via OnDeviceOCRManagerListener.onOnDeviceOCRResult.
Example:
// First load the model via ModelManager
await modelManager.loadModel(
module: OCRModule(modelClass: ModelClass.shippingLabel, modelSize: ModelSize.large),
apiKey: apiKey,
);
// Then make prediction with explicit module
await ocrManager.makePredictionWithModule(
modelClass: ModelClass.shippingLabel,
modelSize: ModelSize.large,
byteArrayImage: imageBytes,
barcodes: detectedBarcodes,
);
Implementation
Future<void> makePredictionWithModule({
required ModelClass modelClass,
required ModelSize modelSize,
required Uint8List byteArrayImage,
required List<ScannedCodeResult> barcodes,
}) async {
await _channel.invokeMethod('makePredictionWithModule', {
'modelClass': switch (modelClass) {
ModelClass.shippingLabel => 1,
ModelClass.billOfLading => 2,
ModelClass.itemLabel => 3,
ModelClass.documentClassification => 4,
},
'modelSize': switch (modelSize) {
ModelSize.nano => 1,
ModelSize.micro => 2,
ModelSize.small => 3,
ModelSize.medium => 4,
ModelSize.large => 5,
ModelSize.xlarge => 6,
},
'byteArrayImage': byteArrayImage,
'barcodes': barcodes.map((item) => item.toMap()).toList(),
});
}