Jump to content

Archived

This topic is now archived and is closed to further replies.

Traian

PHP shape/ pattern recognition inside image

Recommended Posts

Hi!


I would like to get some tips/ snippets about recognising a desired shape/ pattern inside a picture with the help of PHP.


I want to crop fixed areas (using percentages) of an image containing an identity card but, in order to do this, first I have to detect the boundaries of the identity card and crop the image so that there will be nothing left in it except the card. The identity card contained in the picture will not be rotated (not more than a few degrees) and the background may vary.


My final goal is to use the cropped areas with an OCR. I thought that this method will be good for removing the unwanted parts and also helping out the OCR. If you have a better idea, tell me.


Thank you!


Share this post


Link to post
Share on other sites

PHP really wouldn't be best for this. Its just not designed for this kind of task and it would be very inefficient, slow and resource (cpu/ram) intensive.

 

That said, it would be helpful to see an example image as I have no idea on what you mean by "identity card" or what the rest of the background looks like. If these images are all fairly consistent, like a drivers license, there are php "edge detection" scripts that could help give you coordinates of the "contrasted" border, so you can crop from those. It does it by creating several copies of the image, like in greyscale, and contrast the dark/light areas. There is very little useful info I could find in google.

Share this post


Link to post
Share on other sites

Your better off using Python as it has a variety of useful libraries such as nupmpy and scikit. You'll want to apply a kernel to the image such as a 3x3 kernel with -1 along the top row and 1 along the bottom. This will highlight horizontal edges and rotating the kernel 90 degrees will yield vertical edges. Combining the two will yield edge detection. The topic gets increasingly complex and to be totally honest, is probably unnecessary for your purpose. 

 

If you're always scanning cards of the same size, why not predefine the area and cut that area out? 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.