简体   繁体   English

Android Vision Api - 条形码检测如何获取条形码类型?

[英]Android Vision Api - Barcode detection how to get type of barcode?

I am working with Android Google Vision API , and have created a standard barcode reader, but I want to detect what type/format of barcode is read ie CODE 39 , CODE 128 , QR Code .... etc. 我正在使用Android Google Vision API ,并创建了标准条形码阅读器,但我想检测条形码的类型/格式,即CODE 39CODE 128QR Code ....等。
Is there anyway to return the type? 反正有没有返回类型?

Thanks 谢谢

Because I does not found any bulid-in function to decode Format integer value to text value 因为我没有找到任何bulid-in函数来解码格式整数值到文本值
I used following custom method 我使用以下自定义方法

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 "";
    }
}

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

Using 运用

format 格式

you can get the barcode type this is retuned as an integer. 你可以得到条形码类型,这是一个整数重新调整。

valueFormat returns the type, it can match the static variables of the API. valueFormat返回类型,它可以匹配API的静态变量。 Example: 例:

    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 ....
......
.

and the codes you can find them in the class Barcode.class 以及您可以在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;

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM