0
我爲Android使用OpenCV(2.4.8)和Zxing(2.3.0),並且想要實現「隱藏」的QR碼掃描(不使用屏幕上的Zxing CaptureActivity
)在Mat
轉換爲位圖,然後在控制檯中顯示解碼結果。使用Android的OpenCV和Zxing掃描QR碼
所以,我呼籲Zxing()
methot在onCameraFrame
方法:
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;
}
而且這是我的zxing()
法(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();
}
}
有了這個代碼,我收到「代碼未找到「消息(大約每秒五次)在LogCat控制檯中,當相機不捕獲QR碼時,但當嘗試掃描QR碼時,我沒有看到任何消息(我想我會收到sResult)。 我有什麼錯?
Android清單:
<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>