Yandex Cloud
Search
Contact UsTry it for free
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
  • Marketplace
    • Featured
    • Infrastructure & Network
    • Data Platform
    • AI for business
    • Security
    • DevOps tools
    • Serverless
    • Monitoring & Resources
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
    • Price calculator
    • Pricing plans
  • Customer Stories
  • Documentation
  • Blog
© 2026 Direct Cursus Technology L.L.C.
Yandex Object Storage
    • All tutorials
    • Getting statistics on object queries with S3 Select
    • Getting website traffic statistics with S3 Select
    • Getting statistics on object queries using Yandex Query
    • Cost analysis by resource
    • Server-side encryption
    • Blue-green and canary deployment of service versions
    • Analyzing logs in DataLens
    • Mounting buckets to Yandex Data Processing host filesystems
    • Using Object Storage in Yandex Data Processing
    • Importing, processing, and exporting Object Storage data to Managed Service for ClickHouse®
    • Connecting a bucket as a disk in Windows
    • Migrating data from Yandex Data Streams using Yandex Data Transfer
    • Using hybrid storage in Yandex Managed Service for ClickHouse®
    • Loading data from Yandex Managed Service for OpenSearch to Yandex Object Storage using Yandex Data Transfer
    • Automatically copying objects from one bucket to another
    • Regular asynchronous recognition of audio files in a bucket
    • Training a model in Yandex DataSphere on data from Object Storage
    • Connecting to Object Storage from VPC
    • Migrating data to Yandex Managed Service for PostgreSQL using Yandex Data Transfer
    • Uploading data to Yandex MPP Analytics for PostgreSQL using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for ClickHouse® using Yandex Data Transfer
    • Uploading data to Yandex Managed Service for YDB using Yandex Data Transfer
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Uploading data from Yandex Managed Service for YDB using Yandex Data Transfer
    • Hosting a static Gatsby website in Object Storage
    • Installing WordPress High Availability using Cloud Apps
    • Installing Ghost CMS High Availability using Cloud Apps
    • Migrating a database from Managed Service for PostgreSQL to Object Storage
    • Exchanging data between Yandex Managed Service for ClickHouse® and Yandex Data Processing
    • Importing data from Yandex Managed Service for PostgreSQL to Yandex Data Processing using Sqoop
    • Importing data from Yandex Managed Service for MySQL® to Yandex Data Processing using Sqoop
    • Migrating data from Yandex Object Storage to Yandex Managed Service for MySQL® using Yandex Data Transfer
    • Migrating a database from Yandex Managed Service for MySQL® to Yandex Object Storage
    • Exporting Greenplum® data to a cold storage in Yandex Object Storage
    • Loading data from Yandex Direct to a Yandex Managed Service for ClickHouse® data mart using Yandex Cloud Functions, Yandex Object Storage, and Yandex Data Transfer
    • Uploading Terraform states to Object Storage
    • Locking Terraform states using Managed Service for YDB
    • Visualizing Yandex Query data
    • Publishing game updates
    • Developing a custom integration in API Gateway
    • URL shortener
    • Storing application runtime logs
    • Building a skill for Alice and a website with authorization
    • Building an interactive serverless application using WebSocket
    • Deploying a web application using the Java Servlet API
    • Developing a Telegram bot
    • Replicating logs to Object Storage using Fluent Bit
    • Replicating logs to Object Storage using Data Streams
    • Uploading audit logs to ArcSight SIEM
    • Uploading audit logs to Splunk SIEM
    • Creating an MLFlow server for logging experiments and artifacts
    • Operations with data in Yandex Query
    • Federated data queries using Query
    • Recognizing text in image archives using Vision OCR
    • Scheduled image and PDF recognition in an Object Storage bucket
    • Automating tasks using Managed Service for Apache Airflow™
    • Processing files with usage details in Yandex Cloud Billing
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Searching for Yandex Cloud events in Yandex Query
    • Searching for Yandex Cloud events in Object Storage
    • Creating an external table from a bucket table using a configuration file
    • Migrating databases from Google BigQuery to Managed Service for ClickHouse®
    • Using Object Storage in Yandex Managed Service for Apache Spark™
  • Pricing policy
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Bucket logs
  • Release notes
  • FAQ

In this article:

  • Getting started
  • Required paid resources
  • Create a bucket
  • Create a VM
  • Configure the VM
  • Configure the Yandex Cloud CLI
  • Configure a service account
  • Configure the AWS CLI
  • Create an image archive
  • Prepare a script for image recognition and uploading
  • Set up your environment
  • Create a script
  • Verify the recognition accuracy
  • How to delete the resources you created
  1. Tutorials
  2. Recognizing text in image archives using Vision OCR

