Quantcast
Channel: Veon Consulting
Viewing all articles
Browse latest Browse all 166

Get to know to use OCR within PHP to convert image to text

$
0
0

For various business reasons, you may want to convert an image file to text. Programs can be written to to achieve this using optical character recognition (OCR). Considering that many web applications are being written in PHP, lets take this opportunity to see how OCR can be leveraged within PHP to convert an image to text. Also refer to the article below to understand the use cases of image to text conversion.

Looking for a PHP development team? Reach out to us. 

If you want a little more background on how what optical character recognition is you can find this link useful. Tesseract is one of the popular OCR engine, which was developed by Hewlett Packard and now works with most of the platforms and various programming languages. Since it works very well with PHP, we will be using Tesseract for this example.


PHP OCR image to text conversion using Tesseract

In this section of the article, we will explore the image to text conversion in a step by step manner. For this the first step is to install Tesseract. You can find the steps to install the same below.

Get to know the top things you must consider before outsourcing PHP developments.

#1. Install Tesseract

The fist step in this exercise would be to install Tesseract. Following are the instructions on how the library can be installed in Ubuntu and macOS operating systems.

For Ubuntu 18.04 users

$ sudo apt install tesseract-ocr

For macOS Users

$ brew install tesseract --with-all-languages

#2. Add PHP library to interact with the OCR to the project

The next step is to enable / add the Tesseract library so that it is available for PHP scripts. Following is the command to do the same.

$ composer require thiagoalessio/tesseract_ocr

#3. Sample PHP code to invoke image to text conversion

Given below is a sample PHP code which takes the path of an image file from the file directory. It uploads the file before calling the Tesseract library and converts the same into text and outputs the same on the display.

The following code is sample code to access the OCR engine to upload a image file from a directory and process it for text conversion.

/*

 * If image file uploaded correctly then process image with the OCR

 */

if ($uploadOk) {

    $data = (new TesseractOCR($targetImageFile))

            ->lang('eng')

            ->run();

    file_put_contents('uploads/text.txt', $data);

}

Use case of image to text conversion

Following are some of the use cases for image to text conversion we have come across for parsing the image into text file.

CRM image upload

Many a times, sales representatives are in a hurry to gather information. Many a times, the information may be in a picture format. They would want it to be in a text format so that it can be used to update the respective customer record and be available for reporting.

Check out our CRM development service offerings.

Toll Tag

Many paid highways use OCR for reading the license plate of vehicles. Depending on the entry and exit points on the highway, the bill is generated and sent to the vehicle owner.

 Statement and journal conversion

For statements and journal entries which are available in picture and need to be entered into financial system, this can be done via OCR.

Coupon and Promotion via mobile APP picture data upload

Mobile APP users may want to capture pictures and get it converted to text before getting it uploaded to back end system. Information such as voucher and coupons can be scanned. Check out the popular OCR APP on Apple Store.

Fleet Tracking

Large fleet owners want to track entry and exit of cars into the parking. For this an OCR application can be used to read the movement of the cars.

Mobile Banking / Check upload 

If you are looking at building a banking application which can upload checks, you can use this concept to validate check information like amount, routing number and account number. Kindly note that this may require an additional layer of MICR instead of mere OCR.

From the above use cases, we can understand that OCR can tremendously improve user experience. We really hope that you learnt all about using image to text conversion using OCR in PHP. We wish you all the best for your next development project.


Evaluating SugarCRM for your business – We can help

Reach out to us so that we can assess and plan a road-map for your PHP development needs. Let’s build a system, which you will use for years to come.

Contact us for a free assessment


Viewing all articles
Browse latest Browse all 166

Trending Articles