public OcrEngine() { IncludeTextRegions = true; Timeout = 30000; SupportedLanguages = new Dictionary <string, string>(); if (!RemoteOcr.IsRemote(GetType()) && GetType() != typeof(RemoteOcr) && IsInstalled) { GetSupportedLanguages(); } }
private static void UpdateRemoteEngines(string ip) { if (string.IsNullOrWhiteSpace(ip)) { return; } try { using (WebClient webClient = new WebClient()) { string url = "http://" + ip + ":" + port + "/" + GetEnginesCommand; webClient.Proxy = null; webClient.Encoding = Encoding.UTF8; string response = webClient.DownloadString(url); string[] splitted = response.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string value in splitted) { try { string[] splitted2 = value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); string typeStr = splitted2[0]; List <string> languages = new List <string>(); for (int i = 1; i < splitted2.Length; i++) { languages.Add(splitted2[i]); } OcrEngineType type = (OcrEngineType)Enum.Parse(typeof(OcrEngineType), typeStr); if (!OcrEngine.Create(type).IsInstalled) { if (!RemoteTypes.ContainsKey(ip)) { RemoteTypes[ip] = new Dictionary <OcrEngineType, List <string> >(); } RemoteTypes[ip][type] = languages.ToList(); RemoteOcr.SetRemote(type); } } catch { } } } } catch { } }
private static void UpdateRemoteEngines() { try { RemoteOcr.ClearRemote(); RemoteTypes.Clear(); UpdateRemoteEngines(Program.Settings.ServerInfo.IP1); UpdateRemoteEngines(Program.Settings.ServerInfo.IP2); } catch { } }
public OcrResult Load(OcrImage image, string language) { try { OcrResult result = null; if (GetType() != typeof(RemoteOcr) && RemoteOcr.IsRemote(GetType())) { OcrEngineType targetType = GetType(GetType()); RemoteOcr remoteOcr = new RemoteOcr(targetType); result = remoteOcr.Load(image, language, language); } else if (!IsInstalled) { return(OcrResult.Create(OcrResultType.NotInstalled)); } else { string apiLanguage = language == null ? null : GetSupportedLanguageName(language); if (string.IsNullOrEmpty(apiLanguage)) { return(OcrResult.Create(OcrResultType.LanguageNotSupported)); } result = Load(image, language, apiLanguage); } if (result != null && result.Rect == OcrRect.Empty) { result.Rect = new OcrRect(0, 0, image.Width, image.Height); } return(result); } catch (Exception e) { return(OcrResult.Create(OcrResultType.Exception, e.ToString())); } }