[Huawei Developers] Freemind R:
More information like this, you can visit HUAWEI Developer Forum​

Introduction

The Huawei Scan Kit offers versatile scanning, decoding, and generation capacities for bar code and QR code, enabling developers to quickly create the scans for QR code in apps.

Huawei can automatically detect and amplify long-distance or smaller scan codes via its long-range accumulation in the computer vision sector and automate the recognition of normal, complex barcode (example: reflection) scanning (such as dark light, smudge, blur and cylinder) scanning services. Scan Kit improves the performance rate and user experience of QR scanning code.

Zxing is a common third-party open-source SDK, it allows an Android device with imaging hardware (a built-in camera) to scan barcodes or 2-D graphical barcodes and retrieve the data encoded. It only carries out simple QR-code scanning operations and does not support complex scanning conditions, including high light, bend and deformation. However, the optimization effect is still not ideal, and many people will spend a lot of time on the optimization.

Let us now evaluate the Zxing and the Huawei HMS scan kit capabilities:

Note

In this article, I have scanned the code for 5 times and taken the best time captured.

Results may vary from device to device. I have used Huawei Y7p device for scanning, maintained similar condition for both HMS scan and Zxing.

Normal Scanning

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828081844.50515934104250568916890210843170:50510908090904:2800:EDA37F659E49E8FE1281D35564F47BAC1B54CEB1832F6D0EF1692AEF1B3F24E9.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828081844.50515934104250568916890210843170:50510908090904:2800:EDA37F659E49E8FE1281D35564F47BAC1B54CEB1832F6D0EF1692AEF1B3F24E9.png[/IMG]

When simple QR code is scanned from normal distance (around half feet), we have captured the time for decoding the code .

Huawei Scan kit took 0.68 seconds.

Zxing scanner took 1.38 seconds.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828082333.12798388675084585605964259525763:50510908090904:2800:E86A500FF532C162B37C39EF259055D24A11F5E02D158593353A71410C629BEB.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828082333.12798388675084585605964259525763:50510908090904:2800:E86A500FF532C162B37C39EF259055D24A11F5E02D158593353A71410C629BEB.gif[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828082413.77605897266514129529169682787082:50510908092134:2800:2F90542809B829C98184B5CC5063AA1311AE9E756A6BE0399FAF2D20304DDBF2.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828082413.77605897266514129529169682787082:50510908092134:2800:2F90542809B829C98184B5CC5063AA1311AE9E756A6BE0399FAF2D20304DDBF2.gif[/IMG]

Result : HMS Scan kit wins

Scanning QR code at an angle

Let us scan the QR code at an angle more than 45 degrees from line of sight.

Huawei Scan kit took 0.657 seconds.

Zxing scanner took 1.27 seconds.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828082649.00728566237531727718066427759148:50510908090904:2800:8E9F1DEDBD07FBD07D23BB1F65819F2AF01BDA00D84140F23C43761FAB6A6B11.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828082649.00728566237531727718066427759148:50510908090904:2800:8E9F1DEDBD07FBD07D23BB1F65819F2AF01BDA00D84140F23C43761FAB6A6B11.gif[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828082713.36652563086912842573370614503818:50510908090904:2800:FB407D2F06108A6AAD6164DCEF839ADA8DF7864B8492A145C75FAF8446E4DA47.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828082713.36652563086912842573370614503818:50510908090904:2800:FB407D2F06108A6AAD6164DCEF839ADA8DF7864B8492A145C75FAF8446E4DA47.gif[/IMG]

However, when we tried to capture at an angle more than 60 degrees, Zxing was not able to scan the code.

Result: HMS Scan kit wins

Scanning Complex Code:

Complex QR or bar code is too dense to decode. Let us see effectiveness of both the scanners.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828085808.54632686033578321884028481752467:50510908090904:2800:E2E4DFB9B642F8DDA3E15D368403F0DB068E5397B2ECB29F298DCF88686F8AF7.png"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828085808.54632686033578321884028481752467:50510908090904:2800:E2E4DFB9B642F8DDA3E15D368403F0DB068E5397B2ECB29F298DCF88686F8AF7.png[/IMG]

Huawei scanner took 2.214 seconds when scanned from ideal distance (1.5 feet). However, if QR code is scanned from close distance it took 10.237 seconds. When QR code is scanned from distance more that 3 to 4 feet, it took 23.105 seconds.

ZXING scan took 19.10 seconds when scanned from ideal distance (1.5 feet). When scanned from too close or away from QR code, it was not able to able to scan it.

Result: HMS Scan kit wins.

Scanning code from long distance

Since Zxing does not have an automatic zoom-in optimisation, it is difficult to recognize code when the code is less than 20% of the frame.

The HMS Scan Kit has a pre-detection feature that can automatically amplify a long distance QR code even if the QR code cannot be detected by naked eyes.

HMS scan took 1.391 sec to detect when QR code is more 8 feet away.

Zxing failed to detect the code.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828091142.28503847148506399721739564589198:50510908090904:2800:70EF58FD1A2ED3D6CBC5A8C61F4BE8FC475095E4A2DCC2FE0BBF8EDA7FCAC271.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828091142.28503847148506399721739564589198:50510908090904:2800:70EF58FD1A2ED3D6CBC5A8C61F4BE8FC475095E4A2DCC2FE0BBF8EDA7FCAC271.gif[/IMG]

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828091741.93817550208337349120447939771438:50510908090904:2800:BB5AE57B0CAE0A970A592A8156CB2C9039AA6C42BB9A65F8C74EFDA1E884D5FE.gif"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/001/940/588/2640091000001940588.20200828091741.93817550208337349120447939771438:50510908090904:2800:BB5AE57B0CAE0A970A592A8156CB2C9039AA6C42BB9A65F8C74EFDA1E884D5FE.gif[/IMG]

Result: HMS Scan kit wins

Implementation of HMS scan kit:

Prerequisite

Java JDK 1.8 or higher is recommended.

Android Studio is recommended.

Before developing an app, you will need to register as a HUAWEI developer. Refer to Register a HUAWEI ID.

Integrating app gallery connect SDK. Refer to AppGallery Connect Service Getting Started.

Development

1. Add the HMS scan kit dependencies in module-level build.gradle

implementation 'com.huawei.hms:scan:1.1.3.301'

2. To launch HMS default scanner

ScanUtil.startScan(this, REQUEST_CODE_SCAN_ONE, new HmsScanAnalyzerOptions.Creator().create());

3. Getting the scan result

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK || data == null) {
return;
}

endTime = System.currentTimeMillis();

//Default View
if (requestCode == REQUEST_CODE_SCAN_ONE) {
HmsScan obj = data.getParcelableExtra(ScanUtil.RESULT);

if (obj != null) {

tvTimer.setText(String.valueOf((endTime-startTime) /1 000) + " sec");
}

}

Implementation of Zxing scan:

1. Add the Zxing scan dependencies in module-level build.gradle

implementation 'com.journeyapps:zxing-android-embedded:3.4.0'

2. To initialize QR code scanner

qrScan = new IntentIntegrator(this);

3. To launch the scanner

//initiating the qr code scan
qrScan.initiateScan();

4. Getting the scan result

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK || data == null) {
return;
}
endTime = System.currentTimeMillis();

IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);

tvTimer.setText(String.valueOf((endTime-startTime)/1000) + " sec");

if (result != null) {
//if qrcode has nothing in it
if (result.getContents() == null) {
Toast.makeText(this, "Result Not Found", Toast.LENGTH_LONG).show();
} else {
//if qr contains data
try {
//converting the data to json
JSONObject obj = new JSONObject(result.getContents());

} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
}