【发布时间】:2017-12-24 05:55:33
【问题描述】:
我正在开发一个移动应用程序,我试图从相机捕获的图像中提取仪表读数。
我做了研究和反复试验,最终决定使用谷歌的 Mobile Vision API 而不是tesseract-ocr 或OpenCV
所以我使用 Mobile Vision API 下提供的 Text Recognition API 开发了一个小应用程序。这是代码。
if (detector.isOperational() && bitmap != null) {
imageView.setImageBitmap((Bitmap) data.getExtras().get("data"));
Frame frame = new Frame.Builder().setBitmap(bitmap).build();
SparseArray<TextBlock> textBlocks = detector.detect(frame);
String blocks = "";
String lines = "";
String words = "";
for (int index = 0; index < textBlocks.size(); index++) {
//extract scanned text blocks here
TextBlock tBlock = textBlocks.valueAt(index);
blocks = blocks + tBlock.getValue() + "\n" + "\n";
for (Text line : tBlock.getComponents()) {
//extract scanned text lines here
lines = lines + line.getValue() + "\n";
for (Text element : line.getComponents()) {
//extract scanned integer here
if(element.getValue().matches("\\d+")){
words = words + element.getValue();
}
}
}
}
if (textBlocks.size() == 0) {
scanResults.setText("Scan Failed: Found nothing to scan");
} else {
scanResults.setText(scanResults.getText() + "Blocks: " + "\n");
scanResults.setText(scanResults.getText() + blocks + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
scanResults.setText(scanResults.getText() + "Lines: " + "\n");
scanResults.setText(scanResults.getText() + lines + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
scanResults.setText(scanResults.getText() + "Words: " + "\n");
scanResults.setText(scanResults.getText() + words + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
}
} else {
scanResults.setText("Could not set up the detector!");
}
一切正常,但无法从下图中的标记区域读取数字。
我尝试将灰度图像传递给检测器,但没有成功。
请建议我如何使文本可读。
【问题讨论】:
-
其他图片呢?它有效吗?如果您也发布或讲述日志会很有帮助。
-
是的,它适用于其他图像。但是,如果捕获的对象有深度。然后该区域中的任何文本都无法读取,tesseract 和 opencv 也会发生同样的情况。
-
@Dhaval Gulhane 你能读懂它吗?您能分享与此相关的任何发现吗?
标签: android opencv ocr tesseract text-recognition