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.")); } }
/// <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)); }
public string GetText(PageIteratorLevel level) { VerifyNotDisposed(); if (handle.Handle == IntPtr.Zero) { return(String.Empty); } return(TessApi.ResultIteratorGetUTF8Text(handle, level)); }
public string GetWordRecognitionLanguage() { VerifyNotDisposed(); if (handle.Handle == IntPtr.Zero) { return(null); } return(TessApi.ResultIteratorWordRecognitionLanguage(handle)); }
/// <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); } }
/// <summary> /// Gets the page's content as plain text. /// </summary> /// <returns></returns> public string GetText() { Recognize(); return(TessApi.BaseAPIGetUTF8Text(Engine.Handle)); }
public string GetHOCRText(int pageNum) { this.Recognize(); return(TessApi.BaseAPIGetHOCRText(this.Engine.Handle, pageNum)); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
public string GetText(PageIteratorLevel level) => TessApi.ResultIteratorGetUTF8Text(this.handle, level);
/// <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;