Skip to content

Commit

Permalink
add command line args
Browse files Browse the repository at this point in the history
  • Loading branch information
Annushka34 committed Jun 20, 2023
1 parent 1e0f3c4 commit 65381a7
Show file tree
Hide file tree
Showing 39 changed files with 234 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<None Update="test.png">
<None Update="images\test.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
using Aspose.OCR;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace RecognizePNG
{
class Program
{
static void Main(string[] args)
{
PrintStart();
{
string fileName = args.Length > 0 ? args[0] : "images/test.png";
PrintStart(fileName);


// Set the license file
//License lic = new License();
Expand All @@ -21,7 +25,7 @@ static void Main(string[] args)

// Create OcrInput object to containerize images
OcrInput input = new OcrInput(InputType.SingleImage);
input.Add("test.png");
input.Add(fileName);

// set
// 1) the full path to the image
Expand All @@ -45,11 +49,11 @@ static void Main(string[] args)
PrintEnd();
}

static void PrintStart()
static void PrintStart(string fileName)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("This example will work without a license. The result will be reduced.\n");
Console.WriteLine("Recognition has begun. Please, wait...\n\n");
Console.WriteLine($"Recognition [{fileName}] has begun. Please, wait...\n\n");
}

static void PrintEnd()
Expand All @@ -58,7 +62,7 @@ static void PrintEnd()
Console.WriteLine("Recognition is over.");
Console.ResetColor();
Console.ReadKey();
System.Threading.Thread.Sleep(10000);
System.Threading.Thread.Sleep(1000);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,34 @@ The source image: test.png
The source code:


// Set the license file or try our product without license
License lic = new License();
lic.SetLicense("Aspose.Total.lic");
// Set the license file
//License lic = new License();
//lic.SetLicense("Aspose.Total.lic");

// Create AsposeOcr instance.
// You can use the overloaded constructor to set characters restriction.
AsposeOcr api = new AsposeOcr();

// Create OcrInput object to containerize images
OcrInput input = new OcrInput(InputType.SingleImage);
input.Add(fileName);

// set
// 1) the full path to the image
// 2) type of areas to search
// 3) set this to true for AreasType.LINES if you want to split lines after defining paragraphs
List<Rectangle> result = api.GetRectangles("test.png", AreasType.PARAGRAPHS, detectAreas: true);
List<RectangleOutput> result = api.DetectRectangles(input, AreasType.PARAGRAPHS, detectAreas: true);

// Print the result
Console.WriteLine("AREAS RECTANGLES COORDINATES:");
Console.WriteLine("RESULT");
Console.ResetColor();
Console.WriteLine("------------------------------------------------------------------------------");

// Print the result
for (int i = 0; i < result.Count; i++)
{
Console.WriteLine($"X: {result[i].X} Y: {result[i].Y} Width: {result[i].Width} Height: {result[i].Height}");
Console.WriteLine(result[i].Source);
foreach(Rectangle rect in result[i].Rectangles)
Console.WriteLine($"X: {rect.X} Y: {rect.Y} Width: {rect.Width} Height: {rect.Height}");
}

6 changes: 3 additions & 3 deletions Applications_Aspose_Ocr_Net_6/GetSkew/GetSkew.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
<None Update="test.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test1.jpg">
<None Update="images\test1.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test2.png">
<None Update="images\test2.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test3.png">
<None Update="images\test3.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
25 changes: 7 additions & 18 deletions Applications_Aspose_Ocr_Net_6/GetSkew/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Program
{
static void Main(string[] args)
{
PrintStart();
string fileName = args.Length > 0 ? args[0] : "images/test1.jpg";
PrintStart(fileName);

// Set the license file
//License lic = new License();
Expand All @@ -20,7 +21,7 @@ static void Main(string[] args)

// Create OcrInput object to containerize images
OcrInput input = new OcrInput(InputType.SingleImage);
input.Add("test1.jpg");
input.Add(fileName);

// You can put in parameters MemoryStream with image
// The result is the degree of skew
Expand All @@ -29,29 +30,17 @@ static void Main(string[] args)
Console.ResetColor();
Console.WriteLine("------------------------------------------------------------------------------");

Console.WriteLine("SKEW IMAGE 1:");
Console.WriteLine(result[0].Angle);

input.Clear();
input.Add("test2.png");
result = api.CalculateSkew(input);
Console.WriteLine("\nSKEW IMAGE 2:");
Console.WriteLine(result[0].Angle);

input.Clear();
input.Add("test3.png");
result = api.CalculateSkew(input);
Console.WriteLine("\nSKEW IMAGE 3:");
Console.WriteLine("SKEW IMAGE:");
Console.WriteLine(result[0].Angle);

PrintEnd();
}

static void PrintStart()
static void PrintStart(string fileName)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("This example will work without a license. The result will be reduced.\n");
Console.WriteLine("Recognition has begun. Please, wait...\n\n");
Console.WriteLine($"Recognition [{fileName}] has begun. Please, wait...\n\n");
}

static void PrintEnd()
Expand All @@ -60,7 +49,7 @@ static void PrintEnd()
Console.WriteLine("Recognition is over.");
Console.ResetColor();
Console.ReadKey();
System.Threading.Thread.Sleep(10000);
System.Threading.Thread.Sleep(1000);
}
}
}
Expand Down
36 changes: 25 additions & 11 deletions Applications_Aspose_Ocr_Net_6/GetSkew/README.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
The source images: test1.jpg test2.png test3.png
The source code:

