Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
    • Yandex Cloud Partner program
  • Blog
  • Pricing
  • Documentation
© 2025 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
    • Generating a resource-by-resource cost breakdown report using S3 Select
    • Server-side encryption
    • Integrating an L7 load balancer with CDN and Object Storage
    • Blue-green and canary deployment of service versions
    • Analyzing logs in DataLens
    • Mounting buckets to the file system of Yandex Data Processing hosts
    • Using Object Storage in Yandex Data Processing
    • Importing data from Object Storage, processing and exporting to Managed Service for ClickHouse®
    • Mounting 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
    • Recognizing audio files in a bucket on a regular basis
    • 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 Managed Service for Greenplum® 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
    • 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
    • Migrating data from Elasticsearch to Yandex Managed Service for OpenSearch
    • Uploading Terraform states to Object Storage
    • Locking Terraform states using Managed Service for YDB
    • Visualizing Yandex Query data
    • Publishing game updates
    • VM backups using Hystax Acura
    • Backing up to Object Storage with CloudBerry Desktop Backup
    • Backing up to Object Storage with Duplicati
    • Backing up to Object Storage with Bacula
    • Backing up to Yandex Object Storage with Veeam Backup
    • Backing up to Object Storage with Veritas Backup Exec
    • Managed Service for Kubernetes cluster backups in Object Storage
    • Developing a custom integration in API Gateway
    • URL shortener
    • Storing application runtime logs
    • Developing a skill for Alice and a website with authorization
    • Creating 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
    • Exporting audit logs to SIEM Splunk systems
    • Creating an MLFlow server for logging experiments and artifacts
    • Operations with data using Yandex Query
    • Federated data queries using Query
    • Recognizing text in image archives using Vision OCR
    • Converting a video to a GIF in Python
    • 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®
  • 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 digitizing and uploading images
  • Configure the environment
  • Create a script
  • Double-check the recognition results
  • How to delete the resources you created
  1. Tutorials
  2. Recognizing text in image archives using Vision OCR

Recognizing text in image archives in Yandex Vision OCR

Written by
Yandex Cloud
Improved by
Danila N.
Updated at May 7, 2025
  • 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 digitizing and uploading images
    • Configure the environment
    • Create a script
  • Double-check the recognition results
  • How to delete the resources you created

Using Vision OCR and Yandex Object Storage, you can manage image text recognition and store both the source image archive and recognition results.

To configure a text recognition infrastructure using Vision OCR and automatically export 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 archives.
  6. Prepare a script for recognizing and uploading images.
  7. Double-check the recognition results.

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

Getting startedGetting started

Sign up in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register 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 navigate to the cloud page to create or select a folder for your infrastructure to operate in.

Learn more about clouds and folders.

Required paid resourcesRequired paid resources

The infrastructure costs for image recognition and data storage include:

  • Fee for VM computing resources and disks (see Yandex Compute Cloud pricing).
  • Fee for data storage in a bucket and data operations (see Object Storage pricing).
  • Fee for using a dynamic or static 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 to store the source images and recognition results:

Management console
  1. Go to the management console and select the folder where you will perform the operations.
  2. Select Object Storage.
  3. Click Create bucket.
  4. Enter a name for the bucket consistent with the naming requirements.
  5. In the Object read access field, select Restricted.
  6. In the Storage class field, select Cold.
  7. Click Create bucket.

Create a VMCreate a VM

