OCR (Optical character recognition) is a technology which scans images to recognize texts of them. Tesseract
is a library of OCR engine which is a free and also have a nice recognition rate.
We develop an API in NestJS using tesseract.js
which is a javascript version of Tesseract
. The API contains an example usage of tesseract.js
in language, Korean and English, via uploading image files to be recognized. Furthermore, we develop specific area recognition within 4-area (top-left, top-right, bottom-left, and bottom-right).
npm install
Main dependencies are also commented in codes. We can use them.
npm run start
npm run test
We have some unit tests to experience OCR as examples.
See tesseract.constant.ts
.
When we start the codes, NestJS server runs with port number 3000 in default. Now, we can POST
to API.
Name | Value |
---|---|
API | http://localhost:3000/tesseract/upload |
Method | POST |
Content-Type | multipart/form-data |
In Body
, image files must be uploaded and options can be appended. Uploading image files without any options are recognized in all areas. If match KEY
between of files and data, the data is used as an option.
Here is an example in body of uploading 2 image files.
Key | Value | Mandatory |
---|---|---|
book | book.png | Mandatory |
book | top-left | Optional |
code | code.jpg | Mandatory |
code | bottom-right | Optional |
Then, top-left
of book.png
and bottom-right
of code.jpg
are recognized, respectively.
If recognized results are ridiculous, you can doubt resizing of images. 'Resizing' can export incorrect results. It is recommended that you should check the images by adding an extension(.png) to the uploaded file in 'upload' directory.
[1] Github naptha/tesseract.js