How to integrate semantic segmentation using Huawei HiAI - Huawei Developers

Introduction​
In this article we will learn how to integrate Huawei semantic segmentation using Huawei HiAI.
What is Semantic Segmentation?
In simple “Semantic segmentation is the task of assigning a class to every pixel in a given image.”
Semantic segmentation performs pixel-level recognition and segmentation on a photo to obtain category information and accurate position information of objects in the image. The foregoing content is used as the basic information for semantic comprehension of the image, and can be subsequently used in multiple types of image enhancement processing.
Types of objects can be identified and segmented
People
Sky
Greenery (including grass and trees)
Food
Pet
Building
Flower
Water
Beach
Mountain
Features
Fast: This algorithm is currently developed based on the deep neural network, to fully utilize the NPU of Huawei mobile phones to accelerate the neural network, achieving an acceleration of over 10 times.
Lightweight: This API greatly reduces the computing time and ROM space the algorithm model takes up, making your app more lightweight.
How to integrate Semantic Segmentation
Configure the application on the AGC.
Apply for HiAI Engine Library
Client application development process.
Configure application on the AGC
Follow the steps
Step 1: We need to register as a developer account in AppGallery Connect. If you are already a developer ignore this step.
Step 2: Create an app by referring to Creating a Project and Creating an App in the Project
Step 3: Set the data storage location based on the current location.
Step 4: Generating a Signing Certificate Fingerprint.
Step 5: Configuring the Signing Certificate Fingerprint.
Step 6: Download your agconnect-services.json file, paste it into the app root directory.
Apply for HiAI Engine Library
What is Huawei HiAI ?
HiAI is Huawei’s AI computing platform. HUAWEI HiAI is a mobile terminal–oriented artificial intelligence (AI) computing platform that constructs three layers of ecology: service capability openness, application capability openness, and chip capability openness. The three-layer open platform that integrates terminals, chips, and the cloud brings more extraordinary experience for users and developers.
How to apply for HiAI Engine?
Follow the steps
Step 1: Navigate to this URL, choose App Service > Development and click HUAWEI HiAI.
{
"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"
}
Step 2: Click Apply for HUAWEI HiAI kit.
Step 3: Enter required information like Product name and Package name, click Next button.
Step 4: Verify the application details and click Submit button.
Step 5: Click the Download SDK button to open the SDK list.
Step 6: Unzip downloaded SDK and add into your android project under libs folder.
Step 7: Add jar files dependences into app build.gradle file.
implementation fileTree(include: ['*.aar', '*.jar'], dir: 'libs')
implementation 'com.google.code.gson:gson:2.8.6'
repositories {
flatDir {
dirs 'libs'
}
}Copy code
Client application development process
Follow the steps
Step 1: Create an Android application in the Android studio (Any IDE which is your favorite).
Step 2: Add the App level Gradle dependencies. Choose inside project Android > app > build.gradle.
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect
Root level gradle dependencies.
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Step 3: Add permission in AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.hardware.camera"/>
<uses-permission android:name="android.permission.HARDWARE_TEST.camera.autofocus"/>
Step 4: Build application.
Perform initialization by the VisionBase static class, to asynchronously obtain a connection to the service
private void initHuaweiHiAI(Context context){
VisionBase.init(context, new ConnectionCallback(){
@override
public void onServiceConnect(){
Log.i(TAG, "onServiceConnect");
}
@override
public void onServiceDisconnect(){
Log.i(TAG, "onServiceDisconnect");
}
});
}
Define the imageSegmentation instance, and use the context of this app as the input parameter.
ImageSegmentation imageSegmentation = new ImageSegmentation(this);
Set the model type.
SegmentationConfiguration sc = new SegmentationConfiguration();
sc.setSegmentationType(SegmentationConfiguration.TYPE_SEMANTIC);
imageSegmentation.setSegmentationConfiguration(sc);
Define VisionImage.
VisionImage image = null;
Place the Bitmap image to be processed in VisionImage.
image = VisionImage.fromBitmap(bitmap);
Define the segmentation result class.
ImageResult out = new ImageResult();
Call doSegmentation to obtain the segmentation result.
int resultcode = is.doSegmentation (image, out, null);
Convert the result into the Bitmap format.
Bitmap bmp = out.getBitmap();
Result​
Tips and Tricks​
Check dependencies downloaded properly.
Latest HMS Core APK is required.
Min SDK is 21. Otherwise, we get a Manifest merge issue.
If you are taking image from a camera or gallery make sure your app has camera and storage permission.
Add the downloaded huawei-hiai-vision-ove-10.0.4.307.aar, huawei-hiai-pdk-1.0.0.aar file to libs folder.
Conclusion​
In this article, we have learnt the following concepts.
What is Semantic segmentation?
Types of object identified and segmented
Features of sematic segmentation
How to integrate semantic segmentation using Huawei HiAI
How to Apply Huawei HiAI
How to build the application.
Reference​
Semantic Segmentation
Apply for Huawei HiAI
Happy coding

