Как я могу получить строку из класса? (Android studio) распознавание abbyy OCR - PullRequest
0 голосов
/ 04 мая 2018

Я очень плохо знаком с 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 );
            }
        }
    }

Большое спасибо!

1 Ответ

0 голосов
/ 04 мая 2018

Просмотр документации для класса 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 */

        }
    ...
}
...