Recognizing text in image archives using Yandex Vision OCR

Written by
Yandex Cloud
Improved by
Danila N.
Updated at April 28, 2026
  • Getting started
    • Required paid resources
  • Create a bucket
  • Create a VM
  • Configure the VM
    • Configure the Yandex Cloud CLI
    • Configure a service account
    • Configure the AWS CLI
  • Create an image archive
  • Prepare a script for image recognition and uploading
    • Set up your environment
    • Create a script
  • Verify the recognition accuracy
  • How to delete the resources you created

With Vision OCR and Yandex Object Storage, you can perform text recognition on images and maintain an archive of source images and recognition results.

To set up an Vision OCR infrastructure for image recognition and automatic export of the results to Object Storage:

  1. Get your cloud ready.
  2. Create a bucket.
  3. Create a VM.
  4. Configure the VM.
  5. Create an image archive.
  6. Prepare a script for recognizing and uploading images.
  7. Verify the recognition accuracy.

If you no longer need the resources you created, delete them.

Getting startedGetting started

Sign up for Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or create a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can create or select a folder for your infrastructure on the cloud page.

Learn more about clouds and folders here.

Required paid resourcesRequired paid resources

The cost of supporting the infrastructure for image recognition and data storage includes:

  • Fee for VM computing resources and disks (see Yandex Compute Cloud pricing).
  • Fee for bucket data storage and data operations (see Object Storage pricing).
  • Fee for a static or dynamic public IP address (see Yandex Virtual Private Cloud pricing).
  • Fee for using Vision OCR (see Vision OCR pricing).

Create a bucketCreate a bucket

To create an Object Storage bucket for storing source images and recognition results:

Management console
  1. In the management console, select the folder where you will operate.
  2. Go to Object Storage.
  3. Click Create bucket.
  4. Specify the bucket name that meets these naming conventions.
  5. In the Read objects field, select With authorization.
  6. In the Storage class field, select Cold.
  7. Click Create bucket.

Create a VMCreate a VM

Management console
  1. In the management console, navigate to the folder dashboard, click Create resource, and select Virtual machine instance.

  2. Under Boot disk image, enter CentOS 7 in the Product search field and select a public CentOS 7 image.

  3. Under Location, select an availability zone where your VM will reside. If you are not sure which availability zone you need, leave the default selection.

  4. Under Disks and file storages, select the disk type (SSD) and specify its size (19 GB).

  5. Under Computing resources, switch to the Custom tab and specify the platform, number of vCPUs, and amount of RAM:

    • Platform: Intel Cascade Lake
    • vCPU: 2
    • Guaranteed vCPU performance: 20%
    • RAM: 2 GB
  6. Under Network settings:

    • In the Subnet field, select the network and subnet to which you want to connect your VM. If the network or subnet you need does not exist yet, create it.
    • In the Public IP address field, select a static IP address from the list, or leave Auto to assign your VM a random external IP address from the Yandex Cloud pool.
  7. Under Access, select SSH key and specify the VM access credentials:

    • In the Login field, enter the username. Do not use root or other reserved usernames. For operations requiring root privileges, use the sudo command.
    • In the SSH key field, select the SSH key saved in your organization user profile.

      If there are no SSH keys in your profile or you want to add a new key:

      1. Click Add key.

      2. Enter a name for the SSH key.

      3. Select one of the following:

        • Enter manually: Paste the contents of the public SSH key. You need to create an SSH key pair on your own.

        • Load from file: Upload the public part of the SSH key. You need to create an SSH key pair on your own.

        • Generate key: Automatically create an SSH key pair.

          When adding a new SSH key, an archive containing the key pair will be created and downloaded. In Linux or macOS-based operating systems, unpack the archive to the /home/<user_name>/.ssh directory. In Windows, unpack the archive to the C:\Users\<user_name>/.ssh directory. You do not need additionally enter the public key in the management console.

      4. Click Add.

      The system will add the SSH key to your organization user profile. If the organization has disabled the ability for users to add SSH keys to their profiles, the added public SSH key will only be saved in the user profile inside the newly created resource.

  8. Under General information, specify the VM name. The naming requirements are as follows:

    • Length: between 3 and 63 characters.
    • It can only contain lowercase Latin letters, numbers, and hyphens.
    • It must start with a letter and cannot end with a hyphen.
  9. Click Create VM.

  10. Wait for the VM status to change to Running and save its public IP address; you will need it for SSH connection.

Configure the VMConfigure the VM

