示例#1
0
        public void setLines(TextCaptureServiceTextLine[] lines,
                             RecognitionServiceResultStabilityStatus resultStatus)
        {
            if (lines != null && scaleDenominatorX > 0 && scaleDenominatorY > 0)
            {
                this.quads = new Point[lines.Length * 4];
                this.lines = new String[lines.Length];
                for (int i = 0; i < lines.Length; i++)
                {
                    TextCaptureServiceTextLine line = lines[i];
                    for (int j = 0; j < 4; j++)
                    {
                        this.quads[4 * i + j] = new Point(
                            (scaleNominatorX * line.Quadrangle[j].X) / scaleDenominatorX,
                            (scaleNominatorY * line.Quadrangle[j].Y) / scaleDenominatorY
                            );
                    }
                    this.lines[i] = line.Text;
                }
                switch (resultStatus.ToString())
                {
                case "NotReady":
                    textPaint.SetARGB(255, 128, 0, 0);
                    break;

                case "Tentative":
                    textPaint.SetARGB(255, 128, 0, 0);
                    break;

                case "Verified":
                    textPaint.SetARGB(255, 128, 64, 0);
                    break;

                case "Available":
                    textPaint.SetARGB(255, 128, 128, 0);
                    break;

                case "TentativelyStable":
                    textPaint.SetARGB(255, 64, 128, 0);
                    break;

                case "Stable":
                    textPaint.SetARGB(255, 0, 128, 0);
                    break;
                }
                stability = resultStatus.Ordinal();
            }
            else
            {
                stability  = 0;
                this.lines = null;
                this.quads = null;
            }
            this.Invalidate();
        }
示例#2
0
        public void OnFrameProcessed(TextCaptureServiceTextLine[] lines, RecognitionServiceResultStabilityStatus resultStatus, RecognitionServiceWarning 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 (!activity.stableResultHasBeenReached)
            {
                if (resultStatus.Ordinal() >= 3)
                {
                    // The result is stable enough to show something to the user
                    activity.surfaceViewWithOverlay.setLines(lines, resultStatus);
                }
                else
                {
                    // The result is not stable. Show nothing
                    activity.surfaceViewWithOverlay.setLines(null, RecognitionServiceResultStabilityStatus.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.)
                activity.warningTextView.Text = (warning != null ? warning.Name() : "");

                if (resultStatus == RecognitionServiceResultStabilityStatus.Stable)
                {
                    // Stable result has been reached. Stop the service
                    activity.stopRecognition();
                    activity.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
                    activity.surfaceViewWithOverlay.setFillBackground(true);
                    activity.startButton.PlaySoundEffect(Android.Views.SoundEffects.Click);
                }
            }
        }