使用android vision Text OCR构建名片阅读器 [英] Building Business Cards Reader using android vision Text OCR

查看:133
本文介绍了使用android vision Text OCR构建名片阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个Android应用程序,使用谷歌的Android移动视觉OCR文本输入名片作为手机中的联系人。

I am building an android app using google's android mobile vision OCR Text for entry of Business Cards as contacts in the phone.

到目前为止,我能够识别任何拉丁语生成的文本,并且能够在代码块上应用正则表达式

So far i have able to recognize any Latin Generated Text and have been able to apply regex on the block of code

我所做的是我为五个变量名称,电子邮件创建了一个Contacts bean类, compnayname,website,adrs,phnno
对正在生成的实时数据应用正则表达式后,我将过滤结果并将它们保存在bean类
类型的对象中,并将该对象传递给活动并提取数据存储在该对象中并在我的文本视图中显示。

What i have done is that i have created a Contacts bean class for five Variables name,email,compnayname,website,adrs,phnno After applying regex on the live data being generated i am filtering the results and saving them in an object of type bean class and passing that object to the activity and extract the data stored in that object and display it in my text views.

OCR图形类检测方法>>>

The OCR graphic class detection method>>>

List<? extends Text> textComponents = text.getComponents();
        for(final  Text currentText : textComponents) {
            float left = translateX(currentText.getBoundingBox().left);
            float bottom = translateY(currentText.getBoundingBox().bottom);
            canvas.drawText(currentText.getValue(), left, bottom, sTextPaint);
            if (currentText != null && currentText.getValue() != null) {
                //stringList.add(currentText.getValue());

                Log.e("OCrGraphic", "Text detected! " + currentText.getValue());

                if (isCompany== false && currentText.getValue().matches(".[A-Z].[^@$#/-<>!]+")) {
                    Log.e("currentTextcompanyName", currentText.getValue());
                    companyName = "";
                    companyName = currentText.getValue();
                    isCompany = true;
                    contactsBeans.setCompanyName(companyName);
                }

                if (isEmail == false && currentText.getValue().matches("^[_A-Za-z0-9-\\\\+]+(\\\\.[_A-Za-z0-9-]+)*@\"\n" +
                        "\t\t+ \"[A-Za-z0-9-]+(\\\\.[A-Za-z0-9]+)*(\\\\.[A-Za-z]{2,})$") || currentText.getValue().contains("@")) {
                    Log.e("currentTextemail", currentText.getValue());
                    email = "";
                    email = currentText.getValue();
                    isEmail = true;
                    contactsBeans.setEmail(email);

                }
               // Patterns.WEB_URL.matcher(currentText.getValue()).matches();
                if (isWebsite == false && currentText.getValue().matches("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]") || currentText.getValue().startsWith("www") || currentText.getValue().contains("Website") || currentText.getValue().contains("www")) {
                    Log.e("currentTextWebsite", currentText.getValue());
                    website = "";
                    website = currentText.getValue();
                    isWebsite = true;
                    contactsBeans.setWebsite(website);

                }
                if (isName== false && currentText.getValue().matches("[a-zA-z]+([ '-][a-zA-Z]+)*")) {
                    Log.e("name", currentText.getValue());
                    name = "";
                    name = currentText.getValue();
                    isName = true;
                    contactsBeans.setName(name);
                }

                if (isPhone == false && !currentText.getValue().contains("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") && currentText.getValue().startsWith("+") || currentText.getValue().startsWith("0") && currentText.getValue().contains("+-0123456789/-#") ) {
                    Log.e("currentTextphone", currentText.getValue());
                    phone = "";
                    phone = currentText.getValue();
                    isPhone = true;
                    contactsBeans.setPhone(phone);
                }

                if (isAdrs == false &&currentText.getValue().matches("[a-zA-z]+([ '-][a-zA-Z]+)*") && currentText.getValue().contains("Address") || currentText.getValue().contains("Office") || currentText.getValue().contains("Floor") || currentText.getValue().contains("Plaza") || currentText.getValue().contains("office") || currentText.getValue().contains("Floor")|| currentText.getValue().contains("Floors")|| currentText.getValue().contains("floors")|| currentText.getValue().contains("floor")|| currentText.getValue().contains("Street")|| currentText.getValue().contains("Road")) {
                    address = "";
                    address = currentText.getValue();
                    isAdrs = true;
                    contactsBeans.setAddress(address);
                    Log.e("currentTextaddress", currentText.getValue());
                }

                timer = new Timer();
                timer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        context = ApplicationController.getContext();
                        Intent intent = new Intent(context,ContactsEditActivity.class);
                 /*       Log.e("CBname",contactsBeans.getName());
                        Log.e("CBemail",contactsBeans.getEmail());
                        Log.e("CBadrs",contactsBeans.getAddress());
                        Log.e("CBwebsite",contactsBeans.getWebsite());
                        Log.e("CBcomp",contactsBeans.getCompanyName());
                        Log.e("CBphone",contactsBeans.getPhone());*/
                        intent.putExtra("contactsList",contactsBeans);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
                        // intent.putStringArrayListExtra("contactsList",stringList);
                        context.startActivity(intent);
                    }
                },6000,6000);

             /*



           */
} 