Related

Expert: Search product by Image category label using Huawei HiAI

Introduction
In this article, we will learn how to integrate Huawei image category labeling. We will build an application with smart search feature where using image from gallery or camera to find the similar products.
What is Huawei Image category labeling?
Image category labeling identifies image elements such as objects, scenes, and actions, including flower, bird, fish, insect, vehicle and building based on deep learning methods. It identifies 100 different categories of objects, scenes, actions, tags information, and applying cutting-edge intelligent image recognition algorithms for a high degree of accuracy.
Features
Abundant labels: Supports recognition of 280 types of common objects, scenes, and actions.
Multiple-label support: Adds multiple labels with different confidence scores to a single image.
High accuracy: Identifies categories accurately by utilizing industry-leading device-side intelligent image recognition algorithms.
How to integrate Image category labeling
Configure the application on the AGC.
Apply for HiAI Engine Library
Client application development process.
Configure application on the AGC
Follow the steps
Step 1: We need to register as a developer account in AppGallery Connect. If you are already a developer ignore this step.
Step 2: Create an app by referring to Creating a Project and Creating an App in the Project
Step 3: Set the data storage location based on the current location.
Step 4: Generating a Signing Certificate Fingerprint.
Step 5: Configuring the Signing Certificate Fingerprint.
Step 6: Download your agconnect-services.json file, paste it into the app root directory.
Apply for HiAI Engine Library
What is Huawei HiAI ?
HiAI is Huawei’s AI computing platform. HUAWEI HiAI is a mobile terminal–oriented artificial intelligence (AI) computing platform that constructs three layers of ecology: service capability openness, application capability openness, and chip capability openness. The three-layer open platform that integrates terminals, chips, and the cloud brings more extraordinary experience for users and developers.
How to apply for HiAI Engine?
Follow the steps
Step 1: Navigate to this URL, choose App Service > Development, and click HUAWEI HiAI.
{
"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"
}
Step 2: Click Apply for HUAWEI HiAI kit.
Step 3: Enter required information like Product name and Package name, click Next button.
Step 4: Verify the application details and click Submit button.
Step 5: Click the Download SDK button to open the SDK list.
Step 6: Unzip downloaded SDK and add it to your android project under the libs folder.
Step 7: Add jar files dependences into app build.gradle file.
Code:
implementation fileTree(include: ['*.aar', '*.jar'], dir: 'libs')
implementation 'com.google.code.gson:gson:2.8.6'
repositories {
flatDir {
dirs 'libs'
}
}
Client application development process
Follow the steps.
Step 1: Create an Android application in the Android studio (Any IDE which is your favorite).
Step 2: Add the App level Gradle dependencies. Choose inside project Android > app > build.gradle.
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
Root level gradle dependencies.
Code:
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Step 3: Add permission in AndroidManifest.xml
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.hardware.camera"/>
<uses-permission android:name="android.permission.HARDWARE_TEST.camera.autofocus"/>
Step 4: Build application.
Perform initialization by the VisionBase static class, to asynchronously obtain a connection to the service.
Code:
private void initHuaweiHiAI(Context context){
VisionBase.init(context, new ConnectionCallback(){
@Override
public void onServiceConnect(){
Log.i(TAG, "onServiceConnect");
}
@Override
public void onServiceDisconnect(){
Log.i(TAG, "onServiceDisconnect");
}
});
}
Define the labelDetector instance with context as parameter
Code:
LabelDetector labelDetector = new LabelDetector(getApplicationContext());
Place the Bitmap image to be processed in VisionImage
Code:
bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
VisionImage image = (bitmap == null) ? null : VisionImage.fromBitmap(bitmap);
Define Label, the image label result class.
Code:
Label label = new Label();
Call the detect method to obtain the label detection result.
Code:
int resultCode = labelDetector.detect(image, label, null);
Category definitions
Find all categories definition here.
Result
Tips and Tricks
Check dependencies downloaded properly.
Latest HMS Core APK is required.
Min SDK is 21
If you are taking images from a camera or gallery make sure your app has camera and storage permission.
Conclusion
In this article, we have learnt the following concepts.
What is Image category labeling?
Features of Image category labeling
How to integrate Image category labeling using Huawei HiAI
How to Apply Huawei HiAI
Search product by image label
Reference
Image Category Labeling
Find all categories definition here.
Apply for Huawei HiAI
Click to expand...
Click to collapse
Happy coding
Original Source

