android - 如何从类中获取字符串? (Android studio) abbyy OCR 识别

标签 android class android-studio ocr abbyy

我是 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/

相关文章:

java - logcat 中应用程序强制关闭并出现 NullPointerException

java - 二元运算符的操作数类型错误 '=='

java - 找不到符号方法元工厂(Lookup,String,MethodType,MethodType,MethodHandle,MethodType)

java - 无法解析 R android studio 1.2.1.1

android - 将 Android Studio 项目与 Azure Pipelines CI/CD 集成

Android:应用程序在即时运行时经常崩溃

android - Kotlin 适用于 String 未按预期工作

android - 如何更改 xamarin 表单中的导航页面后退按钮

html - 如何为两个不同的 css 属性使用两个缓入缓出效果?

java - 在 Java 中声明 "static"变量时 "global"到底是什么意思?