PHP: Detecting ID from a Scanned Document using Bubbled-In Numbers - php

I am working on a form that can be scanned in and uploaded to my server. I need a script (preferably PHP, but others are welcome) that can read in a 4-digit ID number from the form.
My current plan for the form is to have a table like this:
So, the plus marks show the boxes or bubbles that a person has filled in using a pen. In this example, the ID would be '2014.'
My question is, what is the best way to detect which digits have been filled in?
I assume I should color code the table so that I can find the rgb values within that color range so I know where the table starts and ends. Then I assume I could use the position of each box and check that area to see if the average values inside are above a given threshold.
Anyone done anything similar to this or have any advice / scripts that may help solve this?

Use a barcode of a suitable format, and use a library to read and decode the barcode. I've linked php-zbarcode, which uses ImageMagick and zbar and can decode most barcode formats, including QR codes.

Related

How does Image-Based search works?

I have been working on a eCommerce project and now I am trying to implement search based on image .I have searched the web for possible solution.I came to know google and yahoo has stopped its support for image search API.I would like to know what needs to be extracted from an image and based on what i need to search in my db.Any suggestions will be helpful.Thanks
If you want a brute force method, you can calculate the hash of each image, store it in a database and calculate the hash of the file to search for, match it with the database and well... now you found the exact match of the image.
That may be useful in some situations, but in most you would want to find "similar" images. You could extract meta data from the image, like date taken, filename, etc. If you want to search your own fotoalbum, it is likely that images taken around the same time, are near the same location and thus contain the same content.
Google uses an (as far as I know) unknown method to take a part of the image and search using that information. For example: if you split the image in a X by Y grid and calculate the mean colour value, you can search the database for a match (obviously, you'll have to do this for every image and store the result in the database). If you allow a certain difference in value between the search image and database values, you are likely to find another image that is similar. Searching for only a part of the image, in the database, allows you to find pictures that look the same, but are moved.
Microsoft has created photoDNA, a method that finds the "edges" of the objects in the picture, turning it in a black-white image. Than they resize it to a small resolution and calculate a has. Using this method, you can find photo's that are near to the same, but slightly differ. Ideal if you want to find edited images and resized images.
Another method is to calculate the colour spectrum of the image, normalise it and search for that (with small variations) in a database. Than you'll get images that have near to the same colours, yet the content can be entirely different!
Deep learning could also be an option, if you have allot of images of the same object. By training the computer (e.g. with nVidea cuda), you can make the model recognise objects. If you than search with a photo with a dog on it, your result might be other images with a dog on it.
In summary: there are allot of different methods, each and every one has its own strength and weaknesses, but one they have in common: it's not easy to make!

Table data extraction from image or scanned documents (Not pdf)

I want to extract the table data from images or scanned documents and map the header fields to their particular values mostly in an insurance document.I have tried by extracting them line by line and then mapping them using their position on the page. I gave the table boundary by defining a table start and end pivot, but it doesn't give me proper result, since headers have multiple lines sometimes (I had implemented this in php). I also want to know whether I can use machine learning to achieve the same.
For pdf documents I have used tabula-java which worked pretty well for me. Is there a similar type of implementation for images as well?
Insurance_Image
The documents would be of similar type as in the link above but of different service providers so a generic method of extracting such data would be very useful.
In the image above I want map values like Make = YAMAHA, MODEL= FZ-S, CC= 153 etc
Thanks.
I would definitively give a go to Tesseract, a very good OCR engine. I have been using it successfully in reading all sorts of documents embedded in emails (PDF, images) and a colleague of mine used it for something very similar to your use case - reading specific fields from invoices.
After you parse the document, simply use regex to pick the fields of interest.
I don't think machine learning would be particularly useful for you, unless you plan to build your own OCR engine. I'd start with existing libraries, they offer very good performance.
The easiest and most reliable way to do it without much knowledge in OCR would be this:
- Take an empty template for reference and mark the boxes coordinates that you need to extract the data from. Label them and save them for future use. This will be done only once for each template.
- Now when reading the same template, resize it to match the reference templates dimensions (If it's not already matching).
- You have already every box's coordinates and know what data it should contain (because you labeled them and saved them on the first step).
Which means that now you can just analyze the pixels contained in each box to know what is written there.
This means that given a list of labeled boxes (that you extracted in the first step), you should be able to get the data in each one of these boxes. If this data is typed and not hand written the extracted data would be easier to analyze or do whatever you want with it using simple OCR libraries.
Or if the data is always the same size and font like your example template above, then you could just build your own small database of letters of that font and size. or maybe full words? Depends on each box's possible answers.
Anyway this is not the best approach by far but it would definitely get the work done with minimal effort and knowledge in OCR.

merge two file pdf into one file override?

I have two file pdf, 1st file containing the chart and 2nd file contains information chart.
How to pair the two files back together, right with the position of each page.
I using php,apache2,ubuntu.
Thanks!
Well your question is very ambiguous but going by what I understand, I think you would first need to extract the contents of both pdf's and then map them according to their values from pdf1 to pdf2. For this you can use Tesseract OCR to extract the data and then by writing your code you can try and match them according to their position on page.
Maybe if you just elaborate your question a bit I could help you more.

How to search through a gallery of photos containing QR Codes for a character string

I have a folder of images, each containing a QR Code within the picture which acts as a unique identifier for that image. Each QR Code represents an "Order Number" in the form of "SO12345"
What would be great is if I could just upload these photos to something like dropbox, and then type an order number into the search box and find the image that contains the QR Code equivalent of that search phrase.
Is there an existing service that can do this? Or would it have to be custom written? Is there a PHP library I could use?
Assuming it has to be done using a PHP library, there are 2 ways I could see doing this.
Each time you search for a character phrase, it has to loop through each image 1 by 1 till it either completes with no matches, or finds a match, this format would take longer and longer as the directory increases in size.
Or
Have a function loop through every image as they are uploaded, and if it finds a QR Code, it decodes it and either changes the file name to the QR Code value, or it updates a MySQL row table to associate the QR Code value with the file name. Then the search function searches for a match in file name, or a match in MySQL row value.
Ideally I would rather not reinvent the wheel if necessary. But if it has to be done I would appreciate any help you can offer on where to start to accomplish this.
You could upload the photos to google drive and just name the pictures the QR code. Then just search the QR code in the google drive and it should come up.

Getting data from a Barcode Scanner using PHP

I've read a couple of posts here on the site and as far as I understand it, using PHP to get and process the information obtained through a Barcode Scanner is possible, however I'd like to ask just to make sure, is it recommended? are there any caveats I should be aware of?
EDIT
I don't know the software of the barcode scanner since I haven't had access to it, however I described how it works on the comments down here. the barcode generates a fixed number of characters so I guess I could use a javascript event listener =)
I've noticed a lot of stores use online or LAN POS sites to handle purchases. Typically, the add an item page will set focus to a text field devoted to the product's barcode. When the scanner scans the barcode it's been preconfigured to output the code to wherever the cursor is (in this case, the barcode text field). Most system then have a JavaScript event listener on the field that submits the new item when a barcode is entered (the field reaches a certain length). Of course this is all theory. If you want sample code, please provide more specifics on the scanner and the software it came with.

Categories