// Set the license file or try our product without license
License lic = new License();
lic.SetLicense("Aspose.Total.lic");
// Set the license file
//License lic = new License();
//lic.SetLicense("Aspose.Total.lic");

// Create AsposeOcr instance.
// You can use the overloaded constructor to set characters restriction.
AsposeOcr api = new AsposeOcr();

// You can put in parameters MemoryStream with image or path to the image

// Create OcrInput object to containerize images
OcrInput input = new OcrInput(InputType.SingleImage);
input.Add(fileName);

// You can put in parameters MemoryStream with image
// The result is the degree of skew
var result = api.CalculateSkew("test1.jpg");

// Print the result
List<SkewOutput> result = api.CalculateSkew(input);
Console.WriteLine("RESULT");

Console.ResetColor();
Console.WriteLine("------------------------------------------------------------------------------");

Console.WriteLine("SKEW IMAGE:");
Console.WriteLine(result);
Console.WriteLine("SKEW IMAGE 1:");
Console.WriteLine(result[0].Angle);

input.Clear();
input.Add("images/test2.png");
result = api.CalculateSkew(input);
Console.WriteLine("\nSKEW IMAGE 2:");
Console.WriteLine(result[0].Angle);

input.Clear();
input.Add("images/test3.png");
result = api.CalculateSkew(input);
Console.WriteLine("\nSKEW IMAGE 3:");
Console.WriteLine(result[0].Angle);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<None Update="test.jpg">
<None Update="images\test.jpg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
17 changes: 7 additions & 10 deletions Applications_Aspose_Ocr_Net_6/PreprocessImage/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,25 @@ class Program
{
static void Main(string[] args)
{
PrintStart();
string fileName = args.Length > 0 ? args[0] : "images/test.jpg";
PrintStart(fileName);
// Set the license file
//License lic = new License();
//lic.SetLicense("Aspose.Total.lic");

// Create AsposeOcr instance.
// You can use the overloaded constructor to set characters restriction.
AsposeOcr api = new AsposeOcr();

// Create OcrInput object to containerize images
// Set:
// 1) path to the image or MemruStream with the image.
// 2) set of filters for preprocessing. You can call any number of filters.
OcrInput input = new OcrInput(InputType.SingleImage, new PreprocessingFilter { PreprocessingFilter.ContrastCorrectionFilter() });
input.Add("test.jpg");
input.Add(fileName);


OcrInput result = ImageProcessing.Render(input);
MemoryStream memoryStream = result[0].Stream;

// Use Stream for further recognition or simply save it on the disk
FileStream fs = new FileStream("corrected.jpg", FileMode.OpenOrCreate);
FileStream fs = new FileStream("out/corrected.jpg", FileMode.OpenOrCreate);
memoryStream.WriteTo(fs);
fs.Close();
memoryStream.Close();
Expand All @@ -39,11 +36,11 @@ static void Main(string[] args)
PrintEnd();
}

static void PrintStart()
static void PrintStart(string fileName)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("This example will work without a license. The result will be reduced.\n");
Console.WriteLine("Recognition has begun. Please, wait...\n\n");
Console.WriteLine($"Recognition [{fileName}] has begun. Please, wait...\n\n");
}

