【问题标题】:Android Vision Api - Barcode detection how to get type of barcode?Android Vision Api - 条码检测如何获取条码类型?
【发布时间】:2018-01-26 07:21:51
【问题描述】:

我正在使用 Android Google Vision API,并创建了一个标准条形码阅读器,但我想检测 读取的条形码类型/格式,即 CODE 39CODE 128QR Code....等
反正有返回类型吗?

谢谢

【问题讨论】:

    标签: java android barcode google-vision vision


    【解决方案1】:

    因为我没有找到任何内置函数来将格式整数值解码为文本值
    我使用了以下自定义方法

    private String decodeFormat(int format) {
        switch (format){
            case Barcode.CODE_128:
                return "CODE_128";
            case Barcode.CODE_39:
                return "CODE_39";
            case Barcode.CODE_93:
                return "CODE_93";
            case Barcode.CODABAR:
                return "CODABAR";
            case Barcode.DATA_MATRIX:
                return "DATA_MATRIX";
            case Barcode.EAN_13:
                return "EAN_13";
            case Barcode.EAN_8:
                return "EAN_8";
            case Barcode.ITF:
                return "ITF";
            case Barcode.QR_CODE:
                return "QR_CODE";
            case Barcode.UPC_A:
                return "UPC_A";
            case Barcode.UPC_E:
                return "UPC_E";
            case Barcode.PDF417:
                return "PDF417";
            case Barcode.AZTEC:
                return "AZTEC";
            default:
                return "";
        }
    }
    

    【讨论】:

      【解决方案2】:

      在文档中找到它(之前错过了)。 https://developers.google.com/android/reference/com/google/android/gms/vision/barcode/Barcode

      使用

      格式

      你可以得到条形码类型,它被重新调整为一个整数。

      【讨论】:

        【解决方案3】:

        valueFormat返回类型,可以匹配API的静态变量。 示例:

            final SparseArray <Barcode> barcodes = detections.getDetectedItems ();
            if (barcodes.size ()! = 0) {
                            txtBarcodeValue.post (new Runnable () {
                                @Override
                                public void run () {
                                    System.out.println ("barcodes");
                                    System.out.println (barcodes.valueAt (0) .format); // 256
                                    System.out.println (barcodes.valueAt (0) .valueFormat); // 1 or 2 or 3 ....
        ......
        .
        

        以及您可以在 Barcode.class 类中找到它们的代码

        public static final int CONTACT_INFO = 1;
            public static final int EMAIL = 2;
            public static final int ISBN = 3;
            public static final int PHONE = 4;
            public static final int PRODUCT = 5;
            public static final int SMS = 6;
            public static final int TEXT = 7;
            public static final int URL = 8;
            public static final int WIFI = 9;
            public static final int GEO = 10;
        

        【讨论】:

          猜你喜欢
          • 2017-06-30
          • 1970-01-01
          • 2018-07-30
          • 1970-01-01
          • 2016-11-21
          • 2020-06-19
          • 1970-01-01
          • 2021-11-21
          • 1970-01-01
          相关资源
          最近更新 更多