php - Improving zbar recognition of scanned qr codes - php

I'm trying to read scanned qr codes from php, running zbarimg via exec. Working not-too-bad.
The issue is that it seems to choke on scanning artifacts like these small dots:
I've been trying to get rid of the white dots syndrome by fiddling around with Imagick - changing brightness/contrast/sharpness seems to make them stand out less but some, like this one, are still unreadable.
Is there a way to remove the white dots / improve zbarimg's recognition?
Edit:
One thing I forgot to point out:
What strikes me as weird is the fact that scanning the QR via smartphone, using the camera, reads the code succesfully in a single instant without a single issue, which leads me to think this "fixing up" shouldn't even be needed.
Am I just using zbar the wrong way?
Or do mobile OSes just use a different, better, algorithm? I tried using a zxing wrapper for PHP as well, but it gave even less results compared to zbar.

In terms of cleaning up the image you have shown us, the obvious approach would be to use cellular automata - although for best results you would ant to modify the behaviour to encompass the sharpening and thresholding you are already applying using other filters. You might consider setting the size of the cell to, say, one 25th of the QR code block resolution rather than a 1:1 with pixels in the unerdlying image. Really you should be applying your thresholding via a histogram based approach (assuming that you can isolate the QR code in the image).
I'm not aware of an implementation in PHP but there is at least one OpenCV interface for PHP

Related

How to get the color palette of a website using PHP?

I need to find the common colors used in a particular website.Most of the cases it will be body background,header background etc. But the problem is, some of the classes or IDs override other.So we cannot get the exact color patterns. Is there any way to find the exact color patterns of a website which browser picking?
As Havelock pointed out, the idea that does come to mind is transforming the page into an image, and then getting the color-palette from that. It does however have a few problems:
There is no guarantee, that what the library returns is what the users seens in a particular browser, yet alone all.
The processing needed could be way easier implemented in other languages than PHP. I dont mean, that it cant be done, but it is just not well suited for this task.
If you do however continue along this path, I would recommend trying something with an API, to get your screenshots, and then just using some PHP to parse them. Example for such a service - http://browsershots.org/xmlrpc/
There are several online services to extract colors from websites. Including image colors:
http://www.colorcombos.com/grabcolors.html
http://www.hextractor.com/
more...
A PHP class to extract colors from images can be found here. See also How do I get the Hex Code of a color on my webpage
Also a FireFox Plugin exists.

PDF Verification in PHP

What is the best way in PHP to determine if a PDF is filled out correctly? The source PDF is a faxed form that contains handwritten data. Is an image comparison an option? If the form is filled out on a computer, I know I can use pdftotext to verify that the fields are completed or not. I just don't know how to verify handwritten data.
For hand-written data an image comparison may definitely be an option. See for example the following answer for a basic idea how to start tackling this task:
Imagemagick : “Diff” an Image
However, the job may be much more difficult when faxed images come into play. (We all know how bad a quality you can get from faxes. Also, they frequently are skewed by a small degree. And they may be slightly scaled, compared to the original. Not to forget that their resolution is 204x196dpi, which adds a bit of a distortion. And lastly -- how do you get the faxed form back into PHP? This might involve another step of scanning in the paper, which again will not necessarily add quality to the result.
Still, ImageMagick may be able to handle all this: it can -deskew images, it can reduce or completly remove -noise, and it can -distort, -scale and -repage images and much more...

Is this effect possible with php code, without special software

I've learned to never underestimate what PHP and some libraries can do, so for this paper effect, can it be done with a php graphics library (or at least programmatically) without needing something like Photoshop or Illustrator?
To be clear, I'm asking just about the paper, not the iphone.
Edit: Dan Grossman's answer is great. I'm also wondering if someone can give me algorithmic ideas what might be happening in this image so I could try to possibly come up with some code to map it mathematically. My visual imagination is failing me a little.
The answer is always yes, it's just a matter of difficulty/complexity.
PHP is a Turing-complete language, which means it has equal capabilities of every other Turing-complete language, like C++/Java or whatever your photo editing program was written in.
That means whatever Photoshop does, you can do. If nobody has written a handy library, you can treat the image as a matrix and perform the mathematics necessary to get the desired warping, then write the resulting matrix of pixel information to a new image one pixel at a time as a bitmap.
Of course you weren't hoping for that answer, you meant "does someone provide an easy library for PHP to do effects like this with a couple prewritten commands", right?
That's a little much for PHP's GD library, but you can always shell out to a command line image processor, like imagemagick, and read the resulting file to send back to the browser.
Imagemagick has plenty of distortion methods which will help you get to where you want. However with the detail you've given you'll need to do the math yourself to work out the correct combination of distortions to get the page curl you're after

Recognizable numbers using PHP

I’m trying to extract some numbers ranging from 1-99 from a picture. I’ve tried several OCR methods using PHP, but eventually my script will fail, since the numbers occasionally is rotated 5% to the left or right. This making the picture not being recognizable.
I’ve now installed Ocropus http://code.google.com/p/ocropus/ as a test. Unfortunately this is not giving me the correct numbers every time. This leads me to think that my pictures are not optimized enough.
Does anyone have some tips/ideas how to optimize the readability of the numbers? I would also be grateful for ideas how to find the numbers from the picture.
It seems that Tesseract / Ocropus are getting confused with the skew an it could be that multiple skewed numbers on the same line is confusing the Tesseract or Ocropus.
Are you passing in the whole image as a grid of numbers ? Have you tried sending each box (number) individually as a separate image to the OCR engine ? You may find you get better results.
Have you tried any other OCR engines ? Do you require it to be open source ?
I ran the image through a cheaper commercial OCR engine and all numbers recognised correctly. So another option is to wrap up a commercial OCR engine quite quickly with C# or C++ code and interface to deliver improved results.
Is it acceptable to use an external (web-based) API for your solution?
If so, please consider http://www.wisetrend.com/wisetrend_ocr_cloud.shtml (a REST API for OCR)
It can automatically correct for image rotation; Try tweaking the Deskew and AnalysisMode parameters described in http://www.wisetrend.com/WiseTREND_Online_OCR_API_v2.0.htm
(Also, when using the API, make sure that the image resolution is correctly set in the input image header - it can make all the difference in recognition quality).

Programatically extract pattern from image file and / or PSD

I often have to extract a pattern from a PSD to make an image to be used with XHTML and CSS.
I have often just made a guess in Photoshop, and then had to correct my guesses a few time after. It seems cumbersome.
Is there...
Techniques for extracting a pattern from a Photoshop file with the selector tool?
A Photoshop plugin perhaps that can do this
Software that can parse a pattern image, and give me back the bare minimum to make a tiled pattern?
Should I just be requesting a copy of the pattern in addition to each PSD I receieve?
How have other people in my position tackled this problem before?
In matter of interest, how could / would I program something like this (I could use PHP with GD library)? Is it not worth my time? Would I loop through pixels left to right, and then identify image colours, and positions away from each other, and constantly check if new pixels are beginning to match an older pattern?
I'm currently working on a software that does this (and a couple more things to automate slicing of PSDs), but it's very slow even in C++. Right now i'm looking into GPU accelerated solution...
So if there's an option for requesting pattern you should just do that.

Categories