public static List <string> ExtractWords(string result) { OcrObject ocrObject = ReadToObject(result); List <string> resultWords = ExtractWords(ocrObject); return(resultWords); }
// Deserialize a JSON stream to a User object. public static OcrObject ReadToObject(string json) { OcrObject deserializedUser = new OcrObject(); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)); DataContractJsonSerializer ser = new DataContractJsonSerializer(deserializedUser.GetType()); deserializedUser = ser.ReadObject(ms) as OcrObject; ms.Close(); return(deserializedUser); }
public static List <string> ExtractWords(OcrObject ocrObject) { List <string> words = new List <string>(); if (ocrObject.regions == null) { throw new Exception("OCR image result was not correct and no regions extracted."); } foreach (Region region in ocrObject.regions) { foreach (Line regionLine in region.lines) { foreach (Word regionLineWord in regionLine.words) { words.Add(regionLineWord.text); } } } return(words); }