Answers to FAQs Related to HMS Core Scan Kit - Huawei Developers

Question 1: I wanna know the privacy policy of Scan Kit and the data it collects. Where can I obtain such information?​
Answer: Scan Kit's privacy policy and collected information are illustrated in its official "SDK Privacy and Security Statement" documents, which are separately specified for Android apps and iOS apps.
For Android apps, click here.
For iOS apps, click here.
Question 2: How to use Scan Kit so that my app can recognize multiple barcodes at the same time? If I adopt the multi-barcode recognition mode for my app, what should I do to make my app recognize specified barcodes? In this mode, can the coordinates of the recognized barcodes be returned by Scan Kit? Also, does this mode support auto zoom for a barcode?​
Answer:
(1) To use Scan Kit for simultaneous multi-barcode recognition:
a. Use the MultiProcessor mode for an Android project.
b. Use the Bitmap mode for an iOS project.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
(2) To make an app recognize specified barcodes when the multi-barcode recognition mode is adopted:
You are advised to download the sample code of Scan Kit, debug it, and then modify it.
Specifically speaking, multi-barcode recognition is related to the following classes: MainActivity, CommonActivity, ScanResultView, CameraOperation, and CommonHandler. Modify them as follows:
Call cameraOperation.stopPreview(); to stop barcode scanning as soon as a barcode is successfully recognized.
Add the code for obtaining the coordinates of the screen position of a user's touch to CommonActivity.
Check whether the obtained coordinates are within the range defined by the coordinates of the HmsScan object returned by Scan Kit upon barcode recognition success. If so, the barcode scanning UI will be directed to your custom UI, and the HmsScan object will be passed to the custom UI.
You can submit a ticket online for more support, if the answer above does not resolve your question.
(3) Whether the coordinates of the recognized barcodes can be returned by Scan Kit or not:
Yes. The barcode scanning result is obtained via a barcode scanning request, and the result is in the HmsScan structure. You can call HmsScan.getBorderRect to obtain the coordinates of the recognized barcodes.
(4) Whether the multi-barcode recognition mode supports auto zoom for a barcode or not:
No. The multi-barcode recognition mode does not provide this function. This is to avoid the recognition effect of other barcodes being compromised. If you still want your app to provide the zoom-in/out function, you can implement it by using a button or via user touch.
Question 3: Does Scan Kit support auto zoom-in for barcodes? If yes, does the kit allow auto zoom-in to be canceled?​
Answer: Scan Kit supports auto zoom-in, which is embedded in its Default View mode and Customized View mode. In either mode, auto zoom-in can be triggered when specific conditions are met, with zero additional configuration needed.
In Bitmap mode, when recognizing a barcode, Scan Kit would return a command for zoom ratio adjustment to your app. To know how, refer to step 4 in the Scanning Barcodes Using the Camera.
If you do not need the auto zoom-in function, you can select the MultiProcessor mode. It does not provide this function to prevent the recognition effect of other barcodes from being compromised.
Question 4: Does Scan Kit require any subscription fee or copyright authorization?​
Answer: No and no. Scan Kit is free to use.
Question 5. How to implement continuous scanning with Scan Kit?​
Answer:
Call Mode​Whether Support Continuous Scanning​How to Implement Continuous Scanning​Example​Default View modeNo//Customized ViewYesCall setContinuouslyScan. When the value is true (default value), scanning results will be returned without interruption.
When the value is false, scanning results will only be returned one by one, and the same barcode will be returned only once.remoteView = new RemoteView.Builder().setContext(this).
setContinuouslyScan(true).build();Bitmap modeYesDo not close the camera during barcode scanning to obtain frames one by one. Then, send a barcode scanning request to Scan Kit. You can determine how the request is sent./MultiProcessor modeYes
As the above table shows, Customized View supports continuous barcode scanning. Specifically speaking, you need to set setContinuouslyScan (true) during initialization of RemoteView. For details, see the API Reference for RemoteView.Builder.
Note that the sample code has the logic to close the scanning UI once a barcode is successfully recognized. Therefore, if you use the sample code to test the continuous scanning function, remember to disable this logic in the success callback of RemoteView, to prevent the scanning process from being interrupted.
Question 6: How to customize the barcode scanning UI?​
Answer: Barcode scanning UI customization is not supported by Default View but is supported by the Customized View, Bitmap, and MultiProcessor modes.
To know how to customize the UI, refer to the ScanResultView class and activity_defined.xml or activity_common.xml in the sample code of Scan Kit. You can make adjustments to the UI as required.
activity_defined.xml describes how to customize the UI in Customized View mode, and activity_common.xml tells how to customize the UI in Bitmap or MultiProcessor mode.
Question 7: How to obtain the following data of a successfully recognized barcode: barcode format, as well as the barcode image, barcode coordinates, and barcode corner point information?​
Answer: The prerequisite for obtaining barcode information is that the corresponding barcode is recognized. Scan Kit returns all the information about the recognized barcode in an HmsScan object via the listener for the barcode scanning result callback.
The information covers the barcode coordinates in the input image, original barcode data, barcode format, structured data, zoom ratio, and more.
For details, see Parsing Barcodes and HmsScan.
Question 8: How to make Scan Kit automatically change the language of my app? What countries/regions are supported by the kit?​
Answer: Scan Kit automatically changes the language for your app according to the system language settings, which does not require additional configuration.
Countries/Regions supported by the kit are displayed here. Their languages are also supported by the kit. The languages of countries/regions not listed in the link above means the languages are not yet supported by the kit.
Question 9: Does Scan Kit require the storage read permission when it needs to recognize a barcode in an image from the phone album? I found that in the Default View mode of Scan Kit, if this permission is not granted to the kit, it will fail to access an image from the phone album. Will this issue be resolved?​
Answer: In SDK versions later than Scan SDK 2.10.0.301, the Default View mode allows the storage (media and files) read permission and camera permission to be acquired separately. Click here to learn how.
Get more information at:
HUAWEI Developer Forum
Home page of HMS Core Scan Kit
Development guide for HMS Core Scan Kit

Related

[GUIDE] Bank card recognition achieved by HUAWEI ML Kit

