我正在尝试使用android离线文本识别(OCR)从相机获取数字行。我想从摄像机获取一个数字,并且当出现新行时,对象检测必须停止。
@Override
public void receiveDetections(Detector.Detections<TextBlock> detections) {
final SparseArray<TextBlock> items = detections.getDetectedItems();
if (items.size() != 0) {
textView.post(new Runnable() {
@Override
public void run() {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < items.size(); i++) {
TextBlock item = items.valueAt(i);
stringBuilder.append(item.getValue());
//stringBuilder.append("\n");
intNumber = stringBuilder.toString().trim();
//intNumber = intNumber.replaceAll("\\D+","");
}
//textView.setText(stringBuilder.toString().trim());
// intNumber = intNumber.replaceAll("[^\\d]", "" );
// substring = intNumber.substring(0,18);
number = intNumber;
textView.setText(intNumber);
}
});
}
}
最佳答案
是的,您可以喜欢以下内容。
示例字符串:
String stringWithNewLine= "one\ntwo";
您可以将其转换为数组
String myArray[] = stringWithNewLine.split("\n"); // myArray = {"one", "two"};