How to integrate semantic segmentation using Huawei HiAI

Introduction
In this article we will learn how to integrate Huawei semantic segmentation using Huawei HiAI.
What is Semantic Segmentation?
In simple “Semantic segmentation is the task of assigning a class to every pixel in a given image.”
Semantic segmentation performs pixel-level recognition and segmentation on a photo to obtain category information and accurate position information of objects in the image. The foregoing content is used as the basic information for semantic comprehension of the image, and can be subsequently used in multiple types of image enhancement processing.
Types of objects can be identified and segmented
People
Sky
Greenery (including grass and trees)
Food
Pet
Building
Flower
Water
Beach
Mountain
Features
Fast: This algorithm is currently developed based on the deep neural network, to fully utilize the NPU of Huawei mobile phones to accelerate the neural network, achieving an acceleration of over 10 times.
Lightweight: This API greatly reduces the computing time and ROM space the algorithm model takes up, making your app more lightweight.
How to integrate Semantic Segmentation
Configure the application on the AGC.
Apply for HiAI Engine Library
Client application development process.
Configure application on the AGC
Follow the steps
Step 1: We need to register as a developer account in AppGallery Connect. If you are already a developer ignore this step.
Step 2: Create an app by referring to Creating a Project and Creating an App in the Project
Step 3: Set the data storage location based on the current location.
Step 4: Generating a Signing Certificate Fingerprint.
Step 5: Configuring the Signing Certificate Fingerprint.
Step 6: Download your agconnect-services.json file, paste it into the app root directory.
Apply for HiAI Engine Library
What is Huawei HiAI ?
HiAI is Huawei’s AI computing platform. HUAWEI HiAI is a mobile terminal–oriented artificial intelligence (AI) computing platform that constructs three layers of ecology: service capability openness, application capability openness, and chip capability openness. The three-layer open platform that integrates terminals, chips, and the cloud brings more extraordinary experience for users and developers.
How to apply for HiAI Engine?
Follow the steps
Step 1: Navigate to this URL, choose App Service > Development and click HUAWEI HiAI.
{
"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"
}
Step 2: Click Apply for HUAWEI HiAI kit.
Step 3: Enter required information like Product name and Package name, click Next button.
Step 4: Verify the application details and click Submit button.
Step 5: Click the Download SDK button to open the SDK list.
Step 6: Unzip downloaded SDK and add into your android project under libs folder.
Step 7: Add jar files dependences into app build.gradle file.
Code:
implementation fileTree(include: ['*.aar', '*.jar'], dir: 'libs')
implementation 'com.google.code.gson:gson:2.8.6'
repositories {
flatDir {
dirs 'libs'
}
}
Client application development process
Follow the steps
Step 1: Create an Android application in the Android studio (Any IDE which is your favorite).
Step 2: Add the App level Gradle dependencies. Choose inside project Android > app > build.gradle.
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
Root level gradle dependencies.
Code:
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Step 3: Add permission in AndroidManifest.xml
Code:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.hardware.camera"/>
<uses-permission android:name="android.permission.HARDWARE_TEST.camera.autofocus"/>
Step 4: Build application.
Perform initialization by the VisionBase static class, to asynchronously obtain a connection to the service.
Code:
private void initHuaweiHiAI(Context context){
VisionBase.init(context, new ConnectionCallback(){
@Override
public void onServiceConnect(){
Log.i(TAG, "onServiceConnect");
}
@Override
public void onServiceDisconnect(){
Log.i(TAG, "onServiceDisconnect");
}
});
}
Define the imageSegmentation instance, and use the context of this app as the input parameter.
Code:
ImageSegmentation imageSegmentation = new ImageSegmentation(this);
Set the model type.
Code:
SegmentationConfiguration sc = new SegmentationConfiguration();
sc.setSegmentationType(SegmentationConfiguration.TYPE_SEMANTIC);
imageSegmentation.setSegmentationConfiguration(sc);
Define VisionImage.
Code:
VisionImage image = null;
Place the Bitmap image to be processed in VisionImage.
Code:
image = VisionImage.fromBitmap(bitmap);
Define the segmentation result class.
Code:
ImageResult out = new ImageResult();
Call doSegmentation to obtain the segmentation result.
Code:
int resultcode = is.doSegmentation (image, out, null);
Convert the result into the Bitmap format.
Code:
Bitmap bmp = out.getBitmap();
Result
Tips and Tricks
Check dependencies downloaded properly.
Latest HMS Core APK is required.
Min SDK is 21. Otherwise we get Manifest merge issue.
If you are taking image from a camera or gallery make sure your app has camera and storage permission.
Add the downloaded huawei-hiai-vision-ove-10.0.4.307.aar, huawei-hiai-pdk-1.0.0.aar file to libs folder.
Conclusion
In this article, we have learnt the following concepts.
What is Semantic segmentation?
Types of object identified and segmented
Features of sematic segmentation
How to integrate semantic segmentation using Huawei HiAI
How to Apply Huawei HiAI
How to build the application.
Reference
Semantic Segmentation
Apply for Huawei HiAI
Original Source
Very useful sharing, thanks

