我正在开发一个移动应用程序,我试图从相机捕获的图像中提取仪表读数。
我做了研究,经过反复试验,最终决定使用 Google 的 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!");
}
一切正常,但无法从下图中的标记区域读取数字。
我试图将灰度图像传递给检测器,但没有成功。
请建议我如何使文本可读。