static void Main(string[] args) { var projectDir = Directory.GetParent(Directory.GetCurrentDirectory()).FullName; var pathFiles = Directory.EnumerateFiles( projectDir + Path.DirectorySeparatorChar + ".." + Path.DirectorySeparatorChar + "Samples") .ToList(); var resultDir = projectDir + Path.DirectorySeparatorChar + "Results"; if (!Directory.Exists(resultDir)) { Directory.CreateDirectory(resultDir); } foreach (var pathFile in Directory.EnumerateFiles(resultDir)) { File.Delete(pathFile); } foreach (var pathFile in pathFiles) { FormExtraction.ExtractCharacters( pathFile, resultDir, removeEmptyBoxes: true); } Console.WriteLine("End"); Console.ReadLine(); }
private void InitializeReadFormDataProperties(ref int propertyOrder) { Action applyVisibility = () => { bool readFormDataValue = Properties[PropertyNames.ReadFormData].GetValue <bool>(); FormExtraction returnFormDataAsValue = Properties[PropertyNames.ReturnFormDataAs].GetValue <FormExtraction>(); Properties[PropertyNames.ReturnFormDataAs].IsVisible = readFormDataValue; Properties[PropertyNames.FormDataType].IsVisible = (readFormDataValue && returnFormDataAsValue == FormExtraction.CustomType); Properties[PropertyNames.SamplePdf].IsVisible = (readFormDataValue && returnFormDataAsValue == FormExtraction.Infer); }; EventHandler updateVisibility = (sender, args) => applyVisibility(); Property readFormData = Properties.AddOrRetrieve(PropertyNames.ReadFormData, typeof(bool), ValueUseOption.DesignTime, false); readFormData.Order = propertyOrder++; readFormData.Description = "Reads form data."; readFormData.ValueChanged += RefreshOutput; readFormData.ValueChanged += updateVisibility; Property returnFormDataAs = Properties.AddOrRetrieve(PropertyNames.ReturnFormDataAs, typeof(FormExtraction), ValueUseOption.DesignTime, FormExtraction.CustomType); returnFormDataAs.Order = propertyOrder++; returnFormDataAs.Description = "Controls how the form data is returned."; returnFormDataAs.ValueChanged += RefreshOutput; returnFormDataAs.ValueChanged += updateVisibility; Property formDataType = Properties.AddOrRetrieve(PropertyNames.FormDataType, typeof(ITypeReference), ValueUseOption.DesignTime, null); formDataType.Order = propertyOrder++; formDataType.Description = "The expected type for the document's form data."; formDataType.Validations.Add(new RequiredValidator()); formDataType.ValueChanged += RefreshOutput; Property samplePdf = Properties.AddOrRetrieve(PropertyNames.SamplePdf, typeof(string), ValueUseOption.DesignTime, string.Empty); samplePdf.Order = propertyOrder++; samplePdf.Description = "A sample PDF containing the empty form."; samplePdf.Validations.Add(new RequiredValidator()); samplePdf.Validations.Add(new PdfHasFieldsValidator()); samplePdf.Editor = typeof(FilePathEditor); samplePdf.ValueChanged += RefreshOutput; applyVisibility(); }
private void UpdateReadFormDataProperties(ReadDesigner designer, IFunctionData data) { bool readFormData = data.Properties["Read form data"].GetValue <bool>(); designer.Properties[PropertyNames.ReadFormData].Value = readFormData; if (readFormData) { FormExtraction formExtraction = data.Properties["Return form data as"].GetValue <FormExtraction>(); designer.Properties[PropertyNames.ReturnFormDataAs].Value = formExtraction; switch (formExtraction) { case FormExtraction.CustomType: designer.Properties[PropertyNames.FormDataType].Value = data.Properties["Form data type"].Value; break; case FormExtraction.Infer: designer.Properties[PropertyNames.SamplePdf].Value = data.Properties["Sample pdf"].Value; break; } } }
private static void Run(FormExtractionOptions options) { try { using (Image <Rgba32> image = Image.Load <Rgba32>(options.InputFile)) { int row = image.Width; int col = image.Height; int[] imgData = new int[row * col]; for (int y = 0; y < row; y++) { for (int x = 0; x < col; x++) { int val = image[x, y].R | image[x, y].B | image[x, y].G; imgData[y + x * row] = val < 122 ? 0 : 255; } } var result = FormExtraction.FindBoxes(imgData, row, col, options); if (result.ReturnCode != 0) { Environment.Exit(result.ReturnCode); } if (options.Output == "std") { // Show result on the console. Console.WriteLine("Boxes: " + result.Boxes.Count); Console.WriteLine("Duration: " + result.Duration); Console.WriteLine(); int iBox = 1; foreach (var box in result.Boxes) { Console.WriteLine("Box #" + iBox); foreach (var element in box) { Console.WriteLine(" Element: " + element.TopLeft + "; " + element.TopRight + "; " + element.BottomRight + "; " + element.BottomLeft); } iBox++; } } else { // Write result to output file. var outputPath = options.Output; throw new NotImplementedException(); } } } catch (Exception ex) { Console.WriteLine("Something wrong happen: " + ex.Message + Environment.NewLine + ex.StackTrace); } }