Please bookmark this page to avoid losing your image tool!

Image Verb Finder

(Free & Supports Bulk Upload)

Drag & drop your images here or

The result will appear here...
You can edit the below JavaScript code to customize the image tool.
/**
 * Identifies Russian verbs in an image using OCR and highlights them.
 * This function performs Optical Character Recognition (OCR) on the input image
 * to extract Russian text. It then uses a heuristic approach to identify words
 * that are likely verbs based on their endings. The identified verbs are
 * highlighted on a new canvas which is returned.
 *
 * @param {HTMLImageElement} originalImg The original image object to be processed.
 * @returns {Promise<HTMLCanvasElement>} A promise that resolves to a canvas element
 * with the original image and highlighted verbs.
 */
async function processImage(originalImg) {

    /**
     * Dynamically loads a script from a given URL.
     * @param {string} url The URL of the script to load.
     * @returns {Promise<void>} A promise that resolves when the script has loaded.
     */
    const loadScript = (url) => {
        return new Promise((resolve, reject) => {
            if (document.querySelector(`script[src="${url}"]`)) {
                resolve();
                return;
            }
            const script = document.createElement('script');
            script.src = url;
            script.onload = () => resolve();
            script.onerror = (err) => reject(new Error(`Failed to load script: ${url}`));
            document.head.appendChild(script);
        });
    };

    /**
     * A heuristic function to check if a Russian word is a verb based on its ending.
     * NOTE: This is a simplified approach and is not 100% accurate. It may produce
     * false positives (e.g., nouns ending in 'ть' like 'мать') and miss some verb forms.
     * @param {string} word The word to check.
     * @returns {boolean} True if the word is likely a verb, false otherwise.
     */
    const isRussianVerb = (word) => {
        if (!word || word.length < 2) return false;
        const lowerWord = word.toLowerCase();

        // Common nouns or other words that are frequent false positives.
        const exceptions = [
            'мать', 'пять', 'шесть', 'семь', 'восемь', 'девять', 'десять', 'кость',
            'часть', 'гость', 'соль', 'боль', 'цель', 'ночь', 'дочь', 'речь'
        ];
        if (exceptions.includes(lowerWord)) {
            return false;
        }

        // A list of common Russian verb endings, sorted by length to avoid partial matches.
        const verbEndings = [
            'ешь', 'ете', 'ишь', 'ите',
            'ть', 'ти', 'чь', 'ла', 'ло', 'ли', 'ют', 'ят',
            'ем', 'ет', 'им', 'ит', 'ат', 'л', 'ю', 'у'
        ].sort((a, b) => b.length - a.length);

        return verbEndings.some(ending => lowerWord.endsWith(ending));
    };

    // --- Main Processing ---

    const canvas = document.createElement('canvas');
    canvas.width = originalImg.naturalWidth;
    canvas.height = originalImg.naturalHeight;
    const ctx = canvas.getContext('2d');
    ctx.drawImage(originalImg, 0, 0);

    // Helper to draw status messages on the canvas
    const drawStatus = (message) => {
        ctx.fillStyle = 'rgba(0, 0, 0, 0.6)';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        ctx.font = `bold ${Math.min(48, canvas.width / 15)}px 'Arial'`;
        ctx.fillStyle = 'white';
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';
        ctx.fillText(message, canvas.width / 2, canvas.height / 2);
    };

    try {
        await loadScript('https://cdn.jsdelivr.net/npm/tesseract.js@5/dist/tesseract.min.js');
    } catch (error) {
        console.error(error);
        drawStatus('Ошибка: не удалось загрузить библиотеку OCR.');
        return canvas;
    }

    drawStatus('Анализ изображения...');

    const worker = await Tesseract.createWorker('rus', 1, {
        logger: m => {
            if (m.status === 'recognizing text') {
                 drawStatus(`Распознавание... ${Math.round(m.progress * 100)}%`);
            }
        }
    });

    try {
        const { data: { words } } = await worker.recognize(originalImg);
        
        // Redraw original image to clear the status message
        ctx.drawImage(originalImg, 0, 0);

        ctx.fillStyle = 'rgba(255, 255, 0, 0.4)'; // Yellow highlight fill
        ctx.strokeStyle = 'rgba(255, 165, 0, 0.9)'; // Orange border
        ctx.lineWidth = 1;

        for (const word of words) {
            // Clean the word of punctuation for analysis.
            const cleanedText = word.text.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()?]/g, "").trim();
            if (word.confidence > 60 && isRussianVerb(cleanedText)) {
                const { x0, y0, x1, y1 } = word.bbox;
                const width = x1 - x0;
                const height = y1 - y0;
                ctx.fillRect(x0, y0, width, height);
                ctx.strokeRect(x0, y0, width, height);
            }
        }

    } catch (error) {
        console.error('OCR process failed:', error);
        ctx.drawImage(originalImg, 0, 0);
        drawStatus('Ошибка при распознавании текста.');
    } finally {
        await worker.terminate();
    }

    return canvas;
}

Free Image Tool Creator

Can't find the image tool you're looking for?
Create one based on your own needs now!

Description

The Image Verb Finder is a tool designed to identify and highlight Russian verbs in images using Optical Character Recognition (OCR). When provided with an image containing Russian text, the tool processes the image to extract the text, analyzes the words to determine which are likely to be verbs based on their endings, and highlights those verbs in a visually distinct way on a new canvas. This can be particularly useful for language learners or educators looking to study verb usage in context, as well as for anyone needing to analyze Russian text for specific verb identification.

Leave a Reply

Your email address will not be published. Required fields are marked *