FORUMS

How to use HUAWEI ML Kit service to quickly develop a photo translation app

34 posts
Thanks Meter: 2
 
By Jack Wu Shenzhen, Member on 15th June 2020, 04:30 AM
Post Reply Email Thread
Photo translation app is quite useful when traveling abroad and this article will help the developers build this app in short time. We use HUAWEI ML kit help to build this app and this will largely accelerate the whole development process.
Introduction
There must be a lot of friends who like to travel. Sometimes it's better to go abroad for a tour. Before the tour, we will make all kinds of strategies for eating, wearing, living, traveling and playing routes.
Imaginary tourism:
Before departure, the imagined tourist destination may have beautiful buildings:

Delicious food

Beautiful women

Carefree life

Actual tourism:
But in reality, if you go to a place where the language is different from ur mother tongue, you may encounter the following problems:
A confusing map

Unreadable menu

Street sign

That's too hard to travel abroad without any translation tool !!!

Photo translator will help you
With text recognition and translation services, none of the above is a problem. There are only two steps to complete the development of photo translation small application:
Text recognition
First take a photo and then send the image to Huawei HMS ml kit text recognition service for text recognition
Huawei's text recognition service provides offline SDK (end side) and cloud side at the same time. The end side is free and can be detected in real time, and the cloud side recognition type and accuracy are higher. In this actual battle, we use the capabilities provided by cloud side.

Photo translation app development
1 Development preparation
Due to the use of cloud services, it is necessary to register the developer account with Huawei's developer alliance and open these services in the cloud. Here we will not go into details, just follow the operation steps of the official appgallery connect configuration and service opening:
Registered developer, open service reference please go to:
https://developer.huawei.com/consume...enable-service
1.1 add Maven in project level gradle
Open the Android studio project level build.gradle file.

Add the maven address
Code:
buildscript {
    repositories {        
        maven {url 'http://developer.huawei.com/repo/'}
    }    }allprojects {
    repositories {       
        maven { url 'http://developer.huawei.com/repo/'}
    }}
1.2 add SDK dependency in application level build.gradle

Integrated SDK. (Due to the use of cloud-side capabilities, only SDK basic packages can be introduced)
Code:
dependencies{  
    implementation 'com.huawei.hms:ml-computer-vision:1.0.2.300'
    implementation 'com.huawei.hms:ml-computer-translate:1.0.2.300'}
1.3 apply for camera and storage permission in Android manifest.xml file
Code:
<uses-permission android:name="android.permission.CAMERA" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><uses-feature android:name="android.hardware.camera" /><uses-feature android:name="android.hardware.camera.autofocus" />
Two key steps of code development

2.1 dynamic authority application
Code:
private static final int CAMERA_PERMISSION_CODE = 1; @Override 
public void onCreate(Bundle savedInstanceState) { 
    // Checking camera permission   
   if (!allPermissionsGranted()) {
       getRuntimePermissions();
   }}
2.2 create a cloud text analyzer. You can create a text analyzer from the text detection configurator "mlremotetextsetting".
Code:
MLRemoteTextSetting setting = (new MLRemoteTextSetting.Factory()).
         setTextDensityScene(MLRemoteTextSetting.OCR_LOOSE_SCENE).create();this.textAnalyzer = MLAnalyzerFactory.getInstance().getRemoteTextAnalyzer(setting);
2.3 create "mlframe" object through android.graphics.bitmap for analyzer to detect pictures.
Code:
MLFrame mlFrame = new MLFrame.Creator().setBitmap(this.originBitmap).create();
2.4 call "asyncanalyseframe" method for text detection.
Code:
Task<MLText> task = this.textAnalyzer.asyncAnalyseFrame(mlFrame);
            task.addOnSuccessListener(new OnSuccessListener<MLText>() {
                @Override                public void onSuccess(MLText mlText) {
                    // Transacting logic for segment success.
                    if (mlText != null) {
                        RemoteTranslateActivity.this.remoteDetectSuccess(mlText);
                    } else {
                        RemoteTranslateActivity.this.displayFailure();
                    }
                }
            }).addOnFailureListener(new OnFailureListener() {
                @Override                public void onFailure(Exception e) {
                    // Transacting logic for segment failure.
                    RemoteTranslateActivity.this.displayFailure();
                    return;
                }
            });
