newer version azure ocr is slower than before how to make it faster

Gökhan Dumlupınar 20 Reputation points
2025-10-04T11:29:56.64+00:00

I am trying to working on azure ocr

as a recommended ı tried to use new version but it is slower then before do ı making wrong here

-- 4.0 version

import { AzureKeyCredential } from '@azure/core-auth';

const createAzureClient = require('@azure-rest/ai-vision-image-analysis').default;

const azureEndpoint = process.env.AZURE_ENDPOINT;

const azureApiKey = process.env.AZURE_API_KEY;

// Validation

if (!azureEndpoint || !azureApiKey) {

throw new Error('Azure credentials not configured');

}

if (!azureEndpoint.startsWith('https://')) {

throw new Error('Azure endpoint must use HTTPS');

}

const credential = new AzureKeyCredential(azureApiKey);

const client = createAzureClient(azureEndpoint,credential);

const features = ['Read'];

const imageBuffer = Buffer.from(base64Image,'base64');

const result = await client.path("/imageanalysis:analyze").post({

body: imageBuffer,

queryParameters: {features},

contentType: 'application/octet-stream',

});

const iaResult = result.body;

rawData = iaResult;

extractedText = iaResult.readResult?.blocks.map(block =>

block.lines.map(line => line.text).join('\n')

).join('\n\n') || '';

break;

-- 3.2 version

const azureEndpoint = process.env.AZURE_ENDPOINT;

const azureApiKey = process.env.AZURE_API_KEY;

// Validation

if (!azureEndpoint || !azureApiKey) {

throw new Error('Azure credentials not configured');

}

if (!azureEndpoint.startsWith('https://')) {

throw new Error('Azure endpoint must use HTTPS');

}

const response = await fetch(

${azureEndpoint}/vision/v3.2/ocr?language=unk&detectOrientation=true,

{

method: 'POST',

headers: {

'Ocp-Apim-Subscription-Key': azureApiKey,

'Content-Type': 'application/octet-stream',

},

body: Buffer.from(base64Image, 'base64'),

},

);

const data = await response.json();

if (!response.ok) {

throw new Error(data.error?.message || 'Azure OCR failed');

}

// Optimized parsing

const textParts = [];

for (const region of data.regions) {

const regionText = [];

for (const line of region.lines) {

const words = line.words.map((w) => w.text);

regionText.push(words.join(' '));

}

textParts.push(regionText.join('\n'));

}

extractedText = textParts.join('\n\n');

break;

}

Computer Vision
Computer Vision
An Azure artificial intelligence service that analyzes content in images and video.
{count} votes

Answer accepted by question author
  1. SRILAKSHMI C 8,295 Reputation points Microsoft External Staff Moderator
    2025-10-06T06:54:48.4666667+00:00

    Hello Gökhan Dumlupınar,

    Welcome to Microsoft Q&A and Thank you for reaching out.

    I understand that you are experiencing slower performance with Azure OCR v4.0 / Image Analysis SDK compared to the previous v3.2. This is a common scenario because the newer version is more feature-rich and extensible, which can introduce additional processing time.

    Azure OCR v4.0 (AI Vision / Image Analysis SDK) supports multiple features in a single call, such as Read, Object Detection, and Tags. This broader feature set can increase latency, especially if unnecessary features are enabled.

    In your sample, you correctly enabled features = ['Read']. Ensure only required features are used. Avoid sending images with extra features, as this can significantly increase processing time.

    Ensure images meet recommended input requirements: text height of at least 12 pixels, and image dimensions between 50x50 and 10,000x10,000 pixels. Resize large images before sending them to the API, as high-resolution images take longer to process.

    Confirm that images are correctly oriented and in a supported format (JPEG, PNG, BMP). For complex documents, consider splitting images into smaller parts to simplify processing.

    v4.0 provides both synchronous and asynchronous modes for OCR (Read API). For large documents or high-resolution images, using the async Read API (analyzeRead / ReadResults) allows background processing and can improve perceived performance.

    Reduce repeated requests by batching multiple images when possible. Ensure your client is in a region close to the service endpoint to minimize network latency. You can also monitor network performance using Azure Monitor to identify any bottlenecks.

    Using a Free tier (F0) may limit availability and performance. Upgrading to a higher tier (like S0) can improve processing speed and reliability.

    For pure OCR tasks where speed is critical, using the REST endpoint for the Read API can sometimes be faster than the full Image Analysis SDK due to reduced processing overhead.

    To optimize OCR performance in v4.0 while retaining accuracy:

    Enable only the required features (Read only).

    Use smaller or preprocessed images.

    Consider async Read API for large images or multi-page documents.

    Monitor network and service tier performance.

    Evaluate REST API usage for minimal overhead in pure OCR tasks.

    I Hope this helps. Do let me know if you have any further queries.

    Thank you!

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.