拍摄时图像质量下降

时间:2018-10-04 04:29:24

标签: java android

我已经为文本识别器应用程序完成了相机模块,但是图像质量太低,文本检测器引擎有时无法从图像中获取任何文本。在预览中看起来还是不错的,我的手机是Pixel XL,所以我认为不是相机问题。也许当我将图像的位图传递给文本检测器活动时,它降低了质量,我该如何恢复?

am使用intent.putExtra传递位图,这是我的代码:

Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        Intent  intent = new Intent(MainActivity.this, GetTextActivity.class);
        intent.putExtra("key", data);
        startActivity(intent);
    }
};

这是在接收器中:

 byte[] byteArray = getIntent().getByteArrayExtra("key");
    Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
    imgCaptured.setImageBitmap(bmp);

    //text recognizer
    TextRecognizer textRecognizer = new TextRecognizer.Builder(getApplicationContext()).build();
    if (!textRecognizer.isOperational()) {
        Log.w("MainActivity_capture", "Detector is not available");
    } else {
        Frame frame = new Frame.Builder().setBitmap(bmp).build();
        SparseArray<TextBlock> items = textRecognizer.detect(frame);
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<items.size();i++){
            TextBlock item = items.valueAt(i);
            sb.append(item.getValue());
            sb.append("\n");
        }
        tvGetText.setText(sb);
    }

0 个答案:

没有答案
相关问题