1

我对 Android 和 Java 很陌生,但我想稍微修改一下这个示例。

https://github.com/abbyysdk/RTR-SDK.Android/tree/master/sample-textcapture

我想使用/存储 OCR 识别为变量或字符串的内容。

我认为这是我想要获取的信息的行类,并且在这部分代码中。

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 );
            }
        }
    }

太感谢了!

4

1 回答 1

2

查看ITextCaptureService.TextLine该类的文档会发现该Text属性是String包含已识别文本的。您所要做的就是遍历每个lines以获取文本。就像是:

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 */

        }
    ...
}
于 2018-05-04T16:52:20.673 回答