Jump to content

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!


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.

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? 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.