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++
- Android
- Objective-C
- Swift
const result = await cvRouter.capture(file, "ReadSingleBarcode"); for (let item of result.items) { if (item.type === Dynamsoft.Core.EnumCapturedResultItemType.CRIT_BARCODE) { console.log("confidence: " + item.confidence); console.log("angle: " + item.angle); } }
CCaptureVisionRouter* cvr = new CCaptureVisionRouter; CCapturedResult* result = cvr->Capture("IMAGE-FILE-PATH", CPresetTemplate::PT_READ_BARCODES); if (result->GetErrorCode() != 0) { cout << "Error: " << result->GetErrorCode() << "," << result->GetErrorString() << endl; } int capturedResultItemCount = result->GetItemsCount(); for (int j = 0; j < capturedResultItemCount; j++) { const CCapturedResultItem* capturedResultItem = result->GetItem(j); CapturedResultItemType type = capturedResultItem->GetType(); if (type == CapturedResultItemType::CRIT_BARCODE) { const CBarcodeResultItem* barcodeResultItem = dynamic_cast<const CBarcodeResultItem*> (capturedResultItem); cout << "Result " << j + 1 << endl; cout << "Confidence: " << barcodeResultItem->GetConfidence() << endl; cout << "Angle: " << barcodeResultItem->GetAngle() << endl; } } // more process here
public void onDecodedBarcodesReceived(DecodedBarcodesResult result) { if (result != null){ BarcodeResultItem[] items = result.getItems(); for (int i=0; i < items.length; i++){ BarcodeResultItem item = items[i]; Log.i("DecodedBarcodes", "onDecodedBarcodesReceived: This is the number "+i+" barcode"); int confidence = item.getConfidence(); Log.i("DecodedBarcodes", "The confidence of the barcode is: "+confidence); int angle = item.getAngle(); Log.i("DecodedBarcodes", "The rotation angle of the barcode is: "+angle); } } }
- (void)onDecodedBarcodesReceived:(DSDecodedBarcodesResult *)result { if (result.items.count > 0) { for (DSBarcodeResultItem *item in result.items) { NSInteger confidence = item.confidence; NSInteger angle = item.angle; } } }
func onDecodedBarcodesReceived(_ result: DecodedBarcodesResult) { if let items = result.items, items.count > 0 { for item in items { let confidence = item.confidence let angle = item.angle } } }