Code viewer for World: HTML
// Function to perform OCR using Azure Computer Vision API
async function performOCR() {
    const subscriptionKey = 'ff952ab532914688a855f238573a97dc'; // Replace with your subscription key
    const endpoint = 'https://suraksha.cognitiveservices.azure.com'; // Replace with your API endpoint

    const imageUrl = '/uploads/shettys3/text.png'; // Replace with the URL of the image to analyze

    const ocrUrl = `${endpoint}/vision/v4.0/ocr`;

    const params = {
        language: 'en', // Language code for OCR
        detectOrientation: 'true' // Detect text orientation
    };

    const requestOptions = {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Ocp-Apim-Subscription-Key': subscriptionKey
        },
        body: JSON.stringify({ url: imageUrl, ...params })
    };

    try {
        const response = await fetch(ocrUrl, requestOptions);
        if (!response.ok) {
            throw new Error(`Error: ${response.status} - ${response.statusText}`);
        }

        const data = await response.json();
        // Handle the OCR response data here
        console.log('OCR Result:', data);
        return data;
    } catch (error) {
        console.error('Error performing OCR:', error);
        throw error;
    }
}

// Call the function to perform OCR
performOCR();