cv4j
cv4j copied to clipboard
摄像头预览时调用findQRCodeBounding导致OOM
public void onPreviewFrame(final byte[] data, final int width, final int height) {
super.onPreviewFrame(data, width, height);
threadPoolManager.addTask(new Runnable() {
@Override
public void run() {
findQRCode(data, width, height);
}
});
}
private void findQRCode(byte[] data, int width, int height) {
YuvImage img = new YuvImage(data, ImageFormat.NV21, width, height, null);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
img.compressToJpeg(new android.graphics.Rect(0, 0, width, height), 100, stream);
Bitmap bitmap = BitmapFactory.decodeByteArray(stream.toByteArray(), 0, stream.size());
CV4JImage cv4JImage = new CV4JImage(bitmap);
QRCodeScanner qrCodeScanner = new QRCodeScanner();
//这一行会导致OOM
Rect qrCodeBounding = qrCodeScanner.findQRCodeBounding(cv4JImage.getProcessor(), width, height);
bitmap.recycle();
Log.i(getClass().getSimpleName(), "findQRCode: width" + qrCodeBounding.width + ",height:" + qrCodeBounding.height);
}
请问还有什么别的方法能找寻二维码区域吗
+1