2.5 create a text translator. You can create a translator through class "mlremotetranslatesetting".
Code:
MLRemoteTranslateSetting.Factory factory = new MLRemoteTranslateSetting
                .Factory()
                // Set the target language code. The ISO 639-1 standard is used.
                .setTargetLangCode(this.dstLanguage);
        if (!this.srcLanguage.equals("AUTO")) {
            // Set the source language code. The ISO 639-1 standard is used.
            factory.setSourceLangCode(this.srcLanguage);
        }
        this.translator = MLTranslatorFactory.getInstance().getRemoteTranslator(factory.create());
2.6 call "asyncanalyseframe" method to translate the content obtained by text recognition.
Code:
final Task<String> task = translator.asyncTranslate(this.sourceText);
        task.addOnSuccessListener(new OnSuccessListener<String>() {
            @Override            public void onSuccess(String text) {
                if (text != null) {
                    RemoteTranslateActivity.this.remoteDisplaySuccess(text);
                } else {
                    RemoteTranslateActivity.this.displayFailure();
                }
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override            public void onFailure(Exception e) {
                RemoteTranslateActivity.this.displayFailure();
            }
        });
2.7 release resources after translation.
Code:
if (this.textAnalyzer != null) {
            try {
                this.textAnalyzer.close();
            } catch (IOException e) {
                SmartLog.e(RemoteTranslateActivity.TAG, "Stop analyzer failed: " + e.getMessage());
            }
        }
        if (this.translator != null) {
            this.translator.stop();
        }
3 source code
The demo source code has been uploaded to GitHub(the project directory is: Photo translate). You can do scene based optimization for reference.
https://github.com/HMS-MLKit/HUAWEI-HMS-MLKit-Sample
4 demo


5 Brainstorming
The app development demonstrats how to use the two cloud side capabilities of Huawei HMS ml kit, text recognition and translation. Huawei's text recognition and translation can also help developers to do many other interesting and powerful functions, such as:
[general text recognition]
1. text recognition of bus license plate
2. Text recognition in document reading
[card recognition]
1. The card number of the bank card can be identified through text recognition, which is used in the scenarios such as bank card binding, etc
2. Of course, in addition to identifying bank cards, you can also identify various card numbers in your life, such as membership cards and preferential cards
3. In addition, it can also realize the identification of ID card, Hong Kong and Macao pass and other certificate numbers
[translation]
1. Signpost and signboard translation
2. Document translation
3. Web page translation, such as identifying the language type of the comment area of the website and translating it into the language of the corresponding country;
4. Introduction and translation of overseas products
5. Translation of restaurant order menu

FOR MORE REFERENCE PLZ CLICK:
https://developer.huawei.com/consume...introduction-4
24th June 2020, 12:34 AM |#2  
Junior Member
Thanks Meter: 1
 
More
Thanks for the guide. I'm not sure that this application is suitable for high-quality translation of documents, as machine translators do this poorly, but otherwise it looks very simple and convenient. I travel often for work and I really need good translations. For documents and business, I use a quality translation service https://thewordpoint.com/services/tr...rvice/business , which I really trust. And for everyday transfers abroad I will try this application.
The Following User Says Thank You to rikkirose For This Useful Post: [ View ] Gift rikkirose Ad-Free
24th June 2020, 03:46 AM |#3  
OP Member
Flag shenzhen
Thanks Meter: 2
 
More
Reply to rikkirose
Quote:
Originally Posted by rikkirose

Thanks for the guide. I'm not sure that this application is suitable for high-quality translation of documents, as machine translators do this poorly, but otherwise it looks very simple and convenient.


Hi,rikkirose,document translation is not yet supported, and it is expected to be supported in August this year. Currently,High-quality translation, the key areas of optimization are news, travel, technology, and social. If it is not within those scopes, and if you really want to try it, you can provide us sample, we can do verification and quality improvement for you.

Please feel free to email and transfer the sample and detail requirement to this email:[email protected]
26th June 2020, 07:14 AM |#4  
Junior Member
Flag Bangalore
Thanks Meter: 0
 
More
Hi,

Nice Post. Can we use Huawei ML Kit to translate our communication to other languages. It will help tourists to communicate. Is it possible.???
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes