private void tsbClear_Click(object sender, EventArgs e) { OCRResult = null; PhraseRects.Clear(); pbxDisplay.Image = snap = edit = null; ChangeState(State.ready); }
// 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(""); } }
IEnumerable <OCRBox> GetBoxes(IAsyncOCR ocrResult) { if (ocrResult == null) { return(null); } return(GetBoxes(ocrResult.smallBoxes)); }
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); } }
public void DoAutoFit(IAsyncOCR OCRResult) { if (OCRResult != null) { IEnumerable <OCRBox> FitRects = GetBoxes(OCRResult); if (FitRects.Count() > 0) { Location = FitRects.Select(box => box.rect).FitRect(); } } }
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 }
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); }
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(); } }
public PhraseRect(Rectangle Location, IAsyncOCR OCRResult, frmBabel BabelForm, TranslationCallback callback = null) : this(Location, OCRResult, NewPhraseMode, BabelForm, callback) { // nothing to do }