示例#1
0
        /// <summary>
        /// Every x seconds the Context Recognition algorithm is run if the window has changed.
        /// Some info about the context is added (currently: process + windows information)
        /// Then, the background worker is started for OCR recognition
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RunContextRecognition(object sender, EventArgs e)
        {
            // determine whether store or not
            if (_screenshotChangedTracker == null || !_screenshotChangedTracker.WindowChanged())
            {
                return;
            }

            // capture the screenshot
            var sc = ScreenCapture.CaptureActiveWindowHq();

            if (sc == null || sc.Image == null)
            {
                return;                                 // screenshot capture unsuccessful
            }
            // get window & process names (additional contextual information)
            var currentWindowName  = _screenshotChangedTracker.GetWindowText();
            var currentProcessName = _screenshotChangedTracker.GetProcessName();

            var ce = new ContextEntry
            {
                Timestamp   = DateTime.Now,
                WindowName  = currentWindowName,
                ProcessName = currentProcessName,
                Confidence  = OcrLibrary.Settings.OcrConfidenceAcceptanceThreshold, // so it won't be saved if it isn't overwritten
                OcrText     = string.Empty,
                Screenshot  = sc
            };

            // runs the OCR process and get's the result as a context entry
            ce = OcrEngine.GetInstance().RunOcr(ce);

            // only save in database if useful accuracy & enough content
            if (ce != null &&
                ce.Confidence < OcrLibrary.Settings.OcrConfidenceAcceptanceThreshold &&
                ce.OcrText.Length > OcrLibrary.Settings.OcrTextLengthAcceptanceThreshold)
            {
                SaveContextEntryToDatabase(ce);
            }

            // dispose data (to free up RAM)
            DisposeData(ce);
        }