HTML JPG OCR JSON BMP
Aspose.OCR  for .NET
OCR

Recognize image and save result as JSON file in C#

Get recognition result in JSON formatted file using Aspose.OCR for .NET library.

How to Recognize image and save result as JSON file using C#

Aspose.OCR for .NET can return recognition results in JSON format - de facto data exchange standard for websites and REST APIs. To get the results as JSON, use GetJson method of Aspose.OCR.RecognitionResult object. Set isReadable parameter of the method to true to get a JSON string in a human-readable format with line breaks and auto-indentation.

To run the examples, you just need to download the Aspose.OCR tools with the following links:

Command line tools

RecognizeAndSaveJson project



Run program in Command Prompt


  RecognizeAndSaveJson

or

Run program in Command Prompt if you want to use own image (document)


  RecognizeAndSaveJson folder/image.png




The result pdf file will be stored in the *out* folder

Recognition result

PropertyTypeDescription
FileNameStringFull path to the file.
RecognitionAreasRectanglesListGets rectangles coordinates.
RecognitionAreasTextListGets list recognition results of a list of areas (Rectangles).
RecognitionCharactersListList<char[]>A set of characters found by the recognition algorithm and arranged in descending order of probability.
RecognitionLinesResultList Gets a list of recognition results with a list of rows (Rectangles).
RecognitionTextstringGets recognition result in one string.
Skewdouble Gets skew angle.
WarningsListGets list of the warning messages describing non-critical faults appeared during generation.


This sample code shows how to get areas coordinates


		//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();
            RecognitionResult res = api.RecognizeImage("test.png", new RecognitionSettings 
            {
                //// allowed options
                // AllowedCharacters = CharactersAllowedType.LATIN_ALPHABET, // ignore not latin symbols
                // AutoContrast = false, // use Contrast correction filter before recognition - good for images with noice 
                // AutoSkew = true, // switch off if your image not rotated
                // DetectAreas = true, // switch off if your image has a simple document structure (one column text without pictures)
                // 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
                // PreprocessingFilters = 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()
                // },
                // 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)
                // SkewAngle = 5, // use this if your want to switch on out automatically skew correction and set up your own angle
                // 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.Save("result.json", SaveFormat.Json, false);        

Other Supported Tools

Using C#, one can easily run our examples.

Recognize image (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Recognize PDF (Scanned PDF)
Recognize TIFF (Multipage TIFF)
Preprocess image (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Get JSON (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Get XLSX (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Detect angle (GIF, PNG, JPEG, BMP, TIFF, JFIF)
Recognize image from URL (URL with GIF, PNG, JPEG, BMP, TIFF, JFIF)
Text areas detection (GIF, PNG, JPEG, BMP, TIFF, JFIF)