This article is originally from HUAWEI Developer Forum.
Forum link: https://forums.developer.huawei.com/forumPortal/en/home
1 About This Document
Check out the machine learning service business introduction on the Huawei Developer website (https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/ml-introduction-4)
It can be seen that Huawei HMS divides machine learning services into four major services: text-related services, language-related service, image-related services, and face/body-related services. One of them is text-related services. Including text recognition, document recognition, bank card recognition, general card recognition, what are the differences and associations between these sub-services?I will try to explain.
2 Application Scenario Differences
Text service SDKs are classified into device APIs and cloud APIs. Device APIs are processed and analyzed only on the device side and use the computing resource such as the CPU and GPU of the device. Cloud APIs need to send data to the cloud and use the server resources on the cloud for processing and analysis, all the services have device-side APIs except the document identification service, which requires a large amount of computing data to be processed on the cloud. To simplify the analysis scope, we only describe the device-side API service in this document.
2.1 Scenario Comparison
2.1.1 Text recognition: It is more like a versatile talent. Anything can be done, as long as it is text, it can be recognized.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Text OCR application scenarios
Text OCR does not provide a UI. The UI is implemented by developers.
2.1.2 Bank card identification: more like a partial student, only a certain subject is excellent.
default customized box is provided for bank cards. You can quickly extract bank card numbers by directly aligning with the box.
Bank card identification
2.1.3 General cards: Between the above two categories, with certain attainments in a certain field. Can extract text from all cards. In addition, a card alignment box is provided to prompt users to align cards to be identified.
2.2 How to Choose
Bank Card OCR are selected for identification bank cards. For other types of cards, general cards identification are used for identification. For other scenarios, text recognition is used.
3 Service Integration Differences
Compilation Dependency Differences
In order to facilitate everyone's understanding, first explain the following concepts:
Basic SDK APIs provided for developers. All APIs are opened through the basic SDK.
Plug-in The calibration box mentioned in the previous scene comparison summary provides an interface to verify the input quality of the image frame. If it does not meet the requirements, can prompt the user to reposition it.
Model package This is the core of Huawei's HMS ML Kit services. It contains a large number of samples input through a machine learning platform to learn and generate interpreter model files.
Compilation Dependency Summary
According to the preceding compilation dependency, all services need to integrate the corresponding basic SDK and model package. However, Bank Card recognition, and General Card recognition have corresponding plug-ins, which are the calibration boxes mentioned above. In terms of models, Bank Card recognition use a dedicated model package, while General Card recognition and text recognition uses a general model package.
Development Differences
First, let's see how to integrate the services. The detailed steps are not described here. You can view the development steps of the corresponding services on Huawei Developers.
Text recognition
Create an identifier. MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting);
Create a fram object and transfer the image bitmap. MLFrame frame = MLFrame.fromBitmap(bitmap);
Send the frame object to the recognizer for recognition. Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
Result handling Task<MLText> task = analyzer.asyncAnalyseFrame(frame); task.addOnSuccessListener(new OnSuccessListener<MLText>() { @override public void onSuccess(MLText text) { // Recognition success. } }).addOnFailureListener(new OnFailureListener() { @override public void onFailure(Exception e) { // Recognition failed. } });
Bank Card recognition
Start the UI to identify the bank card. private void startCaptureActivity(MLBcrCapture.Callback callback) {
Rewrite the callback function to process the recognition result. private MLBcrCapture.Callback callback = new MLBcrCapture.Callback() { @override public void onSuccess(MLBcrCaptureResult bankCardResult){ // Identify the success. } };
General Card recognition
Start the interface to identify the general card. private void startCaptureActivity(Object object, MLGcrCapture.Callback callback)
Rewrite the callback function to process the recognition result. private MLGcrCapture.Callback callback = new MLGcrCapture.Callback() { @override public int onResult(MLGcrCaptureResult cardResult){ //Successful identification processing The return MLGcrCaptureResult.CAPTURE_STOP;// processing is complete, and the identification is exited. } };
Development Summary
According to the preceding comparison, the processing logic is similar except that no GUI is provided for text recognition. The images to be recognized are transmitted to the SDK and the recognition result is obtained through the callback function. The core difference is that the returned structured data is different.
According to the preceding comparison, the bank card recognition return the directly processed identification content. You can directly obtain the bank card number through the interface without considering how the content is extracted. However, the text recognition and general card recognition return the full identification information, it contains text content such as blocks, lines, and words. If you want to obtain the required information, you need to extract the full information that is identified. For example, you can use the regular expression to match consecutive x digits to identify a card number or match the content after a recognized keyword.
4 Technical Difference Analysis
Based on the preceding difference analysis, we can see that text-related services are different in scenarios, service integration, also has some association. For example, Text recognition and General Card recognition use the same general machine learning model. The following analyzes and explains the technical differences from the technical perspective. As described in the compilation dependency analysis, the basic SDK and model package need to be integrated for text services, and plug-ins need to be integrated for some services to generate calibration boxes. What is the model package? You may be familiar with machine learning. Machine learning is usually divided into the collection of training samples, feature extraction, data modeling, prediction, etc. The model is actually a "mapping function" learned through training samples, feature extraction and other actions in machine learning. In HUAWEI HMS ML Kit, this mapping function is not enough. It needs to be executed, which is called the interpreter framework. In addition, some algorithms need to perform pre-processing and post-processing on the image, for example, converting an image frame into a corresponding eigenvector. To facilitate understanding, the preceding content is collectively referred to as a model file. To enable these model files to run on the mobile phone, the model files further need to be optimized, for example, a running speed of the model files on the mobile phone terminal is optimized, and a size of the model files is reduced.
Differences and association analysis
Now, let's look at the differences and relationships between text services. To facilitate understanding, the following figure shows the differences and relationships between text services.
Text recognition
The training is carried out using a general text data set. His advantages are wide application range and high flexibility. As long as the text content can be recognized.
General card recognition
It is the same as the data set used for text recognition, so there is no difference between the model files, but a general card plug-in is added. The main function is to ensure that the user points the card to the center of the camera, and also recognizes the reflective and blurred images , if the requirements are not met, the user is prompted to readjust, so that the recognition accuracy of the card can be improved.
Bank Card OCR
The bank card recognition service uses the dedicated data training set of the bank card. We all know that the characters on the bank card are greatly different from those in common print. In addition, the characters are convex. If the general model is used, it is difficult to achieve high accuracy, the training uses the dedicated data sets of bank cards and ID cards to improve the accuracy of ID card and bank card identification. In addition, targeted pre-processing is performed for bank cards. For example, the image quality and tilt angle can be dynamically detected in real time, and an alignment box can be generated to restrict the location of cards, if the image is blurred, reflected, or not aligned with the calibration box, the user is prompted to re-align the image.
Notice:
Based on Huawei machine learning service, we will share a series of practical experience later. You can continue to pay attention to our forum.
Any questions about this, you can try to acquire answers from HUAWEI Developer Forum.

HUAWEI HMS Scan Kit vs Zxing

This is originally from HUAWEI Developer Forum (https://forums.developer.huawei.com/forumPortal/en/home)​
Brief Introduction of Both
Zxing is a common third-party open-source SDK. However, Zxing has the following defect: It only implements basic operations of scanning the QR code and does not support more complex scanning environments such as strong light, bending, and deformation. Currently, the mainstream practice is to optimize the source code based on Zxing. However, the optimization effect is still not ideal, and many people will spend a lot of time on the optimization.
The Huawei Scan Kit service provides convenient bar code and QR code scanning, parsing, and generation capabilities, helping developers quickly build the QR code scanning function in apps. Thanks to Huawei’s long-term accumulation in the computer vision field, Huawei’s unified barcode scanning service (Scan Kit) can detect and automatically amplify long-distance or small-sized codes, and optimize the identification of common complex barcode scanning scenarios (such as reflection, dark light, smudge, blur, and cylinder). Improves the QR code scanning success rate and user experience.
Now, let’s compare the capabilities of Zxing and Huawei HMS Scan Kit from the following aspects:
long-distance code scanning
The success of long-distance QR code scanning depends on the QR code specifications (the more information is, the more difficult it is to identify) and the distance between the camera and the QR code.
Due to the lack of automatic zoom-in optimization for Zxing, it is difficult to recognize the code when the code is less than 1/5 of the screen.
The HMS Scan Kit has a pre-detection function, which can automatically amplify the QR code at a long distance even if the QR code cannot be identified by naked eyes.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Conclusion: Scan Kit Wins
Scanning Codes in Complex Scenarios
In complex scenarios, code scanning can be classified into reflection, dark light, smudge, blur, and cylinder scanning. In complex scenarios, the recognition effect of Zxing is poor. Complex scenarios are as follows:
These scenarios are common in daily life. For example, outdoor scenarios such as reflection, dark light, and smudge may occur. When a QR code is attached to a product, curved surfaces or even edges and corners may occur. When you walk and scan the QR code, you will also encounter the challenge of motion blur. The following figure shows the test comparison in these scenarios.
Conclusion: Scan Kit Wins
Scan the QR code at any angle
Currently, Zxing supports only forward scanning, that is, Zxing cannot identify the code with a certain angle. Scan Kit can easily achieve this. When the code deflection is within 10 degrees, Zxing can still have high recognition accuracy. However, when the code deflection exceeds 10 degrees, the recognition accuracy of Zxing decreases sharply. However, Scan Kit is not affected by the clip angle, and the recognition accuracy does not decrease.
Comparison Conclusion: Scan Kit Wins
Multi-code identification comparison
Multi-code identification helps identify multiple codes at a time in scenarios such as express delivery and supermarket checkout, improving service processing efficiency. In multi-code identification mode, the Scan Kit can identify five types of codes on the screen at the same time and return the corresponding types and values of all codes at a time.
Conclusion: Scan Kit Wins
SDK Package Size
The size of the Zxing package is about 500 KB, which is a satisfactory size. Scan Kit has two modes: Lite and Pro. In Lite mode, the package size is 700 KB. In Pro mode, the package size is 3.3 MB. If you use the table, you will have a clearer understanding.
These two modes are slightly different on non-Huawei phones. Therefore, if you are not sensitive to the package size on non-Huawei phones, try to select the Pro version. I have also performed tests on non-Huawei Lite versions, but the test results are slightly lower than those of the Pro version.
Conclusion: Zxing has advantages.
Platform Support
Zxing and Scan Kit support both iOS and Android platforms.
Conclusion: The score is even.
Integration Modes
The integration mode of Zxing is relatively simple. It can be quickly integrated with SDK by only a few lines of code. However, in the actual product development process, the development of the product interface and auxiliary functions is also involved. However, Zxing does not provide the corresponding quick integration mode. The integration guide is available on the live network for a long time. Therefore, the development difficulty can be reduced. In summary, the first point in Zxing integration is that no default interface is available. Second, you need to achieve their own automatic amplification, flash and other functions.
Scan Kit provides multiple access modes, including single-code access, multi-code access, and customized access. The differences between the two integration modes are as follows:
The default layout is provided for the single-code access of Scan Kit cameras. In addition, functions such as automatic amplification and flash are preset. Developers do not need to manually configure these functions. The code integration volume is 5 lines, which is especially suitable for scenarios where quick integration and quick replacement of the QR code scanning function are required.
The customized access of Scan Kit allows users to design the layout by themselves. Only the basic functions and blank layout of scanning and decoding are provided. Users can design the layout based on their app style. However, they need to implement functions such as automatic zoom and flash. The corresponding technical documents can be found on the optical network of Huawei developers. However, compared with the single-code access, this access mode is more complicated.
The integration mode is as follows:
Zxing
1. Create a project and import the Zxing module.
2. Add rights and dynamically apply for rights.
3. Copy the onActivity method.
4. Invoking the Decoding Function
5. Compile the UI and ensure that the UI is correctly displayed.
Scan Kit
The default view mode provides two functions: camera QR code scanning and image-based QR code scanning. In this mode, developers do not need to develop the UI for QR code scanning.
The process is almost the same as that of Zxing.
1. Create a project and import the Scan Kit module.
2. Add permissions and dynamically apply for permissions.
3. Copy the onActivity method.
4. Invoke the decoding function.
The following uses the Default View Mode as an example to describe the integration procedure.
Create a project and add online dependency in the app/build.gradle file.
Code:
implementation'com.huawei.hms:scan:{version}'
2. Declare the QR code scanning page in the AndroidManifest.xml file of the calling module.
Code:
<!-Camera permission-->
<uses-permission android:name="android.permission.CAMERA" />
<!--Reading the file permission-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!--Features-->
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
3. Create QR code scanning options based on the site requirements.
Code:
HmsScanAnalyzerOptions options = new HmsScanAnalyzerOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE, HmsScan.DATAMATRIX_SCAN_TYPE).create();
4. Invoke the static method startScan of ScanUtil to start the Default View QR code scanning page.
Code:
ScanUtil.startScan(this, REQUEST_CODE_SCAN_ONE, options);
The comparison shows that Scan Kit and Zxing have the same dependency and permission application methods. However, Scan Kit can use the UI by default (with built-in flash, automatic focal length, and QR code import). Zxing needs to implement the UI by itself, then, manually complete these functions.
Conclusion: Scan Kit Wins
Technical Analysis
Why is Scankit better than Zxing? The following describes the technical analysis of Zxing and Scan Kit from the perspective of technical implementation principles.
Zxing
Zxing uses the traditional recognition algorithm. It can detect codes by analyzing the codes from a certain angle. This algorithm allows only a certain degree of deformation, for example, the square code can be slightly skewed by less than 10 degrees, his pixels still fit the pattern, but if they’re deformed too much or angularly too large, they can’t detect the position of the code. The detection process of ZXing is classified into two types: one-dimensional code detection and two-dimensional code serial detection.
In one-dimensional code detection, Zxing uses a progressive scanning mechanism for feature recognition. Because one-dimensional code features are black-and-white crossover, when the black-and-white sequence with equal spacing of the class is identified, it is considered as a potential code. The length of the potential code is determined by finding the start bit and the end bit. Then, the sequence is sent to different one-dimensional code decoding modules for serial decoding, which takes a long time. When serial decoding fails, a failure message is displayed, and the failure time is also long. In addition, once the one-dimensional code has a wrinkle, rotation, or deformation, a sequence that meets a specific requirement cannot be found through progressive scanning, that is, the one-dimensional code cannot be detected in a complex condition.
1、Quiet zone(fround) 2.Start character 3.Data symbols 4.Terminator 5、Quiet zone(behind)
In two-dimensional code detection, Zxing uses different detection algorithms for different two-dimensional codes. For example, the most common QR code has three location detection patterns. Therefore, Zxing still uses the interlaced scanning mode to find the features of the location detection pattern. Once the features whose black-and-white ratio is 1:1:3:1:1 are found, that is, a central point of the position detection graph is used as a reference point to perform affine transformation, so that the corrected picture is sent to the QR decoding module. The positioning point of the QR code has a function of correcting rotation, and therefore can be well adapted to a rotation situation. However, Zxing is completely unable to process cases such as partial blocking, deformation, and contaminating and reflecting of the positioning point. As shown in the figure, the detection position detection graph is the most important step for detecting whether the two-dimensional code is successfully detected. Once a location fails to be detected, the two-dimensional code cannot be detected.
HUAWEI Scan Kit
Scan Kit uses the deep learning algorithm, which is spatially invariant. By training detectors of corresponding code types, Scan Kit can quickly find all required codes.
Actual process:
The bar code detection module and angle prediction module use the deep learning model.
Barcode detection: The serial process of separate detection of two-dimensional codes of one-dimensional codes in Zxing is no longer restricted. A trained detector can be used to directly obtain the code pattern and corresponding position. The bar code can be accurately sent to the corresponding decoding module through one detection, and a separate serial decoding process is no longer required. Because decoding includes a series of operations with high overheads such as skipping scanning, and information of different codes cannot be shared, this operation greatly reduces an end-to-end delay, and avoids a lot of repeated and unnecessary calculation overheads.
Angle prediction: The corresponding three-bit angle of the code is returned for radiographic transformation. In practice, the core of barcode detection is to accurately obtain boundary points. After being converted into binary images, the images are sent to the decoding module, but the decoding effect is still poor. This is also the most important step to solve the bar code identification in complex scenarios.
To sum up, the deep learning changes the serial detection and decoding process of the barcode of Zxing to a parallel process. In addition, the three-digit angle value of the barcode is returned. After the affine change, the aligned standard front barcode is obtained. This greatly improves the barcode detection success rate and greatly reduces the latency.
Nice and useful article
do huawei and zxing scan detect damaged qr code?
riteshchanchal said:
do huawei and zxing scan detect damaged qr code?
Click to expand...
Click to collapse
Hi, it depends on the broken level of your QR code. If the QR code is a little unclear or slightly broken, it can be avaliable.
If possible, I think you can send a picture or describe the degree of the broken condition. It will help you get a more accurate reply.

Comparison Between Zxing and Huawei HMS Scan Kit

About This Document
Zxing is a common third-party open-source SDK. However, Zxing has the following defect: It only implements basic operations of scanning the QR code and does not support more complex scanning environments such as strong light, bending, and deformation. Currently, the mainstream practice is to optimize the source code based on Zxing. However, the optimization effect is still not ideal, and many people will spend a lot of time on the optimization.
The Huawei Scan Kit service provides convenient bar code and QR code scanning, parsing, and generation capabilities, helping developers quickly build the QR code scanning function in apps. Thanks to Huawei's long-term accumulation in the computer vision field, Huawei's unified barcode scanning service (Scan Kit) can detect and automatically amplify long-distance or small-sized codes, and optimize the identification of common complex barcode scanning scenarios (such as reflection, dark light, smudge, blur, and cylinder). Improves the QR code scanning success rate and user experience.
Now, let's compare the capabilities of Zxing and Huawei HMS Scan Kit from the following aspects:
 Remote code scanning
 Scan QR codes in complex scenarios
 Scan the barcode at any angle.
 multicode recognition
 Integration difficulty
 SDK Package Size
 Cross-platform support
Comparison of long-distance code scanning
The success of long-distance QR code scanning depends on the QR code specifications (the more information is, the more difficult it is to identify) and the distance between the camera and the QR code. Due to the lack of automatic zoom-in optimization for Zxing, it is difficult to recognize the code when the code is less than 1/5 of the screen. The HMS Scan Kit has a pre-detection function, which can automatically amplify the QR code at a long distance even if the QR code cannot be identified by naked eyes.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
https://communityfile-drcn.op.hiclo...A1B389BE789A4FD4B3C70DF5A2582CD647359FF7D.gif
Comparison Conclusion: Scan Kit Wins
Comparison by Scanning Codes in Complex Scenarios
In complex scenarios, code scanning can be classified into reflection, dark light, smudge, blur, and cylinder scanning. In complex scenarios, the recognition effect of Zxing is poor. Complex scenarios are as follows:
These scenarios are common in daily life. For example, outdoor scenarios such as reflection, dark light, and smudge may occur. When a QR code is attached to a product, curved surfaces or even edges and corners may occur. When you walk and scan the QR code, you will also encounter the challenge of motion blur. The following figure shows the test comparison in these scenarios.
https://communityfile-drcn.op.hiclo...4F29750B35AD76B2B0183B45B46F9DFCAF24F3105.gif
https://communityfile-drcn.op.hiclo...9C42B539997998371B63EA6A0451ED87ED041DFEE.gif
https://communityfile-drcn.op.hiclo...CE580ECA67EEEBBCC9E7D7238AA5052D87B882D79.gif
Comparison Conclusion: Scan Kit Wins
Scan the QR code at any angle for comparison.
Currently, Zxing supports only forward scanning, that is, Zxing cannot identify the code with a certain angle. Scan Kit can easily achieve this. When the code deflection is within 10 degrees, Zxing can still have high recognition accuracy. However, when the code deflection exceeds 10 degrees, the recognition accuracy of Zxing decreases sharply. However, Scan Kit is not affected by the clip angle, and the recognition accuracy does not decrease.
https://communityfile-drcn.op.hiclo...4B65A180C69FEEF682C5E2069485FD83D8CA58C18.gif
Comparison Conclusion: Scan Kit Wins
Multi-code identification comparison
Multi-code identification helps identify multiple codes at a time in scenarios such as express delivery and supermarket checkout, improving service processing efficiency. In multi-code identification mode, the Scan Kit can identify five types of codes on the screen at the same time and return the corresponding types and values of all codes at a time.
Comparison Conclusion: Scan Kit Wins
SDK Package Size Comparison
The size of the Zxing package is about 500 KB, which is a satisfactory size. Scan Kit has two modes: Lite and Pro. In Lite mode, the package size is 700 KB. In Pro mode, the package size is 3.3 MB. If you use the table, you will have a clearer understanding.
These two modes are slightly different on non-Huawei phones. Therefore, if you are not sensitive to the package size on non-Huawei phones, try to select the Pro version. I have also performed tests on non-Huawei Lite versions, but the test results are slightly lower than those of the Pro version.
Conclusion: Zxing has advantages.
Platform Support Comparison
Zxing and Scan Kit support both iOS and Android platforms.
Conclusion: The score is even.
Comparison of Integration Modes
The integration mode of Zxing is relatively simple. It can be quickly integrated with SDK by only a few lines of code. However, in the actual product development process, the development of the product interface and auxiliary functions is also involved. However, Zxing does not provide the corresponding quick integration mode. The integration guide is available on the live network for a long time. Therefore, the development difficulty can be reduced. In summary, the first point in Zxing integration is that no default interface is available. Second, you need to achieve their own automatic amplification, flash and other functions.
Scan Kit provides multiple access modes, including single-code access, multi-code access, and customized access. The differences between the two integration modes are as follows:
The default layout is provided for the single-code access of Scan Kit cameras. In addition, functions such as automatic amplification and flash are preset. Developers do not need to manually configure these functions. The code integration volume is 5 lines, which is especially suitable for scenarios where quick integration and quick replacement of the QR code scanning function are required.
The customized access of Scan Kit allows users to design the layout by themselves. Only the basic functions and blank layout of scanning and decoding are provided. Users can design the layout based on their app style. However, they need to implement functions such as automatic zoom and flash. The corresponding technical documents can be found on the optical network of Huawei developers. However, compared with the single-code access, this access mode is more complicated.
The integration mode is as follows:
Zxing integration process
1. Create a project and import the Zxing module.
2. Add rights and dynamically apply for rights.
3. Copy the onActivity method.
4. Invoking the Decoding Function
5. Compile the UI and ensure that the UI is correctly displayed.
Scan Kit integration process
The default view mode provides two functions: camera QR code scanning and image-based QR code scanning. In this mode, developers do not need to develop the UI for QR code scanning.
The process is almost the same as that of Zxing.
1. Create a project and import the Scan Kit module.
2. Add permissions and dynamically apply for permissions.
3. Copy the onActivity method.
4. Invoke the decoding function.
The following uses the Default View Mode as an example to describe the integration procedure.
1. Create a project and add online dependency in the app/build.gradle file.
implementation'com.huawei.hms:scan:{version}'
2. Declare the QR code scanning page in the AndroidManifest.xml file of the calling module.
<!-Camera permission-->
<uses-permission android:name="android.permission.CAMERA" />
<!--Reading the file permission-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!--Features-->
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
3. Create QR code scanning options based on the site requirements.
HmsScanAnalyzerOptions options = new HmsScanAnalyzerOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE, HmsScan.DATAMATRIX_SCAN_TYPE).create();
4. Invoke the static method startScan of ScanUtil to start the Default View QR code scanning page.
ScanUtil.startScan(this, REQUEST_CODE_SCAN_ONE, options);
The comparison shows that Scan Kit and Zxing have the same dependency and permission application methods. However, Scan Kit can use the UI by default (with built-in flash, automatic focal length, and QR code import). Zxing needs to implement the UI by itself, then, manually complete these functions.
Comparison Conclusion: Scan Kit Wins
Technical Analysis
Why is Scankit better than Zxing? The following describes the technical analysis of Zxing and Scan Kit from the perspective of technical implementation principles.
Zxing Technology Analysis
Zxing uses the traditional recognition algorithm. It can detect codes by analyzing the codes from a certain angle. This algorithm allows only a certain degree of deformation, for example, the square code can be slightly skewed by less than 10 degrees, his pixels still fit the pattern, but if they're deformed too much or angularly too large, they can't detect the position of the code. The detection process of ZXing is classified into two types: one-dimensional code detection and two-dimensional code serial detection.
In one-dimensional code detection, Zxing uses a progressive scanning mechanism for feature recognition. Because one-dimensional code features are black-and-white crossover, when the black-and-white sequence with equal spacing of the class is identified, it is considered as a potential code. The length of the potential code is determined by finding the start bit and the end bit. Then, the sequence is sent to different one-dimensional code decoding modules for serial decoding, which takes a long time. When serial decoding fails, a failure message is displayed, and the failure time is also long. In addition, once the one-dimensional code has a wrinkle, rotation, or deformation, a sequence that meets a specific requirement cannot be found through progressive scanning, that is, the one-dimensional code cannot be detected in a complex condition.
In two-dimensional code detection, Zxing uses different detection algorithms for different two-dimensional codes. For example, the most common QR code has three location detection patterns. Therefore, Zxing still uses the interlaced scanning mode to find the features of the location detection pattern. Once the features whose black-and-white ratio is 1:1:3:1:1 are found, that is, a central point of the position detection graph is used as a reference point to perform affine transformation, so that the corrected picture is sent to the QR decoding module. The positioning point of the QR code has a function of correcting rotation, and therefore can be well adapted to a rotation situation. However, Zxing is completely unable to process cases such as partial blocking, deformation, and contaminating and reflecting of the positioning point. As shown in the figure, the detection position detection graph is the most important step for detecting whether the two-dimensional code is successfully detected. Once a location fails to be detected, the two-dimensional code cannot be detected.
Technical Analysis of Huawei HMS Scan Kit
Scan Kit uses the deep learning algorithm, which is spatially invariant. By training detectors of corresponding code types, Scan Kit can quickly find all required codes.
Actual process:
The bar code detection module and angle prediction module use the deep learning model.
Barcode detection: The serial process of separate detection of two-dimensional codes of one-dimensional codes in Zxing is no longer restricted. A trained detector can be used to directly obtain the code pattern and corresponding position. The bar code can be accurately sent to the corresponding decoding module through one detection, and a separate serial decoding process is no longer required. Because decoding includes a series of operations with high overheads such as skipping scanning, and information of different codes cannot be shared, this operation greatly reduces an end-to-end delay, and avoids a lot of repeated and unnecessary calculation overheads.
Angle prediction: The corresponding three-bit angle of the code is returned for radiographic transformation. In practice, the core of barcode detection is to accurately obtain boundary points. After being converted into binary images, the images are sent to the decoding module, but the decoding effect is still poor. This is also the most important step to solve the bar code identification in complex scenarios.
To sum up, the deep learning changes the serial detection and decoding process of the barcode of Zxing to a parallel process. In addition, the three-digit angle value of the barcode is returned. After the affine change, the aligned standard front barcode is obtained. This greatly improves the barcode detection success rate and greatly reduces the latency.
More information
Demos, sample codes, and development documents are available on the Huawei developer official website.
Demo and sample code:
https://developer.huawei.com/consumer/en/doc/development/HMS-Examples/scan-sample-code4
Development guide:
https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/scan-introduction-4
API reference:
https://developer.huawei.com/consumer/en/doc/development/HMS-References/scan-apioverview
To be supplemented
Based on Huawei machine learning service, we will share a series of practical experience later. You can continue to pay attention to it.

Understand ML Kit text, bank card & general card identification

More information like this, you can visit HUAWEI Developer Forum​
Original link: https://forums.developer.huawei.com/forumPortal/en/topicview?tid=0201253487604250240&fid=0101187876626530001
1 About This Document
Check out the machine learning service business introduction on the Huawei Developer website
It can be seen that Huawei HMS divides machine learning services into four major services: text-related services, language-related service, image-related services, and face/body-related services. One of them is text-related services. Including text recognition, document recognition, bank card recognition, general card recognition, what are the differences and associations between these sub-services?I will try to explain.
2 Application Scenario Differences
First, let’s look at the sub-services of the text-related services and the scenario differences.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Text service SDKs are classified into device APIs and cloud APIs. Device APIs are processed and analyzed only on the device side and use the computing resource such as the CPU and GPU of the device. Cloud APIs need to send data to the cloud and use the server resources on the cloud for processing and analysis, all the services have device-side APIs except the document identification service, which requires a large amount of computing data to be processed on the cloud. To simplify the analysis scope, we only describe the device-side API service in this document.
2.1 Scenario Comparison
As shown in the preceding table, the application scenarios of different capabilities are different.
2.1.1 Text recognition: It is more like a versatile talent. Anything can be done, as long as it is text, it can be recognized..
Text OCR application scenarios
Text OCR does not provide a UI. The UI is implemented by developers.
2.1.2 Bank card identification: more like a partial student, only a certain subject is excellent.
default customized box is provided for bank cards. You can quickly extract bank card numbers by directly aligning with the box.
Bank card identification
2.1.3 General cards: Between the above two categories, with certain attainments in a certain field. Can extract text from all cards. In addition, a card alignment box is provided to prompt users to align cards to be identified.
General card identification
2.2 How to Choose
Bank Card OCR are selected for identification bank cards. For other types of cards, general cards identification are used for identification. For other scenarios, text recognition is used.
3 Service Integration Differences
Compilation Dependency Differences
In order to facilitate everyone’s understanding, first explain the following concepts:
Basic SDK APIs provided for developers. All APIs are opened through the basic SDK.
Plug-in The calibration box mentioned in the previous scene comparison summary provides an interface to verify the input quality of the image frame. If it does not meet the requirements, can prompt the user to reposition it.
Model package This is the core of Huawei’s HMS ML Kit services. It contains a large number of samples input through a machine learning platform to learn and generate interpreter model files.
The following table summarizes the compilation dependencies of different services.
Compilation Dependency Summary
According to the preceding compilation dependency, all services need to integrate the corresponding basic SDK and model package. However, Bank Card recognition, and General Card recognition have corresponding plug-ins, which are the calibration boxes mentioned above. In terms of models, Bank Card recognition use a dedicated model package, while General Card recognition and text recognition uses a general model package.
Development Differences
First, let’s see how to integrate the services. The detailed steps are not described here. You can view the development steps of the corresponding services on the Developer website.
https://developer.huawei.com/consumer/en/doc/development/HMS-Guides/ml-introduction-4
The following describes the main development procedure of the corresponding service:
Text recognition
Create an identifier. MLTextAnalyzer analyzer = MLAnalyzerFactory.getInstance().getLocalTextAnalyzer(setting);
Create a fram object and transfer the image bitmap. MLFrame frame = MLFrame.fromBitmap(bitmap);
Send the frame object to the recognizer for recognition. Task<MLText> task = analyzer.asyncAnalyseFrame(frame);
Result handling Task<MLText> task = analyzer.asyncAnalyseFrame(frame); task.addOnSuccessListener(new OnSuccessListener<MLText>() { @override public void onSuccess(MLText text) { // Recognition success. } }).addOnFailureListener(new OnFailureListener() { @override public void onFailure(Exception e) { // Recognition failed. } });
Bank Card recognition
Start the UI to identify the bank card. private void startCaptureActivity(MLBcrCapture.Callback callback) {
Rewrite the callback function to process the recognition result. private MLBcrCapture.Callback callback = new MLBcrCapture.Callback() { @override public void onSuccess(MLBcrCaptureResult bankCardResult){ // Identify the success. } };
General Card recognition
Start the interface to identify the general card. private void startCaptureActivity(Object object, MLGcrCapture.Callback callback)
Rewrite the callback function to process the recognition result. private MLGcrCapture.Callback callback = new MLGcrCapture.Callback() { @override public int onResult(MLGcrCaptureResult cardResult){ //Successful identification processing The return MLGcrCaptureResult.CAPTURE_STOP;// processing is complete, and the identification is exited. } };
Development Summary
According to the preceding comparison, the processing logic is similar except that no GUI is provided for text recognition. The images to be recognized are transmitted to the SDK and the recognition result is obtained through the callback function. The core difference is that the returned structured data is different. To facilitate understanding, the following tables are provided:
Return the content summary.
According to the preceding comparison, the bank card recognition return the directly processed identification content. You can directly obtain the bank card number through the interface without considering how the content is extracted. However, the text recognition and general card recognition return the full identification information, it contains text content such as blocks, lines, and words. If you want to obtain the required information, you need to extract the full information that is identified. For example, you can use the regular expression to match consecutive x digits to identify a card number or match the content after a recognized keyword. Based on the preceding analysis, the development difficulty comparison is as follows:
Development difficulty comparison summary
4 Technical Difference Analysis
Based on the preceding difference analysis, we can see that text-related services are different in scenarios, service integration, also has some association. For example, Text recognition and General Card recognition use the same general machine learning model. The following analyzes and explains the technical differences from the technical perspective. As described in the compilation dependency analysis, the basic SDK and model package need to be integrated for text services, and plug-ins need to be integrated for some services to generate calibration boxes. What is the model package? You may be familiar with machine learning. Machine learning is usually divided into the collection of training samples, feature extraction, data modeling, prediction, etc. The model is actually a “mapping function” learned through training samples, feature extraction and other actions in machine learning. In HUAWEI HMS ML Kit, this mapping function is not enough. It needs to be executed, which is called the interpreter framework. In addition, some algorithms need to perform pre-processing and post-processing on the image, for example, converting an image frame into a corresponding eigenvector. To facilitate understanding, the preceding content is collectively referred to as a model file. To enable these model files to run on the mobile phone, the model files further need to be optimized, for example, a running speed of the model files on the mobile phone terminal is optimized, and a size of the model files is reduced.
Differences and association analysis
Now, let’s look at the differences and relationships between text services. To facilitate understanding, the following figure shows the differences and relationships between text services.
Text recognition integration mode
Text recognition
The training is carried out using a general text data set. His advantages are wide application range and high flexibility. As long as the text content can be recognized.
General card recognition
It is the same as the data set used for text recognition, so there is no difference between the model files, but a general card plug-in is added. The main function is to ensure that the user points the card to the center of the camera, and also recognizes the reflective and blurred images , if the requirements are not met, the user is prompted to readjust, so that the recognition accuracy of the card can be improved.
Bank Card OCR
The bank card recognition service uses the dedicated data training set of the bank card. We all know that the characters on the bank card are greatly different from those in common print. In addition, the characters are convex. If the general model is used, it is difficult to achieve high accuracy, the training uses the dedicated data sets of bank cards and ID cards to improve the accuracy of ID card and bank card identification. In addition, targeted pre-processing is performed for bank cards. For example, the image quality and tilt angle can be dynamically detected in real time, and an alignment box can be generated to restrict the location of cards, if the image is blurred, reflected, or not aligned with the calibration box, the user is prompted to re-align the image.
5 Summary
Based on the preceding analysis, the conclusion is as follows:
How, after reading this article, what feeling, come to express your opinion quickly!
DemoGithub address: https://github.com/HMS-MLKit/HUAWEI-HMS-MLKit-Sample

Developing a Barcode Reader to Make Life Easier

I recently came across an article saying that barcodes and barcode readers have become a mainstay of today's economies and our lives in general, since they were introduced in the 1970s.
So, I decided to test how true this is by seeing how often I come across barcode readers in a typical day of mine. And — surprise surprise — they turned out to be more important than I thought.
A Reader's Day in My Life​Right after I left my home in the morning, I came across a bike for hire and used a bike sharing app to scan the QR code on the bike to unlock it. When I finally got to work, I scanned the bike's code again to lock it and complete the journey.
At lunch, I went to a café, sat down, and scanned the barcode on the table to order some lunch. After filling myself up, I went to the counter and scanned the QR code on the wall to pay.
And after work, before I went home, I went to my local collection point to pick up the smartwatch I'd recently bought. It was here where I saw the staff struggling to scan and record the details of the many packages they were handling. When I finally got home and had dinner, there was one last barcode to scan for the day. That was the QR code for the brand-new smartwatch, which was needed for linking the device with an app on my phone.
Overcoming Obstacles for Barcode Readers​That said, scanning barcodes is not as easy as it sounds because the scanning experience encountered several challenges:
First, poor-quality barcodes made recognizing barcodes a challenge. Barcodes on the bike and table were smudged due to daily wear and tear, which is common in a public space.
Second, the placement of codes is not ideal. There was an awkward moment when I went to the counter to pay for my lunch, and the payment code was stuck on the wall right next to a person who thought I was trying to secretly take a picture of him.
Third is slow and rigid barcode scanning. When I went to the collection point, it was clear that the efficiency of the sorters was let down by their readers, which were unable to scan multiple barcodes at once.
Fourth, different barcode formats mean that the scanning mode must be switched.
So, in the face of all these challenges, I decided to develop my own reader. After doing some research and testing, I settled on HMS Core Scan Kit, because this kit utilizes computer vision technologies to ensure that it can recognize a hard-to-read barcode caused by factors including dirt, light reflection, and more. The kit can automatically zoom in on a barcode image from a distance so that the barcode can be easily identified, by using the deep learning algorithm model. The kit supports multi-scanning of five different barcodes at once, for faster recording of barcode information. And the kit supports 13 barcode formats, covering those commonly adopted in various scenarios.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
Aside from these advantages, I also found that the kit supports customization of the scanning UI, analysis of barcode content in 12 kinds of scenarios for extracting structured data, two SDKs (1.1 MB and 3.3 MB respectively), and four different call modes. An Android app can be integrated with the kit in just five lines of code. And of the modes available, I chose the Default View mode for my app. Let's have a look at how this works.
Service Process of the Solution​
Specifically speaking:
1. A user opens an app and sends a barcode scanning request.
2. The app checks whether it has the camera permission.
3. When the app has obtained the permission, the app calls the startScan API to launch the barcode scanning UI.
4. The HMS Core SDK checks whether the UI is successfully displayed.
5. The HMS Core SDK calls onActivityResult to obtain the scanning result.
6. The app obtains the scanning result according to the scanning status (RESULT_CODE). If the result is SUCCESS, the app returns the scanning result to the user; if the result is ERROR_NO_READ_PERMISSION, the app needs to apply for the file read permission and enters the Default View mode again.
7. The app encapsulates the scanning result and sends it to the user.
Development Procedure​Making Preparations​1. Install Android Studio 3.6.1 or later.
2. Install JDK 1.8.211 or later.
3. Make the following app configurations:
minSdkVersion: 19 or later
targetSdkVersion: 33
compileSdkVersion: 31
Gradle version: 4.6 or later
4. Install the SDK Platform 21 or later.
5. Register as a developer.
6. Create a project and an app in AppGallery Connect.
7. Generate a signing certificate fingerprint, which is used to verify the authenticity of an app.
8. Go to AppGallery Connect to add the fingerprint in the SHA-256 certificate fingerprint field, as marked in the figure below.
9. Integrate the HMS Core SDK with the Android Studio project.
10. Configure obfuscation scripts so that the SDK will not be obfuscated.
11. Integrate Scan Kit via HMS Toolkit. For details, click here.
12. Declare necessary permissions in the AndroidManifest.xml file.
Developing the Scanning Function​1. Set the scanning parameters, which is an optional step.
Scan Kit supports 13 barcode formats in total. You can add configurations so that Scan Kit will scan only the barcodes of your desired formats, increasing the scanning speed. For example, when only the QR code and DataMatrix code need to be scanned, follow the code below to construct the HmsScanAnalyzerOptions object.
When there is no specified format of the barcodes to be scanned, this object is not required. 1 is one of the parameter values for the scanning UI titles, corresponding to the var1 parameter in setViewType.
Code:
// QRCODE_SCAN_TYPE and DATAMATRIX_SCAN_TYPE indicate that Scan Kit will support only the barcodes in the QR code and DataMatrix formats. setViewType is used to set the scanning UI title. 0 is the default value, indicating title Scan QR code/barcode, and 1 indicates title Scan QR code. setErrorCheck is used to set the error listener. true indicates that the scanning UI is exited upon detection of an error; false indicates that the scanning UI is exited upon detection of the scanning result, without reporting the error.
HmsScanAnalyzerOptions options = new HmsScanAnalyzerOptions.Creator().setHmsScanTypes(HmsScan.QRCODE_SCAN_TYPE, HmsScan.DATAMATRIX_SCAN_TYPE).setViewType(1).setErrorCheck(true).create();
2. Call startScan of ScanUtil to start the scanning UI of the Default View mode, where a user can choose to use the camera to scan a barcode or go to the phone's album and select an image to scan.
REQUEST_CODE_SCAN_ONE: request ID, corresponding to the requestCode parameter of the onActivityResult method. This parameter is used to check whether the call to onActivityResult is from the scanning result callback of Scan Kit. If requestCode in the onActivityResult method is exactly the request ID defined here, the scanning result is successfully obtained from Scan Kit.
Set options to null when there is a need to scan barcodes in all formats supported by the kit.
Code:
ScanUtil.startScan(this, REQUEST_CODE_SCAN_ONE, options);
3. Receive the scanning result using the callback API, regardless of whether the scanned object is captured by the camera or from an image in the album.
Call the onActivityResult method of the activity to obtain the intent, in which the scanning result object HmsScan is encapsulated. RESULT describes how to obtain intent parameters.
If the value of requestCode is the same as that of REQUEST_CODE_SCAN_ONE defined in step 2, the received intent comes from Scan Kit.
Obtain the code scanning status through RESULT_CODE in the intent.
Use RESULT in the intent to obtain the object of the HmsScan class.
Code:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK || data == null) {
return;
}
if (requestCode == REQUEST_CODE_SCAN_ONE) {
// Input an image for scanning and return the result.
int errorCode = data.getIntExtra(ScanUtil.RESULT_CODE, ScanUtil.SUCCESS);
if (errorCode == ScanUtil.SUCCESS) {
Object obj = data.getParcelableExtra(ScanUtil.RESULT);
if (obj != null) {
// Display the scanning result.
...
}
}
if (errorCode == ScanUtil.ERROR_NO_READ_PERMISSION) {
// The file read permission is not assigned. Apply for the permission.
...
}
}
}
Then — Boom! The barcode reader is all set and ready. I gave it a spin last week and everything seemed to be working well.
Takeaway​Barcodes are everywhere these days, so it's important to carry a barcode reader at all times. This signals a fantastic opportunity for app developers.
The ideal barcode reader will support different barcode formats, be capable of identifying poor-quality barcodes in challenging environments, and support multi-scanning of barcodes at the same time.
As challenging as it sounds, HMS Core Scan Kit is the perfect companion. Computer vision techs, deep learning algorithm, support for multiple and continuous barcode scanning… With all these features, together with its easy-to-use and lightweight SDKs and flexible call modes, the kit gives developers and users all they'll ever need from a barcode reader app.

Categories

Resources