/// <summary>
        /// Extract image text using specific language.
        /// </summary>
        /// <param name="fileName">The image file name.</param>
        /// <param name="language">The language.</param>
        /// <param name="useDefaultDictionaries">Use default dictionaries or not.</param>
        /// <param name="folder">The image folder.</param>
        /// <returns><see cref="OCRResponse"/> with the operation result.</returns>
        public OCRResponse ExtractText(string imageFileName, LanguageName language, bool useDefaultDictionaries = false, string folder = null)
        {
            //build URI to extract text
            string strURI = "";
            if (string.IsNullOrEmpty(folder))
                strURI = Product.BaseProductUri + "/ocr/" + imageFileName + "/recognize?language=" + language + "&useDefaultDictionaries=" + useDefaultDictionaries;
            else
                strURI = Product.BaseProductUri + "/ocr/" + imageFileName + "/recognize?language=" + language + "&useDefaultDictionaries=" + useDefaultDictionaries + "&folder=" + folder;

            //sign URI
            string signedURI = Utils.Sign(strURI);

            //execute signed URI request and get response
            Stream responseStream = Utils.ProcessCommand(signedURI, "GET");

            StreamReader reader = new StreamReader(responseStream);
            string strJSON = reader.ReadToEnd();

            //Parse the json string to JObject
            JObject parsedJSON = JObject.Parse(strJSON);

            //Deserializes the JSON to a object. 
            OCRResponse ocrResponse = JsonConvert.DeserializeObject<OCRResponse>(parsedJSON.ToString());

            return ocrResponse;
        }
示例#2
0
 /// <summary>
 /// Initialize language content
 /// </summary>
 /// <param name="langName"></param>
 public Language(LanguageName langName)
 {
     Items = new Dictionary<string, string>();
     switch (langName)
     {
         case LanguageName.Vietnamese:
             Vietnamese();
             break;
         case LanguageName.English:
             English();
             break;
     }
 }
        /// <summary>
        /// Extract image text from local file.
        /// </summary>
        /// <param name="localFile">The local file.</param>
        /// <param name="language">The text language.</param>
        /// <param name="useDefaultDictionaries">Use default dictionaries or not.</param>
        /// <returns><see cref="OCRResponse"/> with the operation result.</returns>
        public OCRResponse ExtractText(string localFile, LanguageName language, bool useDefaultDictionaries = false)
        {
            //build URI to extract text
            string strURI = strURI = Product.BaseProductUri + "/ocr/recognize?language=" + language + "&useDefaultDictionaries=" + useDefaultDictionaries;

            //sign URI
            string signedURI = Utils.Sign(strURI);
            FileStream stream = new FileStream(localFile, FileMode.Open, FileAccess.Read);

            //execute signed URI request and get response
            Stream responseStream = Utils.ProcessCommand(signedURI, "POST", stream);

            StreamReader reader = new StreamReader(responseStream);
            string strJSON = reader.ReadToEnd();

            //Parse the json string to JObject
            JObject parsedJSON = JObject.Parse(strJSON);

            //Deserializes the JSON to a object. 
            OCRResponse ocrResponse = JsonConvert.DeserializeObject<OCRResponse>(parsedJSON.ToString());

            return ocrResponse;
        }
 public void RemoveNamespace(string namespaceName)
 {
     var existingNamespace = new LanguageName(namespaceName);
     if (namespaces.Contains(existingNamespace)) namespaces.Remove(existingNamespace);
 }
 public void AddNamespace(string namespaceName)
 {
     var newNamespace = new LanguageName(namespaceName);
     if (!namespaces.Contains(newNamespace)) namespaces.Add(newNamespace);
 }
 private bool IsRegistered(string namespaceString)
 {
     var existingNamespace = new LanguageName(namespaceString);
     return namespaces.Contains(existingNamespace);
 }
        /// <summary>
        /// Scans whole or part of images and extracts OCR text
        /// </summary>
        /// <param name="imageFileName">Name of the image file</param>
        /// <param name="language">Language of document to recognize</param>
        /// /// <param name="useDefaultDictionaries">Allows to correct text after recognition using default dictionaries</param>
        /// /// <param name="x">Start x of the rectangle: Recognition of text inside specified Rectangle region</param>
        /// /// <param name="y">Start y of the rectangle: Recognition of text inside specified Rectangle region</param>
        /// /// <param name="width">Width of the rectangle: Recognition of text inside specified Rectangle region</param>
        /// /// <param name="height">Height of the rectangle: Recognition of text inside specified Rectangle region</param>
        /// /// <param name="folder">Folder with images to recognize</param>
        /// <returns></returns>
        public OCRResponse ExtractText(string imageFileName, LanguageName language, bool useDefaultDictionaries, int x, int y,
            int width, int height, string folder)
        {
            //build URI to extract text
            string strURI = Product.BaseProductUri + "/ocr/" + imageFileName + "/recognize?language=" + language +
                ((x >= 0 && y >= 0 && width > 0 && height > 0) ? "&rectX=" + x + "&rectY=" + y + "&rectWidth=" + width + "&rectHeight=" + height : "") +
             "&useDefaultDictionaries=" + ((useDefaultDictionaries) ? "true" : "false") +
             ((string.IsNullOrEmpty(folder)) ? "" : "&folder=" + folder);

            //sign URI
            string signedURI = Utils.Sign(strURI);

            //execute signed URI request and get response
            Stream responseStream = Utils.ProcessCommand(signedURI, "GET");

            StreamReader reader = new StreamReader(responseStream);
            string strJSON = reader.ReadToEnd();

            //Parse the json string to JObject
            JObject parsedJSON = JObject.Parse(strJSON);

            //Deserializes the JSON to a object. 
            OCRResponse ocrResponse = JsonConvert.DeserializeObject<OCRResponse>(parsedJSON.ToString());

            return ocrResponse;
        }
示例#8
0
 public bool Equals(LanguageName other)
 {
     return other != null && Matches(other.MatchName);
 }