예제 #1
0
 private void tsbClear_Click(object sender, EventArgs e)
 {
     OCRResult = null;
     PhraseRects.Clear();
     pbxDisplay.Image = snap = edit = null;
     ChangeState(State.ready);
 }
예제 #2
0
            // Get the combined text content of all boxes under this rect
            private string GetText(IAsyncOCR OCRResult)
            {
                var myBoxes = GetBoxes(OCRResult);

                if (myBoxes.Any())
                {
                    var myRects = AutoPhraseLineRects(myBoxes)
                                  .OrderBy(box => box.Top);
                    var myTexts = myRects
                                  .Select(rect => GetBoxesInRect(rect, myBoxes, PhraseRectMode.contains))
                                  .Select(boxenum => boxenum
                                          .Select(box => box.text)
                                          .Aggregate((l, r) => l + " " + r));
                    if (breakLines)
                    {
                        return(myTexts.Aggregate((l, r) => l + Environment.NewLine + r));
                    }
                    else
                    {
                        return(myTexts.Aggregate((l, r) => l + " " + r));
                    }
                }
                else
                {
                    return("");
                }
            }
예제 #3
0
 IEnumerable <OCRBox> GetBoxes(IAsyncOCR ocrResult)
 {
     if (ocrResult == null)
     {
         return(null);
     }
     return(GetBoxes(ocrResult.smallBoxes));
 }
예제 #4
0
 public void UpdateText(IAsyncOCR OCRResult, TranslationCallback callback = null)
 {
     // Only reevaluate if the underlying text actually changed
     if (atrans == null || this.GetText(OCRResult) != this.atrans.rawText)
     {
         string NewText = GetText(OCRResult);
         BabelForm.Invoke(BabelForm.SafeIncrementOdometer, new object[] { 0, NewText.Length }); // Update odometer
         atrans = AsyncStatic.MakeTranslation(NewText, callback);
     }
 }
예제 #5
0
 public void DoAutoFit(IAsyncOCR OCRResult)
 {
     if (OCRResult != null)
     {
         IEnumerable <OCRBox> FitRects = GetBoxes(OCRResult);
         if (FitRects.Count() > 0)
         {
             Location = FitRects.Select(box => box.rect).FitRect();
         }
     }
 }
예제 #6
0
        private void Viewfinder_Load(object sender, EventArgs e)
        {
            DebugLog.Log("==============================================");
            DebugLog.Log("Babel starting");
            LoadSettings();

            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolveEventHandler);


            if (Properties.Settings.Default.WaiverSigned != true)
            {
                Disclaimer dc = new Disclaimer();
                dc.ShowDialog(this);
            }

            OCRResult   = null;
            PhraseRects = new List <PhraseRect>();

            SnapRegion = new Rectangle(0, 0, 640, 480);

            Text = "Viewfinder - Ready";
            ChangeState(State.ready);

            vfw               = new Viewfinder();
            vfw.MainForm      = this;
            vfw.StartPosition = FormStartPosition.Manual;
            vfw.Location      = new Point(this.Left + 50, this.Top + 50);

            Picker = new frmWindowPicker();

            AutoOCR         = false;
            Auto_Autophrase = false;
            Autofit         = true;

            NewPhraseMode = PhraseRectMode.intersects;

            SafeAsyncOCR_Callback = AsyncOCR_callback;

            WorkerErrors = new List <WorkerError>();

            SafeIncrementOdometer = new SafeIncrementOdometer_Delegate(IncrementOdometer);

            TrackingWindow = (IntPtr)0;

            DebugLog.Log("Babel started");

#if DEBUG
            //ToggleVFW(); // Show viewfinder immediately
#endif
        }
예제 #7
0
            public PhraseRect(Rectangle Location, IAsyncOCR OCRResult, PhraseRectMode Mode, frmBabel BabelForm, TranslationCallback callback = null)
            {
                this.Location = Location;

                this.BabelForm = BabelForm;

                this.mode = Mode;
                if (Autofit)
                {
                    DoAutoFit(OCRResult);
                }
                UpdateText(OCRResult, callback);
            }
예제 #8
0
        public void AsyncOCR_callback(IAsyncOCR result)
        {
            if (InvokeRequired)
            {
                Invoke(SafeAsyncOCR_Callback, new object[] { result });
            }
            else
            {
                if (Auto_Autophrase)
                {
                    MakeAutoPhrases();
                }

                ChangeState(State.OCRed);
                statusBarLeft.Text = "Recognition complete [" + result.timeStamp + " elapsed]";
                pbxDisplay.Invalidate();
            }
        }
예제 #9
0
 public PhraseRect(Rectangle Location, IAsyncOCR OCRResult, frmBabel BabelForm, TranslationCallback callback = null)
     : this(Location, OCRResult, NewPhraseMode, BabelForm, callback)
 {
     // nothing to do
 }