Contacs Bean parceable class

Contacs Bean parceable class

public class ContactsBeans implements Parcelable {
    String name;
    String phone;String email;String companyName;
    String address; String website;
    public List<ContactsBeans> selectedContactsAttribute;

    public ContactsBeans() {
    }

    public ContactsBeans(List<ContactsBeans> selectedContactsAttribute) {
        this.selectedContactsAttribute = selectedContactsAttribute;
    }

    public ContactsBeans(String name, String phone, String email, String companyName, String address, String website) {

        this.name = name;
        this.phone = phone;
        this.email = email;
        this.companyName = companyName;
        this.address = address;
        this.website = website;
    }

    protected ContactsBeans(Parcel in) {
        name = in.readString();
        phone = in.readString();
        email = in.readString();
        companyName = in.readString();
        address = in.readString();
        website = in.readString();
        selectedContactsAttribute = in.createTypedArrayList(ContactsBeans.CREATOR);
    }

    public static final Creator<ContactsBeans> CREATOR = new Creator<ContactsBeans>() {
        @Override
        public ContactsBeans createFromParcel(Parcel in) {
            return new ContactsBeans(in);
        }

        @Override
        public ContactsBeans[] newArray(int size) {
            return new ContactsBeans[size];
        }
    };

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getWebsite() {
        return website;
    }

    public void setWebsite(String website) {
        this.website = website;
    }

    public List<ContactsBeans> getSelectedContactsAttribute() {
        return selectedContactsAttribute;
    }

    public void setSelectedContactsAttribute(List<ContactsBeans> selectedContactsAttribute) {
        this.selectedContactsAttribute = selectedContactsAttribute;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(name);
        dest.writeString(phone);
        dest.writeString(email);
        dest.writeString(companyName);
        dest.writeString(address);
        dest.writeString(website);
        dest.writeTypedList(selectedContactsAttribute);
    }
}

https://developers.google.com/android/reference/com/google/android/gms/愿景/文字/文字

https://codelabs.developers.google.com/codelabs/mobile-vision-ocr/#6

I已经按照上面的教程
我有以下问题

I have followed the above tutorial I have the following questions

a-)如何使用文本行而不是文本块?

a-) How to use Text Lines instead of text blocks?

b-)我在Graphic类中使用Timer Task如何在它完成后杀死它或者我应该使用其他方法吗?

b-) I am using Timer Task in the Graphic class how to kill it when it's done or should i use some other approach?

c - )是否有任何应用程序,我还没有找到一个使用视觉OCR进行名片输入,他们说它虽然可以吗?

c-) Is there any app, i haven't found one which is using vision OCR for Business Card entry, they say it ca though?

d-)我的正则表达式exp是否在Java的单独IDE中进行了正确的测试?

d-) My regex exp are correct tested in a separate IDE for Java any suggestions?

e-)我使用额外的意图来获取存储在contacts bean对象中的数据并将其显示在活动中,它就像雪球永远不会停止我已经在我的 IF STATEMENTS中添加了标记。

e-) I am using intents extra to take the data stored in the contacts bean object and display it in the activity, it just goes like a snow ball never stops although i have put flags in my IF STATEMENTS .

f-)在某些时候,我们可以阻止OCR库检测到任何其他文本在所有的旗帜都成真之后。或者只是任何方式?

f-) Can at some point,we can stop the OCR library from detecting any further text after all the flags have gone true. or just any way?

g-)无论条件是否为真,它都会一直覆盖我的变量?

g-)It keeps overriding my variables regardless the condition is true or not?

所有的帮助都会受到高度重视。
感谢分配。

All the help would be highly regarded. Thanks allot.

推荐答案

对于a)点 - 你也可以使用:

for point a)- you can also use :

 List<Line> lines = (List<Line>) text.getComponents();
        for(Line elements : lines){
            Log.i("current lines ", ": " + elements.getValue());
        }

这篇关于使用android vision Text OCR构建名片阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