imageprocessor / cv4j

The target is to set up a high quality and real-time image process and machine learning library which is implemented in pure java. The framework can run application on java desktop and android platform.
Apache License 2.0
843 stars 151 forks source link

摄像头预览时调用findQRCodeBounding导致OOM #25

Open xiaojigugu opened 4 years ago

xiaojigugu commented 4 years ago
        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);
}

请问还有什么别的方法能找寻二维码区域吗

cyzaoj commented 3 years ago

+1