How to Get Barcode Confidence and Rotation Angle
This article offers two examples about how to get result confidence and barcode rotation angle.
Barcode Confidence
The score of recognition confidence could measure the reliability of a recognized result. The higher the score, the more precise the results are.
Barcode Rotation Angle
Dynamsoft Barcode Reader SDK is able to detect barcodes at all angles. The SDK is also able to return the angles of the barcodes decoded.
The following illustrations will show how the angle is calculated for different barcode types:
-
OneD Barcode
-
QR Code
-
Data Matrix
-
Aztec
-
Maxicode
Code Snippet for Getting Confidence and Angle
The following code snippet shows how to get the confidence and rotation angle of the barcode result:
- JavaScript
- C
- C++
- C#
- Java
- Android
- Objective-C
- Swift
- Python
(async() => { let scanner = await Dynamsoft.DBR.BarcodeScanner.createInstance(); scanner.onUniqueRead = (txt, result) => { let conficence = result.localizationResult.confidence; let angle = result.localizationResult.angle; alert(txt); }; await scanner.show(); })();
int iRet = -1; char errorBuf[512]; TextResultArray* paryResult = NULL; iRet = DBR_InitLicense("YOUR-LICENSE-KEY", errorBuf, 512); if (iRet != DBR_OK) { printf("%s\n", errorBuf); } void* reader = DBR_CreateInstance(); DBR_DecodeFile(reader, "YOUR-IMAGE-FILE-PATH", ""); // Start decoding DBR_GetAllTextResults(reader, &paryResult); for (int iIndex = 0; iIndex < paryResult->resultsCount; iIndex++) { int confidence = paryResult->results[iIndex]->results[0]->confidence; int angle = paryResult->results[iIndex]->localizationResult->angle; //add further process with the confidence and angle } DBR_FreeTextResults(&paryResult); // Add further process
char errorBuf[512]; int iRet = -1; TextResultArray* paryResult = NULL; iRet = dynamsoft::dbr::CBarcodeReader::InitLicense("YOUR-LICENSE-KEY", errorBuf, 512); if (iRet != DBR_OK) { cout << errorBuf << endl; } CBarcodeReader* reader = new CBarcodeReader(); reader->DecodeFile("YOUR-IMAGE-FILE-PATH", ""); // Start decoding reader->GetAllTextResults(&paryResult); for (int iIndex = 0; iIndex < paryResult->resultsCount; iIndex++) { int confidence = paryResult->results[iIndex]->results[0]->confidence; int angle = paryResult->results[iIndex]->localizationResult->angle; //add further process with the confidence and angle } CBarcodeReader::FreeTextResults(&paryResult); // Add further process
string errorMsg; EnumErrorCode iRet = BarcodeReader.InitLicense("YOUR-LICENSE-KEY", out errorMsg); if (iRet != EnumErrorCode.DBR_SUCCESS) { Console.WriteLine(errorMsg); } BarcodeReader reader = new BarcodeReader(); TextResult[] result = reader.DecodeFile("YOUR-IMAGE-FILE-PATH", ""); // Start decoding for (int iIndex = 0; iIndex < result.Length; iIndex++) { int confidence = result[iIndex].Results[0].Confidence; int angle = result[iIndex].LocalizationResult.Angle; //add further process with the confidence and angle } // Add further process
BarcodeReader.initLicense("YOUR-LICENSE-KEY"); BarcodeReader reader = new BarcodeReader(); TextResult[] result = reader.decodeFile("YOUR-IMAGE-FILE-PATH", ""); // Start decoding for (int iIndex = 0; iIndex < result.length; iIndex++) { int confidence = result[iIndex].results[0].confidence; int angle = result[iIndex].localizationResult.angle; //add further process with the confidence and angle } // Add further process
BarcodeReader reader = new BarcodeReader(); TextResult[] result = reader.decodeFile("YOUR-IMAGE-FILE-PATH"); // Start decoding for (int iIndex = 0; iIndex < result.length; iIndex++) { int confidence = result[iIndex].results[0].confidence; int angle = result[iIndex].localizationResult.angle; //add further process with the confidence and angle } // Add further process
NSError *error = nil; DynamsoftBarcodeReader* reader = [[DynamsoftBarcodeReader alloc] init]; NSArray<iTextResult*>* result = [reader decodeFileWithName:@"YOUR-IMAGE-FILE-PATH" error:&err]; // Start decoding for (iTextResult* barcode in result) { int confidence = barcode.results[0].confidence; int angle = barcode.localizationResult.angle; //add further process with the confidence and angle } // Add further process
let reader = DynamsoftBarcodeReader.init() var result: [iTextResult]? = nil do { result = try reader.decodeFileWithName("YOUR-IMAGE-FILE-PATH") } catch let err { } // Start decoding for barcode in result ?? [] { let confidence = barcode.results[0].confidence let angle = barcode.localizationResult.angle //add further process with the confidence and angle } // Add further process
error = BarcodeReader.init_license("YOUR-LICENSE-KEY") if error[0] != EnumErrorCode.DBR_OK: print(error[1]) dbr = BarcodeReader() text_results = dbr.decode_file("YOUR-IMAGE-FILE-PATH") for result in text_results: confidence = result.extended_results[0].confidence angle = result.localization_result.angle #add further process with the confidence and angle