Correct your document before uploading to any application or website using Huawei Document Skew Correction by Huawei HiAI in Android

Introduction
In this article, we will learn how to integrate Huawei Document Skew Correction using Huawei HiAI. We will build the Document correction application. Where the application will detect document in the image.
About application:
Usually user Struggles a lot while uploading or filling any form due to document issue. This application helps them to take picture from the camera or from the gallery, it automatically detects document from the image.
Document skew correction is used to improve the document photography process by automatically identifying the document in an image. This actually returns the position of the document in the original image.
Document skew correction also adjusts the shooting angle of the document based on the position information of the document in the original image. This function has excellent performance in scenarios where photos of old photos, paper letters, and drawings are taken for electronic storage.
Features
Document detection: Recognizes documents in images and returns the location information of the documents in the original images.
Document correction: Corrects the document shooting angle based on the document location information in the original images, where areas to be corrected can be customized.
How to integrate Document Skew Correction
Configure the application on the AGC.
Apply for HiAI Engine Library.
Client application development process.
Configure application on the AGC
Follow the steps
Step 1: We need to register as a developer account in AppGallery Connect. If you are already a developer ignore this step.
Step 2: Create an app by referring to Creating a Project and Creating an App in the Project
Step 3: Set the data storage location based on the current location.
Step 4: Generating a Signing Certificate Fingerprint.
Step 5: Configuring the Signing Certificate Fingerprint.
Step 6: Download your agconnect-services.json file, paste it into the app root directory.
Apply for HiAI Engine Library
What is Huawei HiAI?
HiAI is Huawei’s AI computing platform. HUAWEI HiAI is a mobile terminal–oriented artificial intelligence (AI) computing platform that constructs three layers of ecology: service capability openness, application capability openness, and chip capability openness. The three-layer open platform that integrates terminals, chips, and the cloud brings more extraordinary experience for users and developers.
How to apply for HiAI Engine?
Follow the steps
Step 1: Navigate to this URL, choose App Service > Development and click HUAWEI HiAI.
{
"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"
}
Step 2: Click Apply for HUAWEI HiAI kit.
Step 3: Enter required information like Product name and Package name, click Next button.
Step 4: Verify the application details and click Submit button.
Step 5: Click the Download SDK button to open the SDK list.
Step 6: Unzip downloaded SDK and add into your android project under libs folder.
Step 7: Add jar files dependences into app build.gradle file.
Code:
implementation fileTree(include: ['*.aar', '*.jar'], dir: 'libs')
implementation 'com.google.code.gson:gson:2.8.6'
repositories {
flatDir {
dirs 'libs'
}
}
Client application development process
Follow the steps.
Step 1: Create an Android application in the Android studio (Any IDE which is your favorite).
Step 2: Add the App level Gradle dependencies. Choose inside project Android > app > build.gradle.
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
Root level gradle dependencies.
Code:
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Step 3: Add permission in AndroidManifest.xml
XML:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
Step 4: Build application.
1. Initialize Vision base.
Java:
private void initVisionBase(){
VisionBase.init(this, new ConnectionCallback() {
[USER=439709]@override[/USER]
public void onServiceConnect() {
mHandler.sendEmptyMessage(MSG_SERIVCE_CONNECTED);
}
[USER=439709]@override[/USER]
public void onServiceDisconnect() {
mHandler.sendEmptyMessage(MSG_SERIVCE_DISCONNECTED);
}
});
}
2. Request Read and write external storage Run time permissions.
Java:
private void requestPermissions() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permission1 = ActivityCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
int permission2 = ActivityCompat.checkSelfPermission(this,
Manifest.permission.CAMERA);
if (permission1 != PackageManager.PERMISSION_GRANTED || permission2 != PackageManager
.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 0x0010);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
3. Create the DocRefine instance
Java:
DocRefine docResolution = new DocRefine(this);
4. Create VisionImage instance. And add bitmap image input.
Java:
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
VisionImage img = VisionImage.fromBitmap(bitmap);
DocCoordinates docCoordinates = new DocCoordinates();
int result = docResolution.docDetect(img, docCoordinates, null);
ImageResult imgResult = new ImageResult();
int resultCode = docResolution.docRefine(img, docCoordinates, imgResult, null)
Bitmap bmp = imgResult.getBitmap();
Result
Tips and Tricks
Recommended image width and height: 1080 px and 2560 px.
Multi-thread invoking is currently not supported.
The document detection and correction API can only be called by 64-bit apps.
If you are taking Video from a camera or gallery make sure your app has camera and storage permission.
Add the downloaded huawei-hiai-vision-ove-10.0.4.307.aar, huawei-hiai-pdk-1.0.0.aar file to libs folder.
Check dependencies added properly.
Latest HMS Core APK is required.
Min SDK is 21. Otherwise you will get Manifest merge issue.
Conclusion
In this article, We have built an application where that detect the document in the image, and correct the document and it gives a result. we have learnt the following concepts.
1. What is Document skew correction?
2. Feature of Document skew correction.
3. How to integrate Document Skew correction using Huawei HiAI
4. How to Apply Huawei HiAI
5. How to build the application
Reference
Document skew correction
Apply for Huawei HiAI
Happy coding

