Set Recognition Quality and Speed
When working with barcodes in applications, optimizing recognition quality and speed is essential. The RecognitionMode
setting in the Aspose.BarCode.Cloud SDK for Dart offers a way to adjust these parameters, making it possible to prioritize either quality or speed during barcode recognition.
Recognition Mode Options
The RecognitionMode
parameter can be set to the following values to control the recognition process:
- Fast: Optimizes for speed but may lower the accuracy slightly. Minimal recognition timeout.
- Normal: Balances speed and quality, suitable for most cases. Medium recognition timeout.
- Excellent: Prioritizes accuracy over speed, ideal for challenging barcode images. Maximum recognition timeout.
Usage in API Requests
The RecognizeApi
interface provides methods to recognize barcodes from files using different HTTP request types. Below are the available methods:
recognize
: Recognizes barcode from a file on the server using aGET
request.recognizeBase64
: Recognizes barcode from a file provided in the request body using aPOST
request with JSON or XML format.recognizeMultipart
: Recognizes barcode from a file provided in the request body using aPOST
request withmultipart/form-data
.
Example Implementations
Example 1: Using recognize
import 'dart:io';
import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';
Configuration makeConfiguration() {
final jwtToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
if (jwtToken != null) {
return Configuration(accessToken: jwtToken);
} else {
return Configuration(
clientId: "Client Id from https://dashboard.aspose.cloud/applications",
clientSecret:
"Client Secret from https://dashboard.aspose.cloud/applications",
);
}
}
Future<void> main() async {
final config = makeConfiguration();
final recognizeApi = RecognizeApi(ApiClient(config));
final result = await recognizeApi.recognize(
DecodeBarcodeType.QR,
"https://products.aspose.app/barcode/scan/img/how-to/scan/step2.png",
recognitionMode: RecognitionMode.Fast,
recognitionImageKind: RecognitionImageKind.Photo,
);
print("File recognized, result: '${result.barcodes[0].barcodeValue}'");
}
Example 2: Using recognizeBase64
import 'dart:convert';
import 'dart:io';
import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';
Configuration makeConfiguration() {
final jwtToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
if (jwtToken != null) {
return Configuration(accessToken: jwtToken);
} else {
return Configuration(
clientId: "Client Id from https://dashboard.aspose.cloud/applications",
clientSecret:
"Client Secret from https://dashboard.aspose.cloud/applications",
);
}
}
Future<void> main() async {
final config = makeConfiguration();
final recognizeApi = RecognizeApi(ApiClient(config));
final fileName =
File("${Directory.current.path}${Platform.pathSeparator}Pdf417.png")
.absolute
.path;
final fileBytes = File(fileName).readAsBytesSync();
final imageBase64 = base64Encode(fileBytes);
final recognizeBase64Request = RecognizeBase64Request(
[DecodeBarcodeType.Pdf417],
imageBase64,
);
final BarcodeResponseList result =
await recognizeApi.recognizeBase64(recognizeBase64Request);
print(
"File '$fileName' recognized, result: '${result.barcodes[0].barcodeValue}'");
}
Example 3: Using recognizeMultipart
import 'dart:io';
import 'package:aspose_barcode_cloud/aspose_barcode_cloud.dart';
Configuration makeConfiguration() {
final jwtToken = Platform.environment['TEST_CONFIGURATION_ACCESS_TOKEN'];
if (jwtToken != null) {
return Configuration(accessToken: jwtToken);
} else {
return Configuration(
clientId: "Client Id from https://dashboard.aspose.cloud/applications",
clientSecret:
"Client Secret from https://dashboard.aspose.cloud/applications",
);
}
}
Future<void> main() async {
final config = makeConfiguration();
final recognizeApi = RecognizeApi(ApiClient(config));
final file =
await File("${Directory.current.path}${Platform.pathSeparator}aztec.png")
.readAsBytes();
final BarcodeResponseList result =
await recognizeApi.recognizeMultipart(DecodeBarcodeType.Aztec, file);
print("File recognized, result: '${result.barcodes[0].barcodeValue}'");
}
Conclusion
Choosing the appropriate RecognitionMode
is essential in tailoring barcode recognition to the specific needs of your application. Whether prioritizing speed or accuracy, the examples provided demonstrate how to use the RecognizeApi
interface to adjust settings for optimal performance. By fine-tuning RecognitionMode
and RecognitionImageKind
, you can enhance both efficiency and accuracy, making your barcode processing solution robust across various use cases.