下图取自 Officelens,因为他们将图像的位深度转换为顶部的清晰黑白图像和底部的原始图像:
但是当我尝试转换时,我得到下面给出的输出:
上面的结果是使用 tif 转换库完成的,我尝试过的代码如下;
private void takePicture() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File folderPath = new File(Environment.getExternalStorageDirectory() + "/OCR");
if (!folderPath.exists()) {
if (folderPath.mkdir()) ; //directory is created;
} else {
File photo = new File(folderPath, "OCRPIC" + UUID.randomUUID().toString().substring(0, 5) + ".jpg");
imageUri = FileProvider.getUriForFile(MainActivity.this,
BuildConfig.APPLICATION_ID + ".provider", photo);
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
startActivityForResult(intent, PHOTO_REQUEST);
}
}
当我将图像从相机保存到内部存储并在检索时我将转换为颜色压缩,下面给出的代码,
TiffConverter.ConverterOptions options = new TiffConverter.ConverterOptions();
options.throwExceptions = false;
options.availableMemory = 1 * 1024 * 1024;
options.compressionScheme = CompressionScheme.LZW;
options.readTiffDirectory = 1;
TiffConverter.convertToTiff(path, Environment.getExternalStorageDirectory() + "/OCR"+"/"+path.substring(path.lastIndexOf("/")+1).substring(0,11)+".jpg", options,null);
我想实现 Office Lens 产生的输出。