Save Contacts from QR Code using Huawei Code Recognition by Huawei HiAI in Android

Introduction
In this article we will learn how to integrate Code Recognition. We will build the contact saving application from QR code using Huawei HiAI.
Code recognition identifies the QR codes and bar codes to obtain the contained information, based on which the service framework is provided.
This API can be used to parse QR codes and bar codes in 11 scenarios including Wi-Fi and SMS, providing effective code detection and result-based service capabilities. This API can be widely used in apps that require code scanning services.
Software requirements
Any operating system (MacOS, Linux and Windows).
Any IDE with Android SDK installed (IntelliJ, Android Studio).
HiAI SDK.
Minimum API Level 23 is required.
Required EMUI 9.0.0 and later version devices.
Required process kirin 990/985/980/970/ 825Full/820Full/810Full/ 720Full/710Full
How to integrate Code Recognition.
Configure the application on the AGC.
Apply for HiAI Engine Library.
Client application development process.
Configure application on the AGC
Follow the steps.
Step 1: We need to register as a developer account in AppGallery Connect. If you are already a developer ignore this step.
Step 2: Create an app by referring to Creating a Project and Creating an App in the Project
Step 3: Set the data storage location based on the current location.
Step 4: Generating a Signing Certificate Fingerprint.
Step 5: Configuring the Signing Certificate Fingerprint.
Step 6: Download your agconnect-services.json file, paste it into the app root directory.
Apply for HiAI Engine Library
What is Huawei HiAI?
HiAI is Huawei’s AI computing platform. HUAWEI HiAI is a mobile terminal–oriented artificial intelligence (AI) computing platform that constructs three layers of ecology: service capability openness, application capability openness, and chip capability openness. The three-layer open platform that integrates terminals, chips, and the cloud brings more extraordinary experience for users and developers.
How to apply for HiAI Engine?
Follow the steps.
Step 1: Navigate to this URL, choose App Service > Development and click HUAWEI HiAI.
{
"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"
}
Step 2: Click Apply for HUAWEI HiAI kit.
Step 3: Enter required information like Product name and Package name, click Next button.
Step 4: Verify the application details and click Submit button.
Step 5: Click the Download SDK button to open the SDK list.
Step 6: Unzip downloaded SDK and add into your android project under libs folder.
Step 7: Add jar files dependences into app build.gradle file.
Code:
implementation fileTree(include: ['*.aar', '*.jar'], dir: 'libs')
implementation 'com.google.code.gson:gson:2.8.6'
repositories {
flatDir {
dirs 'libs'
}
}
Client application development process
Follow the steps.
Step 1: Create an Android application in the Android studio (Any IDE which is your favorite).
Step 2: Add the App level Gradle dependencies. Choose inside project Android > app > build.gradle.
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
Root level gradle dependencies.
Code:
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Step 3: Add permission in AndroidManifest.xml.
XML:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
Step 4: Build application.
Java:
Bitmap bitmap;
List<Barcode> codes;
private void initVisionBase() {
VisionBase.init(this, new ConnectionCallback() {
@Override
public void onServiceConnect() {
}
@Override
public void onServiceDisconnect() {
}
});
}
private void saveContact() {
if (codes != null && codes.size() > 0) {
Log.d("New data: ", "" + new Gson().toJson(codes));
String contactInfo = new Gson().toJson(codes.get(0));
ContactInfo info = new Gson().fromJson(contactInfo, ContactInfo.class);
Intent i = new Intent(Intent.ACTION_INSERT);
i.setType(ContactsContract.Contacts.CONTENT_TYPE);
i.putExtra(ContactsContract.Intents.Insert.NAME, info.getContactInfo().getPerson().getName());
i.putExtra(ContactsContract.Intents.Insert.PHONE, info.getContactInfo().getPhones().get(0).getNumber());
i.putExtra(ContactsContract.Intents.Insert.EMAIL, info.getContactInfo().getEmails().get(0).getAddress());
if (Integer.valueOf(Build.VERSION.SDK) > 14)
i.putExtra("finishActivityOnSaveCompleted", true); // Fix for 4.0.3 +
startActivityForResult(i, PICK_CONTACT_REQUEST);
} else {
Log.e("Data", "No Data");
}
}
class QRCodeAsync extends AsyncTask<Void, Void, List<Barcode>> {
Context context;
public QRCodeAsync(Context context) {
this.context = context;
}
@Override
protected List<Barcode> doInBackground(Void... voids) {
BarcodeDetector mBarcodeDetector = new BarcodeDetector(context);//Construct Detector.
VisionImage image = VisionImage.fromBitmap(bitmap);
ZxingBarcodeConfiguration config = new ZxingBarcodeConfiguration.Builder()
.setProcessMode(VisionTextConfiguration.MODE_IN)
.build();
mBarcodeDetector.setConfiguration(config);
mBarcodeDetector.detect(image, null, new VisionCallback<List<Barcode>>() {
@Override
public void onResult(List<Barcode> barcodes) {
if (barcodes != null && barcodes.size() > 0) {
codes = barcodes;
} else {
Log.e("Data", "No Data");
}
}
@Override
public void onError(int i) {
}
@Override
public void onProcessing(float v) {
}
});
return codes;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
}
Result
Tips and Tricks
An error code is returned if the size of an image input to the old API exceeds 20 MP. In this case, rescale the image for improved input efficiency and lower memory usage.
There are no restrictions on the resolution of the image input to the new API. However, an image larger than 224 x 224 in size and less than 20 MP is recommended.
If you are taking Video from a camera or gallery make sure your app has camera and storage permission.
Add the downloaded huawei-hiai-vision-ove-10.0.4.307.aar, huawei-hiai-pdk-1.0.0.aar file to libs folder.
Check dependencies added properly.
Latest HMS Core APK is required.
Min SDK is 21. Otherwise you will get Manifest merge issue.
Conclusion
In this article, we have built contact saving application and parsing the QR code image from gallery.
We have learnt the following concepts.
Introduction of Code Recognition?
How to integrate Code Recognition using Huawei HiAI
How to Apply Huawei HiAI
How to build the application
Reference
Code Recognition
Apply for Huawei HiAI
Happy coding
thanks for sharing!!

Convert Image to document using Huawei HiAI Engine in Android

Introduction
In this article, we will learn how to convert image to document such as PPT or pdf format. As for users, it is inefficient to manually organize, edit, or improve the note-taking snapshots at conferences or images of paper documents.
Document converter enables apps to convert document images into electronic documents conveniently, such as PPT files. It can recognize documents and the texts in images, and return the recognized content to the client, which will restore the results into a PPT file.
How to integrate Document Converter
1. Configure the application on the AGC.
2. Apply for HiAI Engine Library.
3. Client application development process.
Configure application on the AGC
Follow the steps
Step 1: We need to register as a developer account in AppGallery Connect. If you are already a developer ignore this step.
Step 2: Create an app by referring to Creating a Project and Creating an App in the Project
Step 3: Set the data storage location based on the current location.
Step 4: Generating a Signing Certificate Fingerprint.
Step 5: Configuring the Signing Certificate Fingerprint.
Step 6: Download your agconnect-services.json file, paste it into the app root directory.
Apply for HiAI Engine Library
What is Huawei HiAI?
HiAI is Huawei’s AI computing platform. HUAWEI HiAI is a mobile terminal–oriented artificial intelligence (AI) computing platform that constructs three layers of ecology: service capability openness, application capability openness, and chip capability openness. The three-layer open platform that integrates terminals, chips, and the cloud brings more extraordinary experience for users and developers.
How to apply for HiAI Engine?
Follow the steps
Step 1: Navigate to this URL, choose App Service > Development and click HUAWEI HiAI.
{
"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"
}
Step 2: Click Apply for HUAWEI HiAI kit.
Step 3: Enter required information like Product name and Package name, click Next button.
Step 4: Verify the application details and click Submit button.
Step 5: Click the Download SDK button to open the SDK list.
Step 6: Unzip downloaded SDK and add into your android project under libs folder.
Step 7: Add jar files dependences into app build.gradle file.
implementation fileTree(include: ['*.aar', '*.jar'], dir: 'libs')
implementation 'com.google.code.gson:gson:2.8.6'
repositories {
flatDir {
dirs 'libs'
}
}Copy codeCopy code
Client application development process
Follow the steps.
Step 1: Create an Android application in the Android studio (Any IDE which is your favorite).
Step 2: Add the App level Gradle dependencies. Choose inside project Android > app > build.gradle.
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.huawei.agconnect'
Root level gradle dependencies.
Code:
maven { url 'https://developer.huawei.com/repo/' }
classpath 'com.huawei.agconnect:agcp:1.4.1.300'
Step 3: Add permission in AndroidManifest.xml
XML:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
Step 4: Build application.
Request the runtime permission
Java:
private void requestPermissions() {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int permission1 = ActivityCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
int permission2 = ActivityCompat.checkSelfPermission(this,
Manifest.permission.CAMERA);
if (permission1 != PackageManager.PERMISSION_GRANTED || permission2 != PackageManager
.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.CAMERA}, 0x0010);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Java:
private void convertDocument() {
DocConverter docConverter = new DocConverter(this);//Construct Detector.
VisionImage image = VisionImage.fromBitmap(mBitmap);
VisionTextConfiguration config = new VisionTextConfiguration.Builder()
.setAppType(VisionTextConfiguration.APP_NORMAL)
.setProcessMode(VisionTextConfiguration.MODE_IN)
.setDetectType(TextDetectType.TYPE_TEXT_DETECT_FOCUS_SHOOT)
.setLanguage(VisionTextConfiguration.ENGLISH)
.build();
DocConverterConfiguration docConfig = new DocConverterConfiguration.Builder().build();
docConfig.setTextConfig(config);
MyCallBack cb = new MyCallBack();
int result_code = docConverter.detectSlide(image, cb);
}
class MyCallBack implements SlideCallback {
public void onDocDetect(DocCoordinates coor) {
Log.d("MainActivity", coor.toString());
}
public void onDocRefine(Bitmap bitmap) {
}
public void onSuperResolution(Bitmap bitmap) {
//Set super resolution image to image view
}
public void onTextRecognition(Text text) {
Log.d("MainActivity", text.getValue());
mTxtViewResult.setText(text.getValue());
}
public void onError(int errorCode) {
Log.d("MainActivity", "Error code: "+errorCode);
}
}
Result
Tips and Tricks
An image with a width ranging from 1080 pixels to 2560 pixels is recommended.
Multi-thread invoking is currently not supported.
If you are taking Video from a camera or gallery make sure your app has camera and storage permissions.
Add the downloaded huawei-hiai-vision-ove-10.0.4.307.aar, huawei-hiai-pdk-1.0.0.aar file to libs folder.
Check dependencies added properly.
Latest HMS Core APK is required.
Min SDK is 21. Otherwise you will get Manifest merge issue.
Conclusion
In this article, we have learnt what is the document convertor using Huawei HiAI using android and java. We have learnt how to convert the image to pdf. Huawei HiAI gives immense control on the text from image.
Reference
Document convertor
Apply for Huawei HiAI
Can we get the same content format of document after image is converted into text?

Categories

Resources