在PreviewFrame上使用Zxing Library來增強現實

[英]Use Zxing Library on PreviewFrame for Augmented Reality


Can someone tell me how I can use the Zxing Library for an Augmented Reality App? I know the easiest way to use Zxing is via Intent, but I need the Camera View so I can not use the barcode App.

有人能告訴我如何使用Zxing Library增強現實應用程序嗎?我知道使用Zxing的最簡單的方法是通過Intent,但我需要Camera View,所以我不能使用條形碼應用程序。

I have a SurfaceHolder.Callback which is added to the main activity and overwrites following method:

我有一個SurfaceHolder.Callback,它被添加到主活動並覆蓋以下方法:

@Override
public void surfaceCreated(SurfaceHolder holder) {
    mCamera = Camera.open();

    try {
        mCamera.setPreviewDisplay(holder);
    } catch (IOException e) {
        Log.d(TAG, "Can not set surface holder");
    }

    mCamera.startPreview();

    Parameters parameters = mCamera.getParameters();
    parameters.setPreviewSize(1280, 720);
    parameters.setPictureSize(1280, 720);
    mCamera.setParameters(parameters);

    QrCodeReader reader = new QrCodeReader();
    mCamera.setPreviewCallback(reader);
}

The setted picture size has to be available because it is in the list parameters.getSupportedPictureSizes().

設置的圖片大小必須可用,因為它在list.getSupportedPictureSizes()列表中。

And this method in the QrCodeReader class which implements PreviewCallback:

而這個方法在QrCodeReader類中實現了PreviewCallback:

private Result result;
private MultiFormatReader reader = new MultiFormatReader();
private boolean init = false;

public QrCodeReader(){
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType,
              Object>();
    hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
    reader.setHints(hints);
}

@Override
public void onPreviewFrame(byte[] data, Camera camera) {
    PlanarYUVLuminanceSource source = new PlanarYUVLuminanceSource(data,
          1280, 720, 0, 0, 1280, 720, true);
    HybridBinarizer hybBin = new HybridBinarizer(source);
    BinaryBitmap bitmap = new BinaryBitmap(hybBin);

try {
        result = reader.decodeWithState(bitmap);
        Log.d("Result", "Result found!");
    } catch (NotFoundException e) {
        Log.d(TAG, "NotFoundException");
    } finally {
        reader.reset();
    }
}

The Logcat only shows NotFoundException.

Logcat僅顯示NotFoundException。

1 个解决方案

#1


1  

NotFoundException is normal. If the frame doesn't have a barcode, that's the result. This doesn't mean anything is wrong per se. Keep scanning.

NotFoundException是正常的。如果框架沒有條形碼,那就是結果。這並不意味着任何事情本身都是錯誤的。繼續掃描。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2012/12/01/7250b806f117fde5cb2e23dc13b56bf3.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com