我有一个文本识别应用程序,我只希望该应用程序读取我屏幕上某个框内的文本。我的方法是在将图像发送到文本识别之前从相机中裁剪图像。我在裁剪图像时遇到问题。
如果我尝试将字节转换为位图,然后使用 -
Bitmap bmp = BitmapFactory.decodeByteArray(data, 0, data.length);
Bitmap resizedbitmap=Bitmap.createBitmap(bmp, 100, 100, 200, 200);
然后使用 create bitmap 创建一个用 RECT 裁剪的新位图 - 但由于它为空,因此失败。
我收到位图的空值 - 我已经尝试更改选项,我已经向清单添加了读写权限 - 但它仍然是空值。
我现在正在尝试将字节数组转换为 yuvimage,但我认为数据在压缩过程中丢失了,所以当我扫描我的图像时 - 文本识别给了我扭曲的文本块,而且它不是很准确。
int correctRotation = RNCameraViewHelper.getCorrectCameraRotation(rotation, getFacing(),
getCameraOrientation());
if (data.length < (1.5 * width * height)) {
return;
}
if (willCallTextTask) {
textRecognizerTaskLock = true;
TextRecognizerAsyncTaskDelegate delegate = (TextRecognizerAsyncTaskDelegate) cameraView;
final byte[] compressedImage;
final YuvImage yuvImage = new YuvImage(data, ImageFormat.NV21, width, height, null);
final ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
Log.d("Tag", "Image Stream" + getWidth());
Log.d("Tag", "WIDTH" + width);
Log.d("Tag", "HEIGHT" + height);
yuvImage.compressToJpeg(new Rect(0, 0, width, height), 100, imageStream);
compressedImage = imageStream.toByteArray();
new TextRecognizerAsyncTask(delegate, mThemedReactContext, compressedImage, width, height, correctRotation,
getResources().getDisplayMetrics().density, getFacing(), getWidth(), getHeight(), mPaddingX, mPaddingY)
.execute();
}
}
});
}
任何建议都会很棒 - 或者如果有更好的方法来做到这一点,那就太棒了!