我是 Android 和 Java 的新手,但我想稍微修改一下这个示例。
https://github.com/abbyysdk/RTR-SDK.Android/tree/master/sample-textcapture
我想使用/存储 OCR 识别为变量或字符串的内容。
我认为是lines类是我想要获取的信息,并且在这部分代码中。
public void onFrameProcessed( ITextCaptureService.TextLine[] lines,
ITextCaptureService.ResultStabilityStatus resultStatus, ITextCaptureService.Warning warning )
{
// Frame has been processed. Here we process recognition results. In this sample we
// stop when we get stable result. This callback may continue being called for some time
// even after the service has been stopped while the calls queued to this thread (UI thread)
// are being processed. Just ignore these calls:
if( !stableResultHasBeenReached ) {
if( resultStatus.ordinal() >= 3 ) {
// The result is stable enough to show something to the user
surfaceViewWithOverlay.setLines( lines, resultStatus );
} else {
// The result is not stable. Show nothing
surfaceViewWithOverlay.setLines( null, ITextCaptureService.ResultStabilityStatus.NotReady );
}
// Show the warning from the service if any. The warnings are intended for the user
// to take some action (zooming in, checking recognition language, etc.)
warningTextView.setText( warning != null ? warning.name() : "" );
if( resultStatus == ITextCaptureService.ResultStabilityStatus.Stable ) {
// Stable result has been reached. Stop the service
stopRecognition();
stableResultHasBeenReached = true;
// Show result to the user. In this sample we whiten screen background and play
// the same sound that is used for pressing buttons
surfaceViewWithOverlay.setFillBackground( true );
startButton.playSoundEffect( android.view.SoundEffectConstants.CLICK );
}
}
}
非常感谢!
最佳答案
查看 ITextCaptureService.TextLine
类的文档会发现 Text
属性是一个包含已识别文本的 String
。您所要做的就是遍历每一行 行
以获取文本。像这样的东西:
String recognizedText = "";
foreach(ITextCaptureService.TextLine line : lines) {
recognizedText += line.Text;
}
/* do something with recognizedText */
对于您的示例:
public void onFrameProcessed( ITextCaptureService.TextLine[] lines,
ITextCaptureService.ResultStabilityStatus resultStatus, ITextCaptureService.Warning warning )
{
...
if( resultStatus == ITextCaptureService.ResultStabilityStatus.Stable) {
// Stable result has been reached. Stop the service
stopRecognition();
stableResultHasBeenReached = true;
String recognizedText = "";
foreach(ITextCaptureService.TextLine line : lines) {
recognizedText += line.Text;
}
/* do something with recognizedText */
}
...
}
关于android - 如何从类中获取字符串? (Android studio) abbyy OCR 识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50179625/