Question

I am using OpenCV (2.4.8) and Zxing (2.3.0) for Android and I'd like implement „hidden“ QR code scanning (without use Zxing CaptureActivity on screen) in Mat converted to bitmap and then display decoded result in console.

So, I call Zxing() methot in onCameraFrame method:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {

    // there will be preprocessing
    mRgba = inputFrame.rgba();

    try {
        zxing();
    } catch (ChecksumException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FormatException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }       
    return mRgba;
}

And it is my zxing() method (inspired by ZXing convert Bitmap to BinaryBitmap):

public void zxing() throws ChecksumException, FormatException{

    Bitmap bMap = Bitmap.createBitmap(mRgba.width(), mRgba.height(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(mRgba, bMap);
    int[] intArray = new int[bMap.getWidth()*bMap.getHeight()];  
    //copy pixel data from the Bitmap into the 'intArray' array  
    bMap.getPixels(intArray, 0, bMap.getWidth(), 0, 0, bMap.getWidth(), bMap.getHeight());  

    LuminanceSource source = new RGBLuminanceSource(bMap.getWidth(), bMap.getHeight(),intArray);

    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Reader reader = new QRCodeMultiReader();     

    String sResult = "";

   try {

        Result result = reader.decode(bitmap);   
        sResult = result.getText();
        Log.d(TAG, sResult);

        }
    catch (NotFoundException e) {
            Log.d(TAG, "Code Not Found");
            e.printStackTrace();
    }

    }

With this code, I receive "Code Not Found" messages (about five per second) in LogCat console when camera don’t capture QR code, but when try scan QR code, I don’t see any message ( I thought I will receive sResult). What I have wrong?

Android manifest:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    <activity
        android:name="mk.app_02_28.MainActivity"
        android:label="@string/app_name" 
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>
Was it helpful?

Solution

It was stupid mistake, I had wrong line

Log.d(TAG, sResult);

It should be:

Log.d(TAG,"Found something: "+result.getText());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top