Skip to content

Service which returns text from an image when the url for the image is provided.

License

Notifications You must be signed in to change notification settings

mismaah/ocr-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OCR Service

Uses gosseract (wrapper for tesseract-ocr) to provide a Service which returns text from an image when the url for the image is provided.

Quick Start

Clone repository and navigate to directory

git clone https://github.com/mismaah/ocr-service.git

cd ocr-service

Build and tag docker image

docker build . -t ocr-service

Run docker container

Environment variables are set during container runtime by passing the .env file to the container. The .env.example file can be renamed to .env and filled prior to this.

AUTH_KEY is an optional variable. Setting this variable prevents access to the service if the key is not provided in the GET request. If this variable is not set, the service is available without authorization.

Port 8080 from the container is mapped to the system's port 8080. This can be any port but make sure that it is the same as the PORT environment variable.

docker run -p 8080:8080 --env-file .env ocr-service

An alternative is to set each environment variable individually, for example:

docker run -p 8080:8080 -e PORT='8080' -e AUTH_KEY='secretkey123' ocr-service

Send GET Request

Using CURL

curl -H "Authorization:secretkey123" http://localhost:8080/imagetotext?url=https://image.png

Using Go

url := "http://localhost:8080/imagetotext?url=https://image.png"
request, _ := http.NewRequest("GET", url, nil)
request.Header.Set("Authorization", "secretkey123")
client := &http.Client{}
response, _ := client.Do(request)

Using JavaScript (axios)

axios({
  url: "http://localhost:8080/imagetotext?url=https://image.png",
  method: "GET",
  headers: { Authorization: "secretkey123" },
});

Response

If successful, returns the text from the image:

{
  "text": "Example text from the image."
}

If error, returns the error message:

{
  "error": "Error reading from image."
}

About

Service which returns text from an image when the url for the image is provided.

Topics

Resources

License

Stars

Watchers

Forks