Management console
  1. On the folder dashboard of the management console, click Create resource and select Virtual machine instance.

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

  3. Under Location, select an availability zone where your VM will reside. If you do not know which availability zone you need, leave the default one.

  4. Under Disks and file storages, select theSSD disk and specify its size: 19 GB.

  5. Under Computing resources, navigate to the Custom tab and specify the required platform, number of vCPUs, and the 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 connect your VM to. If the required network or subnet is not there, create it.
    • Under Public IP address, leave Auto to assign a random external IP address to your VM from the Yandex Cloud pool. Alternatively, select a static address from the list if you reserved one.
  7. Under Access, select SSH key and specify the VM access credentials:

    • Under Login, enter a username. Do not use root or any other reserved names. To perform 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 saved SSH keys in your profile, or you want to add a new key:

      • Click Add key.
      • Enter a name for the SSH key.
      • Upload or paste the contents of the public key file. You need to create a key pair for the SSH connection to a VM yourself.
      • Click Add.

      The SSH key will be added to your organization user profile.

      If users cannot add SSH keys to their profiles in the organization, the added public SSH key will only be saved to the user profile of the VM being created.

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

    • It must be from 2 to 63 characters long.
    • It may 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 until the VM status switches to Running and save the VM’s public IP address required 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 and create a profile.

  3. Make sure the Yandex Cloud CLI runs correctly:

    CLI

    Run this command on the VM:

    yc config list
    

    Result:

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

    Save the folder ID from the folder-id property. This ID is required 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 property. This ID is required 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 these properties, 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 authorized key JSON file.

    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 under the service account, such as vision-profile:

    yc config profile create vision-profile
    

    Result:

    Profile 'vision-profile' created and activated
    
  6. Specify the service account’s authorized key in the profile configuration:

    yc config set service-account-key key.json
    
  7. Get a 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 on the VM operating system. To do this, run this 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) you got when configuring the service account.
    • AWS Secret Access Key: Secret key (secret) you got when configuring the service account.
    • Default region name: ru-central1.
    • Default output format: json.
  4. Make sure the ~/.aws/credentials file contains the correct key_id and secret values:

    cat ~/.aws/credentials
    
  5. Make sure 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 your images that include recognizable text to the bucket.

    Tip

    Use the sample image of the penguin crossing road sign.

  2. To make sure you have uploaded the images, use a request with the bucket name:

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

    aws --endpoint-url=https://storage.yandexcloud.net s3 cp s3://<bucket_name>/ my_pictures --recursive
    
  4. Pack the images into an archive, e.g., my_pictures.tar:

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

    rm -rfd my_pictures
    

Prepare a script for digitizing and uploading imagesPrepare a script for digitizing and uploading images

Configure the environmentConfigure the environment

  1. Install the epel repository for additional packages:

    sudo yum install epel-release -y
    
  2. Install the jq package to process the 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 required for the script to run:

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

    Where:

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

Create a scriptCreate a script

Bash

The script includes these steps:

  1. Create the appropriate directories.
  2. Unpack the image archive.
  3. Process all images one by one:
    1. Encode the image as Base64.
    2. Create a request body for the specific image.
    3. Send the image in a POST request to Vision OCR for recognition.
    4. Save the result to the output.json file.
    5. Extract the recognized text from output.json and save it to a text file.
  4. Pack the text files you got into an archive.
  5. Upload the text files archive to Object Storage.
  6. Delete the auxiliary files.

For your convenience, the script text includes comments to each step.

To implement the script:

  1. Create a file, e.g., vision.sh, and open it in the nano text editor:

    sudo nano vision.sh
    
  2. Copy the Bash script text to vision.sh:

    #!/bin/bash
    
    # Create the appropriate directories.
    echo "Creating directories..."
    
    # Create a directory for recognized text.
    mkdir my_pictures_text
    
    # Unpack the image archive to the directory you created.
    echo "Extract pictures in my_pictures directory..."
    tar -xf my_pictures.tar
    
    # Recognize the images from the archive.
    FILES=my_pictures/*
    for f in $FILES
    # For each file in the directory, perform these actions in a loop:
    do
       # Encode the image as Base64 for sending it to Vision OCR.
       CODEIMG=$(base64 -i $f | cat)
    
       # Create a `body.json` file to send to Vision OCR in 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 result 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 it later.
    IMAGE_BASE_NAME=$(basename -- "$f")
    IMAGE_NAME="${IMAGE_BASE_NAME%.*}"
    
    # Get the text data from the `output.json` file and write it to a .txt file with the same name as the 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
    
    # Move 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 the auxiliary 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 the permissions to run the script:

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

    ./vision.sh
    

Double-check the recognition resultsDouble-check the recognition results

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

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

To stop paying 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 if you reserved one.

Was the article helpful?

Previous
Federated data queries using Query
Next
Converting a video to a GIF in Python
© 2025 Direct Cursus Technology L.L.C.