Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
This documentation provides an overview of how to use the Aspose.BarCode.Cloud SDK for PHP to set the type of barcode image for recognition. Setting the correct RecognitionImageKind is essential for optimizing the recognition process and ensuring high accuracy, particularly when dealing with diverse barcode types or varying image qualities.
The Aspose.BarCode.Cloud SDK for PHP allows for flexible barcode scanning and recognition from different image sources. One of the features in this API is the ability to specify the RecognitionImageKind based on the source of the barcode image. This improves accuracy by guiding the recognition engine with additional context about the image.
The RecognitionImageKind parameter is optional and can be set in several requests within the API. It is available in the following request classes:
recognizerecognizeBase64recognizeMultipartThe RecognitionImageKind enum provides three options:
Below are examples of using the RecognitionImageKind setting with various API methods.
recognizeThe recognize method allows for barcode recognition using a GET request.
<?php
use Aspose\BarCode\Configuration;
use Aspose\BarCode\RecognizeApi;
use Aspose\BarCode\Model\{DecodeBarcodeType, RecognitionImageKind};
use Aspose\BarCode\Requests\RecognizeRequestWrapper;
require_once 'vendor/autoload.php';
function makeConfiguration()
{
$config = new Configuration();
$envToken = getenv('TEST_CONFIGURATION_ACCESS_TOKEN');
if (empty($envToken)) {
$config->setClientId("Client Id from https://dashboard.aspose.cloud/applications");
$config->setClientSecret("Client Secret from https://dashboard.aspose.cloud/applications");
} else {
$config->setAccessToken($envToken);
}
return $config;
}
function main()
{
$recognizeApi = new RecognizeApi(null, makeConfiguration());
$request = new RecognizeRequestWrapper(DecodeBarcodeType::QR, "https://products.aspose.app/barcode/scan/img/how-to/scan/step2.png");
$request->image_kind = RecognitionImageKind::Photo;
$result = $recognizeApi->recognize($request);
echo sprintf("File '%s' recognized, result: '%s'\n", "https://products.aspose.app/barcode/scan/img/how-to/scan/step2.png", $result->getBarcodes()[0]->getBarcodeValue());
}
main();
recognizeBase64For recognition using a POST request with JSON or XML, use recognizeBase64:
<?php
use Aspose\BarCode\Configuration;
use Aspose\BarCode\RecognizeApi;
use Aspose\BarCode\Model\{DecodeBarcodeType, RecognizeBase64Request, RecognitionImageKind};
use Aspose\BarCode\Requests\RecognizeBase64RequestWrapper;
require_once 'vendor/autoload.php';
function makeConfiguration()
{
$config = new Configuration();
$envToken = getenv('TEST_CONFIGURATION_ACCESS_TOKEN');
if (empty($envToken)) {
$config->setClientId("Client Id from https://dashboard.aspose.cloud/applications");
$config->setClientSecret("Client Secret from https://dashboard.aspose.cloud/applications");
} else {
$config->setAccessToken($envToken);
}
return $config;
}
function main()
{
$recognizeApi = new RecognizeApi(null, makeConfiguration());
$fileName = __DIR__ . '/../testdata/QR_and_Code128.png';
$imageBytes = file_get_contents($fileName);
$imageBase64 = base64_encode($imageBytes);
$base64Request = new RecognizeBase64Request([
'barcode_types' => [DecodeBarcodeType::Aztec, DecodeBarcodeType::QR],
'file_base64' => $imageBase64,
'image_kind' => RecognitionImageKind::ScannedDocument
]);
$request = new RecognizeBase64RequestWrapper($base64Request);
$result = $recognizeApi->recognizeBase64($request);
echo sprintf(
"File '%s' recognized, results: value: '%s', type: %s\n",
$fileName,
$result->getBarcodes()[0]->getBarcodeValue(),
$result->getBarcodes()[0]->getType()
);
}
main();
recognizeMultipartFor file uploads with multipart form data, recognizeMultipart is used:
<?php
use Aspose\BarCode\Configuration;
use Aspose\BarCode\RecognizeApi;
use Aspose\BarCode\Model\{DecodeBarcodeType, RecognitionImageKind};
use Aspose\BarCode\Requests\RecognizeMultipartRequestWrapper;
require_once 'vendor/autoload.php';
function makeConfiguration()
{
$config = new Configuration();
$envToken = getenv('TEST_CONFIGURATION_ACCESS_TOKEN');
if (empty($envToken)) {
$config->setClientId("Client Id from https://dashboard.aspose.cloud/applications");
$config->setClientSecret("Client Secret from https://dashboard.aspose.cloud/applications");
} else {
$config->setAccessToken($envToken);
}
return $config;
}
function main()
{
$recognizeApi = new RecognizeApi(null, makeConfiguration());
$fileName = __DIR__ . '/../testdata/Pdf417.png';
$file = new SplFileObject($fileName, 'rb');
$request = new RecognizeMultipartRequestWrapper(DecodeBarcodeType::MostCommonlyUsed, $file);
$request->image_kind = RecognitionImageKind::ClearImage;
$result = $recognizeApi->recognizeMultipart($request);
echo sprintf("File '%s' recognized, result: '%s'\n", $fileName, $result->getBarcodes()[0]->getBarcodeValue());
}
main();
The Barcode Recognition API provides flexible options to recognize barcodes in various formats including photos, scanned documents, and clear images. By setting the RecognitionImageKind, developers can enhance recognition accuracy, particularly when working with diverse image sources. Supported barcode types include popular formats like QR Code, Aztec, Pdf417, and many more. The API allows integration with GET and POST methods, supporting JSON, XML, and multipart form data formats.
For high accuracy, configure the RecognitionImageKind parameter based on your image source. This small adjustment can lead to faster processing times and better recognition results across all supported barcode types.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.