Optical Character Recognition

Optical Character Recognition

  • Category: Text Analysis


Utilizing OCR.Space OCRAPI

OCR.Space OCRAPI is a public API that can be used for Optical Character Recognition. It helps to extract text from images and convert them into editable formats. Here we will learn how to use OCR.Space OCRAPI in our JavaScript project.

The API's endpoint URL is https://api.ocr.space/parse/image and requires an API key. Go to the OCR.Space OCRAPI website and sign up for an API key.

Installing Required Libraries

To utilize the OCRAPI, we need to install axios to send HTTP requests and FormData to parse the data. Both can be installed using npm.

npm install axios form-data

Uploading Data to OCRAPI

The OCRAPI needs a multipart/form-data format of the image file. For this, we use the FormData class in JavaScript. Let's create a function that uploads an image file to OCRAPI and returns the output.

async function ocrSpaceAPI(imgFile) {
    const apiUrl = 'https://api.ocr.space/parse/image'
    const apiKey = '<your_api_key_here>'
    const formData = new FormData()
    formData.append("file", imgFile)

    const config = {
        headers: {
            'content-type': 'multipart/form-data'
        },
        data: formData
    }

    const { data } = await axios.post(apiUrl, config, {
        params: {
            'apikey': `${apiKey}`,
            'language': 'eng',
            'isOverlayRequired': 'false'
        }
    })
    return data
}

This function will take the image file as an argument and return the OCR output as JSON.

Utilizing the Output

Now that we have the JSON output, we need to extract the relevant information from it. Here's an example of extracting the text from a JSON output:

const imgFile = document.querySelector('#imgFile')
imgFile.addEventListener('change', async function() {
    const file = this.files[0]
    const ocrOutput = await ocrSpaceAPI(file)
    alert(ocrOutput.ParsedResults[0].ParsedText)
})

This code will create an event listener on the input element with an id of imgFile. When the file is changed, the OCRAPI will be called, and the extracted text will be displayed as an alert.

Conclusion

In conclusion, OCR.Space OCRAPI is a powerful tool to extract text from images. With this short guide, you should understand how to use the OCRAPI in your JavaScript project.

Visit to Optical Character Recognition website

Similar APIs of Text Analysis

Name Parser

Name Parser

Text Analysis

Name Parser is an API service that splits a complete name into useful information such as first name, last name, gender and nationality.

nameparsergender

Cloudmersive Natural Language Processing

Cloudmersive Natural Language Processing

Text Analysis

Natural language processing and text analysis. The most powerful and cost-effective NLP AI APIs, continuously updated. The most powerful and cost-effective NLP AI APIs, continuously updated. Automatically rephrase, or paraphrase an input sentence into alternate, gramatically correct text that preserves the original meaning. Automatically classify the sentiment of input text into Positive, Negative, or Neutral and a corresponding sentiment strength score. Identify the part of speech of words in a sentence. Pull out all the verbs, nouns, proper nouns, etc. from a sentence. Identify the true meaning. Fully parse a sentence into its constituent structure. Perform analytics over unstructured text to identify sentiment, key words and phrases, and much more. Identify the key entities that are referenced in unstructured text. Automatically detect the language of a text string across the world's 14 most popular languages.

translationrephrasingsentiment

Language Detection API

Language Detection API

Text Analysis

Detects text language. Language identification JSON webservice accepts text and returns detected language code and score. Detects 164 languages Fast, supports batching Supports short phrases and single words Secure

languagefastsupport

Google Cloud Natural

Google Cloud Natural

Text Analysis

Natural language understanding technologies to developers, including sentiment, entity, and syntax analysis. This API is part of the larger Cloud Machine Learning API family.

languagenaturalcloud

Semantira

Semantira

Text Analysis

Text Analytics with sentiment analysis, categorization & named entity extraction. Uncover context-rich patterns and insights hidden within mountains of social comments, surveys, reviews, and any other text documents See who’s talking, what they’re talking about, how they feel, and why.

richcontextinsights

Aylien Text Analysis

Aylien Text Analysis

Text Analysis

A collection of information retrieval, and natural language APIs. A content analysis API used for collecting and analyzing news content at scale. An easy-to-use API used to perform a variety of complex NLP tasks on documents, reviews, social comments, or any other type of text. A user friendly platform that makes training custom NLP models easy.

analysissearchfeed

Watson Natural Language Understanding

Watson Natural Language Understanding

Text Analysis

Natural language processing for advanced text analysis. Analyze various features of text content at scale. Provide text, raw HTML, or a public URL and IBM Watson Natural Language Understanding will give you results for the features you request. The service cleans HTML content before analysis by default, so the results can ignore most advertisements and other unwanted content.

rawhtmlanalytics