使用Android vision API检测条形码

时间:2016-09-20 09:44:43

标签: android google-vision

我正在尝试使用google android vision API来检测条形码。相机帧由外部UVCCamera生成,它提供java.nio.DirectByteBuffer帧。我试图通过将public Frame.Builder setImageData (ByteBuffer data, int width, int height, int format)对象作为bytebuffer传递来使用方法java.nio.ByteBufferArray来解析条形码。 UVCCamera帧的像素格式为NV21格式。但我没有得到任何结果,没有错误或例外。

Configuraions

SDK: 23
google pla service: 33
vision api: 'com.google.android.gms:play-services-vision:9.4.0+'

但是在samples中,传递给方法的是java.nio.ByteArrayBuffer(在使用ByteBuffer.wrap(byteArray)包装字节数组之后)

以下是我使用的示例代码[请注意,它是代码的简化版本,实际上在线程上运行]:

public void process(ByteBuffer mPendingFrameData) 
{
    byte[] arr = new byte[frame.remaining()];
    frame.get(arr);
    ByteBuffer buf = ByteBuffer.wrap( arr );

    Frame outputFrame = null;

    while (true) 
    {
        try
        {
            mPendingFrameData.clear();
            outputFrame = new Frame.Builder().setImageData( buf, 640, 480, ImageFormat.NV21).build();

            if( detector.isOperational() )
            {
                SparseArray<Barcode> barcodes = detector.detect(outputFrame);

                if(barcodes.size()!=0)
                {
                    Barcode barcodeValue = barcodes.valueAt(0);
                    System.out.println(barcodeValue.rawValue);
                }
            }
        }
        catch( Exception e )
        {
            System.out.println(e.getMessage());
        }
    }
}

我创建另一个缓冲区的原因是创建一个ByteBufferArray。

任何人都可以告诉我这里缺少的部分是什么?

0 个答案:

没有答案