Configure the Yandex Cloud CLIConfigure the Yandex Cloud CLI

  1. Connect to the VM over SSH.

  2. Install the Yandex Cloud CLI on your VM and create a profile.

  3. Make sure the Yandex Cloud CLI is working properly:

    CLI

    Run the following command on your VM:

    yc config list
    

    Result:

    token: AQ...gs
    cloud-id: b1gdtdqb1900********
    folder-id: b1gveg9vude9********
    

    Save the folder ID from the folder-id field in the response; you will need it for configuring a service account.

Configure a service accountConfigure a service account

CLI
  1. Create a service account:

    yc iam service-account create \
      --name <service_account_name> \
      --description "<service_account_description>"
    

    Where:

    • --name: Service account name, e.g., vision-sa.
    • --description: Service account description, e.g., this is vision service account.

    Result:

    id: aje6aoc8hccu********
    folder_id: b1gv87ssvu49********
    created_at: "2022-10-12T14:04:43.198559512Z"
    name: vision-sa
    description: this is vision service account
    

    Save the service account ID from the id field in the response; you will need it for further configuration.

  2. Assign the editor role to the service account:

    yc resource-manager folder add-access-binding <folder_ID> \
      --role editor \
      --subject serviceAccount:<service_account_ID>
    

    Where:

    • --role: Role to assign.
    • --subject serviceAccount: Service account ID.
  3. Create a static access key for your service account:

    yc iam access-key create \
      --service-account-id <service_account_ID> \
      --description "<key_description>"
    

    Where:

    • --service-account-id: Service account ID.
    • --description: Key description, e.g., this key is for vision.

    Result:

    access_key:
      id: ajen8d7fur27********
      service_account_id: aje6aoc8hccu********
      created_at: "2022-10-12T15:08:08.045280520Z"
      description: this key is for vision
      key_id: YC...li
    secret: YC...J5
    

    Save the following values, as you will need them to configure the AWS CLI:

    • key_id: Static access key ID
    • secret: Secret key
  4. Create an authorized key for the service account:

    yc iam key create \
      --service-account-id <service_account_ID> \
      --output key.json
    

    Where:

    • --service-account-id.
    • --output: Name of the JSON file containing your authorized key.

    Result:

    id: aje3qc9pagb9********
    service_account_id: aje6aoc8hccu********
    created_at: "2022-10-13T12:53:04.810240976Z"
    key_algorithm: RSA_2048
    
  5. Create a Yandex Cloud CLI profile to run as the service account, e.g., vision-profile:

    yc config profile create vision-profile
    

    Result:

    Profile 'vision-profile' created and activated
    
  6. In the profile configuration, specify the service account’s authorized key:

    yc config set service-account-key key.json
    
  7. Obtain an IAM token for the service account:

    yc iam create-token
    

    Save the IAM token. You will need it to send images to Vision OCR.

Configure the AWS CLIConfigure the AWS CLI

  1. Update the packages installed on your VM’s operating system by running the following command:

    sudo yum update -y
    
  2. Install the AWS CLI:

    sudo yum install awscli -y
    
  3. Configure the AWS CLI:

    aws configure
    

    Specify these settings:

    • AWS Access Key ID: Static access key ID (key_id) that you received when configuring the service account.
    • AWS Secret Access Key: Secret key (secret) that you received when configuring the service account.
    • Default region name: ru-central1.
    • Default output format: json.
  4. Verify that the ~/.aws/credentials file contains the correct key_id and secret values:

    cat ~/.aws/credentials
    
  5. Verify that the ~/.aws/config file contains the correct Default region name and Default output format values:

    cat ~/.aws/config
    

