Text OCR API call

Prev Next

Available in Classic and VPC

After completing template registration in the CLOVA OCR Builder and finishing testing and service deployment, you can use CLOVA OCR via a REST API. This section explains how to send an image to the TEXT OCR API and receive the recognition results, along with an example.

Note
  • Template OCR also can call API in the same way.
  • For more information on API call, see CLOVA OCR API guide.

The following is a description on the steps to enter and convert images through TEXT OCR API and details of each step.

1. API environment settings

To control TEXT OCR using the API, you must first create a domain in CLOVA OCR on the NAVER Cloud Platform console. When you create a domain in the OCR Builder, a unique InvokeURL is assigned. The InvokeURL is not exposed directly to external services for security reasons. It is designed to be used through API Gateway to enhance security and service-level processing.

2. Automatic integrating with API Gateway

To use the InvokeURL, you must integrate with API Gateway. There are two methods of integration—automatic and manual. If you choose automatic integration, you can complete API Gateway linkage conveniently with just a few clicks. In this example, the automatic integration method is introduced. To perform automatic integration:

  1. To create a Secret Key in OCR builder, click [Create].
    image-20191217135217405_ko
  2. To connect API Gateway automatically, click [Automatic integration].
  3. If you are not currently using API Gateway, when the automatic integration popup appears, click [OK] to apply for use.
    image-20191217135507352_ko
  4. Once the integration is complete, copy the Secret Key and the OCR Invoke URL values required for API calls.
    image-20191217135557688_ko
    • Secret Key: {X-OCR-SECRET}
    • OCR Invoke URL: {OCR Invoke URL}

3. API Gateway creation URL check

You must check the API Gateway–generated URL in the API Gateway menu of the NAVER Cloud Platform console. If a product named OCR_CUSTOM_API_KR has been created successfully, API call preparation is complete. To check the API Gateway generating URL:

  1. From the NAVER Cloud Platform console, navigate to i_menu > Services > AI Services > CLOVA OCR.
  2. Click My Products menu.
  3. Check if the product named OCR_CUSTOM_API_KR was created.
    image-20191217144827615_ko
    • If it was successfully created, the API call is ready.

4. API call through Postman

When you execute the Text OCR API, you can extract text from an uploaded image. The image recognition result is returned in JSON format, and you can use the returned values in your own service. To call the Text OCR API:

Note

This section provides a simplified overview of how to call the Text OCR API. For detailed information, see the CLOVA OCR API guide.

  1. Create a new API in Postman and set the call method to POST.
  2. In the Invoke URL address, enter InvokeURL of API Gateway that you created in OCR.
    image-20191217171936809_ko
  3. Enter X-OCR-SECRET information in the Header section.
    image-20191217172419810_ko
    • Content-Type : application/json
    • X-OCR-SECRET : {X-OCR-SECRET }
  4. Add the text OCR call body in an image recognition request body form.
    image-20191217172912524_ko
    {
        "images": [
          {
            "format": "png",
            "name": "medium",
            "data": null,
            "url": "https://kr.object.ncloudstorage.com/ocr-img/OCR_ko(1)REAN_en(1).png"
          }
        ],
        "lang": "ko",
        "requestId": "string",
        "resultType": "string",
        "timestamp": {{$timestamp}},
        "version": "V1"
    }
    
  5. To check the response result, click [SEND].
    image-20191217173003063_ko
  6. Check the response result.
    {
    "version":"V1",
    "requestId":"string",
    "timestamp":1576569034247,
    "images":[
      {
        "uid":"9fd73a6aacad4025b3099a36ee55aacd",
        "name":"medium","inferResult":"SUCCESS","message":"SUCCESS",
        "fields":[
            {"inferText":"나","inferConfidence":0.9967288},
            {"inferText":"하늘로","inferConfidence":0.9998919},
            {"inferText":"돌아가리라","inferConfidence":0.9999104},
            {"inferText":"아름다운","inferConfidence":0.99992156},
            {"inferText":"이","inferConfidence":0.99958915},
            {"inferText":"세상","inferConfidence":0.9998707},
            {"inferText":"소풍","inferConfidence":0.9988277},
            {"inferText":"끝내는","inferConfidence":0.9999253},
            {"inferText":"날","inferConfidence":0.99908936},
            {"inferText":"가서","inferConfidence":0.99974936},
            {"inferText":"아름다웠더라고","inferConfidence":0.9997728},
            {"inferText":"말하리라","inferConfidence":0.9993808}
            ],
        "validationResult":{"result":"NO_REQUESTED"}}
        ]
    }
    
  7. Use the response result in your service.