Esempio n. 1
0
        private void Initialise(string datapath, string language, EngineMode engineMode,
                                IEnumerable <string> configFiles, IDictionary <string, object> initialValues, bool setOnlyNonDebugVariables)
        {
            Guard.RequireNotNullOrEmpty("language", language);

            // do some minor processing on datapath to fix some common errors (this basically mirrors what tesseract does as of 3.04)
            if (!string.IsNullOrEmpty(datapath))
            {
                // remove any excess whitespace
                datapath = datapath.Trim();

                // remove any trialing '\' or '/' characters
                if (datapath.EndsWith("\\", StringComparison.Ordinal) ||
                    datapath.EndsWith("/", StringComparison.Ordinal))
                {
                    datapath = datapath.Substring(0, datapath.Length - 1);
                }
            }

            if (TessApi.BaseApiInit(handle, datapath, language, (int)engineMode, configFiles ?? new List <string>(),
                                    initialValues ?? new Dictionary <string, object>(), setOnlyNonDebugVariables) != 0)
            {
                // Special case logic to handle cleaning up as init has already released the handle if it fails.
                handle = new HandleRef(this, IntPtr.Zero);
                GC.SuppressFinalize(this);

                throw new TesseractException(ErrorMessage.Format(1, "Failed to initialise tesseract engine."));
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Returns the text string for the current choice.
        /// </summary>
        /// <returns>string</returns>
        public string GetText()
        {
            VerifyNotDisposed();
            if (_handleRef.Handle == IntPtr.Zero)
            {
                return(string.Empty);
            }

            return(TessApi.ChoiceIteratorGetUTF8Text(_handleRef));
        }
Esempio n. 3
0
        public string GetText(PageIteratorLevel level)
        {
            VerifyNotDisposed();
            if (handle.Handle == IntPtr.Zero)
            {
                return(String.Empty);
            }

            return(TessApi.ResultIteratorGetUTF8Text(handle, level));
        }
Esempio n. 4
0
        public string GetWordRecognitionLanguage()
        {
            VerifyNotDisposed();
            if (handle.Handle == IntPtr.Zero)
            {
                return(null);
            }

            return(TessApi.ResultIteratorWordRecognitionLanguage(handle));
        }
Esempio n. 5
0
 /// <summary>
 /// Gets the page's content as a HOCR text.
 /// </summary>
 /// <param name="pageNum">The page number (zero based).</param>
 /// <param name="useXHtml">True to use XHTML Output, False to HTML Output</param>
 /// <returns>The OCR'd output as a HOCR text string.</returns>
 public string GetHOCRText(int pageNum, bool useXHtml = false)
 {
     //Why Not Use 'nameof(pageNum)' instead of '"pageNum"'
     Guard.Require("pageNum", pageNum >= 0, "Page number must be greater than or equal to zero (0).");
     Recognize();
     if (useXHtml)
     {
         return(TessApi.BaseAPIGetHOCRText2(Engine.Handle, pageNum));
     }
     else
     {
         return(TessApi.BaseAPIGetHOCRText(Engine.Handle, pageNum));
     }
 }
 /// <summary>
 /// Zeigt das jeweils 'passende' Control an
 /// </summary>
 /// <param name="tess">The MyTess.</param>
 /// <param name="toSet">To UserControl.</param>
 /// <param name="set">The set.</param>
 public void ShowSuitableControl()
 {
     if (!TessApi.IsLoggedIn)
     {
         ShowLogin();
     }
     else if (Settings?.CarId == null)
     {
         ShowSettings();
     }
     else
     {
         TessApi.SetCarId(Settings.CarId.Value);
         TessControl tc = new TessControl();
         ShowControl(tc);
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Gets the page's content as plain text.
 /// </summary>
 /// <returns></returns>
 public string GetText()
 {
     Recognize();
     return(TessApi.BaseAPIGetUTF8Text(Engine.Handle));
 }
Esempio n. 8
0
 public string GetHOCRText(int pageNum)
 {
     this.Recognize();
     return(TessApi.BaseAPIGetHOCRText(this.Engine.Handle, pageNum));
 }
Esempio n. 9
0
 /// <summary>
 ///     Attempts to retrieve the value for a string variable.
 /// </summary>
 /// <param name="name">The name of the variable.</param>
 /// <param name="value">The current value of the variable.</param>
 /// <returns>Returns <c>True</c> if successful; otherwise <c>False</c>.</returns>
 public bool TryGetStringVariable(string name, out string value)
 {
     value = TessApi.BaseApiGetStringVariable(handle, name);
     return(value != null);
 }
Esempio n. 10
0
        /// <summary>
        ///     Sets the value of a double variable.
        /// </summary>
        /// <param name="name">The name of the variable.</param>
        /// <param name="value">The new value of the variable.</param>
        /// <returns>Returns <c>True</c> if successful; otherwise <c>False</c>.</returns>
        public bool SetVariable(string name, double value)
        {
            var strEncodedValue = value.ToString("R", CultureInfo.InvariantCulture.NumberFormat);

            return(TessApi.BaseApiSetVariable(handle, name, strEncodedValue) != 0);
        }
Esempio n. 11
0
        /// <summary>
        ///     Sets the value of a boolean variable.
        /// </summary>
        /// <param name="name">The name of the variable.</param>
        /// <param name="value">The new value of the variable.</param>
        /// <returns>Returns <c>True</c> if successful; otherwise <c>False</c>.</returns>
        public bool SetVariable(string name, bool value)
        {
            var strEncodedValue = value ? "TRUE" : "FALSE";

            return(TessApi.BaseApiSetVariable(handle, name, strEncodedValue) != 0);
        }
Esempio n. 12
0
 /// <summary>
 ///     Sets the value of a string variable.
 /// </summary>
 /// <param name="name">The name of the variable.</param>
 /// <param name="value">The new value of the variable.</param>
 /// <returns>Returns <c>True</c> if successful; otherwise <c>False</c>.</returns>
 public bool SetVariable(string name, string value)
 {
     return(TessApi.BaseApiSetVariable(handle, name, value) != 0);
 }
Esempio n. 13
0
 public string GetText(PageIteratorLevel level) => TessApi.ResultIteratorGetUTF8Text(this.handle, level);
Esempio n. 14
0
 /// <summary>
 /// Sets the value of a string variable.
 /// </summary>
 /// <param name="name">The name of the variable.</param>
 /// <param name="value">The new value of the variable.</param>
 /// <returns>Returns <c>True</c> if successful; otherwise <c>False</c>.</returns>
 public bool SetVariable(string name, string value) => TessApi.BaseApiSetVariable(this.Handle, name, value) != 0;