Create an image archiveCreate an image archive

  1. Upload the images with text you want to recognize to the bucket.

    Tip

    Need an example? download an image of the penguin crossing road sign.

  2. Make sure the images were uploaded by sending the following request with your bucket name specified:

    aws --endpoint-url=https://storage.yandexcloud.net s3 ls s3://<bucket_name>/
    
  3. Save the images from the bucket to the my_pictures directory on your VM:

    aws --endpoint-url=https://storage.yandexcloud.net s3 cp s3://<bucket_name>/ my_pictures --recursive
    
  4. Add the images to the my_pictures.tar archive:

    tar -cf my_pictures.tar my_pictures/*
    
  5. Delete the image directory:

    rm -rfd my_pictures
    

Prepare a script for image recognition and uploadingPrepare a script for image recognition and uploading

Set up your environmentSet up your environment

  1. Install the epel repository for additional packages:

    sudo yum install epel-release -y
    
  2. Install the jq package for processing results from Vision OCR:

    sudo yum install jq -y
    
  3. Install the nano text editor:

    sudo yum install nano -y
    
  4. Set the environment variables used by the script:

    export BUCKETNAME="<bucket_name>"
    export FOLDERID="<folder_ID>"
    export IAMTOKEN="<IAM_token>"
    

    Where:

    • BUCKETNAME: Bucket name.
    • FOLDERID: Folder ID.
    • IAMTOKEN: IAM token that you received when configuring the service account.

Create a scriptCreate a script

Bash

The script runs through the following steps:

  1. Creating required directories.
  2. Extracting the image archive.
  3. Processing all images in sequence:
    1. Encoding the image in Base64.
    2. Creating a request body containing the image.
    3. Sending the image to Vision OCR for recognition via a POST request.
    4. Saving the response to the output.json file.
    5. Extracting the recognized text from output.json and saving it to a text file.
  4. Adding the resulting text files to an archive.
  5. Uploading the archive to Object Storage.
  6. Deleting temporary files.

To make things clearer, the script has comments for each step.

To prepare this script:

  1. Create a file named vision.sh and open it in nano:

    sudo nano vision.sh
    
  2. Paste the following Bash script into vision.sh:

    #!/bin/bash
    
    # Create the required directories.
    echo "Creating directories..."
    
    # Create a directory to store the recognized text.
    mkdir my_pictures_text
    
    # Extract the image archive into the new directory.
    echo "Extract pictures in my_pictures directory..."
    tar -xf my_pictures.tar
    
    # Run text recognition on the images from the archive.
    FILES=my_pictures/*
    for f in $FILES
    # Loop through each file in the directory and perform the following steps:
    do
       # Encode the image in Base64 for submission to Vision OCR.
       CODEIMG=$(base64 -i $f | cat)
    
       # Create a `body.json` file that you will send to Vision OCR via a POST request.
       cat <<EOF > body.json
    {
    "mimeType": "JPEG",
    "languageCodes": ["*"],
    "model": "page",
    "content": "$CODEIMG"
    }
    EOF
    # Send the image to Vision OCR for recognition and write the response to the `output.json` file.
    echo "Processing file $f in Vision..."
    curl --request POST \
      --header "Content-Type: application/json" \
      --header "Authorization: Bearer ${IAMTOKEN}" \
      --header "x-data-logging-enabled: true" \
      --header "x-folder-id: ${FOLDERID}" \
      --data '@body.json' \
      https://ocr.api.cloud.yandex.net/ocr/v1/recognizeText \
      --output output.json
    
    # Get the image file name to use later in the request.
    IMAGE_BASE_NAME=$(basename -- "$f")
    IMAGE_NAME="${IMAGE_BASE_NAME%.*}"
    
    # Retrieve the text data from `output.json` and write it to a .txt file named after the original image file.
    cat output.json | jq -r '.result[].blocks[].lines[].text' | awk -v ORS=" " '{print}' > my_pictures_text/$IMAGE_NAME".txt"
    done
    
    # Archive the contents of the text file directory.
    echo "Packing text files to archive..."
    tar -cf my_pictures_text.tar my_pictures_text
    
    # Upload the text file archive to your bucket.
    echo "Sending archive to Object Storage Bucket..."
    aws --endpoint-url=https://storage.yandexcloud.net s3 cp my_pictures_text.tar s3://$BUCKETNAME/ > /dev/null
    
    # Delete temporary files.
    echo "Cleaning up..."
    rm -f body.json
    rm -f output.json
    rm -rfd my_pictures
    rm -rfd my_pictures_text
    rm -r my_pictures_text.tar
    
  3. Set execute permissions for the script:

    sudo chmod 755 vision.sh
    
  4. Run the script:

    ./vision.sh
    

Verify the recognition accuracyVerify the recognition accuracy

Management console
  1. In the Yandex Cloud management console, select the folder containing the bucket with your recognition results.
  2. Go to Object Storage.
  3. Open the bucket with the recognition results.
  4. Verify that the bucket contains my_pictures_text.tar.
  5. Download and unpack the archive.
  6. Verify that the text in the <image_name>.txt files matches the text on the corresponding images.

How to delete the resources you createdHow to delete the resources you created

To stop incurring costs for the resources you created:

  1. Delete all objects from the bucket.
  2. Delete the bucket.
  3. Delete the VM.
  4. Delete the static public IP address if you reserved one.

Was the article helpful?

Previous
Federated data queries using Query
Next
Scheduled image and PDF recognition in an Object Storage bucket
© 2026 Direct Cursus Technology L.L.C.