static void PrintEnd()
Expand All @@ -55,7 +52,7 @@ static void PrintEnd()
Console.WriteLine("The preprocessed image was saved by the name corrected.jpg. Check the folder.");
Console.ResetColor();
Console.ReadKey();
System.Threading.Thread.Sleep(10000);
System.Threading.Thread.Sleep(1000);
}
}
}
Expand Down
51 changes: 37 additions & 14 deletions Applications_Aspose_Ocr_Net_6/PreprocessImage/README.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,46 @@
The source images: test.jpg
The source code:

// Set the license file or try our product without license
License lic = new License();
lic.SetLicense("Aspose.Total.lic");
// Set the license file
//License lic = new License();
//lic.SetLicense("Aspose.Total.lic");

// Create AsposeOcr instance.
// You can use the overloaded constructor to set characters restriction.
AsposeOcr api = new AsposeOcr();

// Set:
// 1) path to the image or MemruStream with the image.
// 2) set of filters for preprocessing. You can call any number of filters.
MemoryStream memoryStream = api.PreprocessImage("test.jpg", new PreprocessingFilter { PreprocessingFilter.ContrastCorrectionFilter()});
// Create OcrInput object to containerize images
// Add filters as you need
PreprocessingFilter filters = new PreprocessingFilter // we automaticaly preprocess your image, but if your recognition result still bad, you can set up the set of filters by your own
{
//PreprocessingFilter.Dilate()
};
OcrInput input = new OcrInput(InputType.SingleImage, filters);
input.Add(fileName);

// Use Stream for further recognition or simply save it on the disk
using(FileStream fs = new FileStream("corrected.jpg", FileMode.OpenOrCreate))
{
memoryStream.WriteTo(fs);
memoryStream.Close();
}
List<RecognitionResult> res = api.Recognize(input, new RecognitionSettings
{
//// allowed options
// AllowedCharacters = CharactersAllowedType.LATIN_ALPHABET, // ignore not latin symbols
// AutoSkew = true, // switch off if your image not rotated
// DetectAreasMode = DetectAreasMode.DOCUMENT, // depends on the structure of your image
// IgnoredCharacters = "*-!@#$%^&", // define the symbols you want to ignore in the recognition result
// Language = Language.Eng, // we support 26 languages
// LinesFiltration = false, // this works slowly, so choose it only if your picture has lines and it they bad detected in TABLE ar DOCUMENT DetectAreasMode

// RecognitionAreas = new System.Collections.Generic.List<System.Drawing.Rectangle> // set this if you want to recognize only partiqular regions on the image
// {
// new System.Drawing.Rectangle(0,0,10,20)
// },
// RecognizeSingleLine = false, // set this true if your image has only one text line (without other objects)
// ThreadsCount = 1, // by default our API use all you threads. But you can run it in one thread. Simply set up this here
// ThresholdValue = 150 // if you want to binarize image with your own threashold value, you can set up this here (from 1 to 255)
});

// Save the result
// Set:
// 1) path for new file
// 2) File format
// 3) set true if you want to correct the mistakes in the words
// 4) set the language if you want to correct the mistakes
// 5) you can set your own dictionary for spell-check
res[0].Save("result.json", SaveFormat.Json, false);
Loading

0 comments on commit 65381a7

Please sign in to comment.