Hello, world!

In this article, you will learn how to extract text from an image file using Aspose.OCR Cloud REST API.

You will need

  • Any system with Internet connection.
  • Some simple image with English text. You can take the one from this article.
  • A web browser.
  • Any tool that allows you to make REST API calls, such as cURL or Postman. The article provides cURL examples.
  • 15 minutes of spare time.

Getting an access token

The Aspose.OCR Cloud API is fully compliant with industry security standards and best practices. Data transfer is carried out using JWT authentication, which eliminates all possibilities of data theft or disclosure.

To obtain a JWT token, get the Client ID and Client Secret credentials:

  1. Sign in to GroupDocs Cloud API Dashboard.
  2. Go to Applications page.
  3. Create the samples storage for exchanging files by clicking the plus icon and following the required steps. For this example, Internal storage with 24-hour retention will suffice.
  4. Provide the application name, for example, HelloWorld.
  5. Click Save button.
  6. Click the newly created HelloWorld application and copy the values from Client Id and Client Secret fields.

Now request an access token with the following API call:

curl --location --request POST 'https://api.aspose.cloud/connect/token' \
     --header 'Content-Type: application/x-www-form-urlencoded' \
     --data-urlencode 'grant_type=client_credentials' \
     --data-urlencode 'client_id=CLIENT-ID-VALUE' \
     --data-urlencode 'client_secret=CLIENT-SECRET-VALUE'

You should get a response that looks something like this:

	"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...HaRYOxBcCRCPLnrFCVXpw7UA",
	"expires_in": 3600,
	"token_type": "Bearer"

Uploading an image to Aspose cloud

Let’s start with a very simple image (source.png):

Image to recognize

Right-click the image and click Save image as to save a file to your computer. Now upload the file to the online storage, created on the previous step:

  1. Open Files page of Aspose Cloud API Dashboard.
  2. Select samples storage.
  3. Drag the source.png file to the storage.

Converting an image to text

Make the following API call:

curl --location --request GET 'https://api.aspose.cloud/v3.0/ocr/source.png/recognize?storage=samples' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...HaRYOxBcCRCPLnrFCVXpw7UA' \

Where source.png is a name of the image file and samples is the name of the Aspose cloud storage. Read the description of /ocr/{name}/recognize API call in Aspose.Ocr Cloud API Reference for more information on the request parameters.

Wait a seconds or two. You will get the following response:

	"text": "All men live enveloped in whale-lines.",
	"pdf": null,
	"hocr": null,
	"status": "200",
	"statusMessage": "success",
	"code": 200

text property of the response body will contain the recognized text.

Live code sample

Ready to recognize Recognizing Drop a file here or click to browse *

* By uploading your files or using the service you agree with our Terms of use and Privacy Policy.

curl --location --request GET 'https://api.aspose.cloud/v3.0/ocr/<file name>/recognize?storage=samples' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {YOUR JWT TOKEN}' \
Recognition result

What’s next?

Congratulations! You have successfully recognized the text in the image. Read the Developer’s reference and API Reference for details on creating advanced OCR solutions with Aspose.Ocr Cloud.

You can also check Aspose.OCR Cloud GitHub repositories for code examples in various programming languages, demonstrating advanced OCR API capabilities. If you like to add or improve an example, we encourage you to contribute to the project. Fork the repository, edit the source code and create a pull request. We will review the changes and include it in the repository if found helpful.