コード例 #1
0
        public void ProcessUploadedFile(HttpPostedFile file)
        {
            fileName = String.Format(@"C:\test\{0}_{1}", file.FileName, DateTime.Now.ToString("MM-dd-hh-mm-ss"));

            byte[] fileData = null;
            using (var binaryReader = new BinaryReader(file.InputStream))
            {
                fileData = binaryReader.ReadBytes(file.ContentLength);
            }

            string jsonObject = ocrSpace.ProcessPicture(fileData, file.FileName);

            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Recipe recipe = serializer.Deserialize <Recipe>(jsonObject);

            if (recipe.OCRExitCode != 1)
            {
                return;
            }

            TextOverlay overlay = recipe.ParsedResults[0].TextOverlay;

            overlay.ComputeExtraFields();

            //string[] lines = recipe.ParsedResults[0].ParsedText.Split(new string[] { "\r\n" }, StringSplitOptions.None);

            string htmlOutput = RecipeHTMLConverter.ConvertRecipeToHTML(recipe);

            File.WriteAllText(fileName + ".html", htmlOutput, swedishEncoding);

            GenerateAreasPicture(recipe.ParsedResults[0].TextOverlay);
        }
コード例 #2
0
        private void SendAbbyyResponse()
        {
            /*
             * JObject json = JObject.Parse(jsonObject);
             * int time = (int)json["ProcessingTimeInMilliseconds"];
             * int exitCode = (int)json["OCRExitCode"];
             * bool hasError = (bool)json["IsErroredOnProcessing"];
             * string errorMessage = (string)json["ErrorMessage"];*/

            List <string> pathes = new List <string>();

            pathes.Add(Server.MapPath("~/input/IMG_0030"));
            pathes.Add(Server.MapPath("~/input/IMG_0031"));
            pathes.Add(Server.MapPath("~/input/IMG_0032"));
            pathes.Add(Server.MapPath("~/input/IMG_20160411_120428"));
            pathes.Add(Server.MapPath("~/input/IMG_20160411_120615"));
            pathes.Add(Server.MapPath("~/input/IMG_20160411_120649"));

            string htmlOutput = String.Empty;
            Recipe recipe     = null;

            foreach (string path in pathes)
            {
                XElement xdoc = XElement.Load(path + ".xml");
                recipe     = processor.ProcessAbbyyXML(xdoc, path);
                htmlOutput = RecipeHTMLConverter.ConvertRecipeToHTML(recipe);
                processor.GenerateAreasPicture(recipe.ParsedResults[0].TextOverlay);
                File.WriteAllText(path + ".html", htmlOutput, swedishEncoding);
            }

            Response.Clear();
            Response.ClearHeaders();
            Response.AddHeader("Content-Type", "text/html; charset=" + swedishEncoding.EncodingName);
            Response.Write(htmlOutput);
            Response.Flush();
            Response.End();
        }