Exemplo n.º 1
0
        public async Task <string> ProcessRecipe()
        {
            string jsonObject = await Request.Content.ReadAsStringAsync();

            //byte[] image = await Request.Content.ReadAsByteArrayAsync();

            //if (image == null)
            //	image = File.ReadAllBytes(@"C:\test\new\IMG_0030.jpg");
            //OCR.Space.OCRSpaceMain ocrSpace = new OCR.Space.OCRSpaceMain();
            //string jsonObject = ocrSpace.ProcessPicture(image, "TestImageName.jpg");

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

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

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

            overlay.ComputeExtraFields();

            string htmlOutput = RecipeHTMLConverter.ConvertRecipeToHTML(recipe);

            string jsonOutput = ProcessRecipe(Encoding.ASCII.GetBytes(htmlOutput));

            return(jsonOutput);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public static string ConvertRecipeToHTML(Recipe recipe)
        {
            TextOverlay overlay = recipe.ParsedResults[0].TextOverlay;

            overlay.ComputeExtraFields();
            overlay.Normalize();
            StringBuilder output = new StringBuilder(String.Empty);

            output.AppendLine("<html>");
            output.AppendLine(String.Format("<body data-ml=\"{0} {1} {2} {3} block\">", 0, 0, overlay.Width, overlay.Height));
            foreach (TextLine line in overlay.Lines)
            {
                output.AppendLine(String.Format("<p data-ml=\"{0} {1} {2} {3} {4}block\">{5}</p>",
                                                line.Bounds.Left, line.Bounds.Top, line.Bounds.Width, line.Bounds.Height, line.Bold? "bold ": String.Empty, line.Text));
            }
            output.AppendLine("</body>");
            output.AppendLine("</html>");
            return(output.ToString());
        }
Exemplo n.º 4
0
        public Recipe ParseImage()
        {
            byte[] image = Request.Content.ReadAsByteArrayAsync().Result;
            if (image == null)
            {
                image = File.ReadAllBytes(@"C:\test\new\IMG_0030.jpg");
            }
            OCR.Space.OCRSpaceMain ocrSpace = new OCR.Space.OCRSpaceMain();
            string jsonObject = ocrSpace.ProcessPicture(image, "TestImageName.jpg");

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

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

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

            overlay.ComputeExtraFields();

            return(recipe);
        }