Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了使用android vision Text OCR构建名片阅读器大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用谷歌的 Android移动视觉OCR文本构建一个Android应用程序,用于输入名片作为手机中的联系人.

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

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

OCR图形类检测方法>>>

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类

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/vision/text/Text

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

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

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

b-)我在Graphic类中使用Timer Task如何在它完成时杀死它或者@R_233_10675@用其他方法

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

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

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

f-)在某些时候,我们可以在所有标志都成立后停止OCR库检测任何进一步的文本.或者只是任何方式?

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

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

解决方法

我可以帮助其中一些.

List<Line> lines = (List<Line>) textBlock.getComponents();

可能需要迭代TextBlock SparseArray以获取每个块行.此外,这种方法也可以从每一行获取每个元素. getComponents()方法位于Text接口中,所有文本项都实现.

您可以计算OcrDetectorProcessor中收到的检测数,并在收到设定数量时将其终止.

您可以通过停止Camerasource来阻止管道检测.在OcrCaptureActivity的CodeLabs示例中,这是在onPause和onDestroy中完成的.通过停止和释放mPreview,应用程序停止并清理相机的挂钩.

我希望这有帮助.

大佬总结

以上是大佬教程为你收集整理的使用android vision Text OCR构建名片阅读器全部内容,希望文章能够帮你解决使用android vision Text OCR构建名片阅读器所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。