Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php shape recognition in images

Tags:

php

I want to detect a certain shape in an photo using PHP. Take a look at the following photo of my girlfriend.

My girlfriend

This photo has a few black corners in it. I would like to detect those corners and cut out whats in side of it. (Like in the example image above).

I'd like to do this in PHP without the use of any 3rd party library.

Any idea how to do this and what algorithms i can use to detect (basic?) shapes like that?

like image 709
w00 Avatar asked Oct 29 '11 19:10

w00


1 Answers

It would be easy though it may require intensive computing on server side.

  1. Its pattern recognition and very basic pattern.
  2. Also we have four different shapes to detect.
  3. Considering the solid and predefined color.
  4. Considering the shapes will have constant dimensions.

It can be achieved by

  1. Reading all pixels one by one from top-left to bottom right corner of image.
  2. Constructing the first (top-left) and second (top-right) shape by comparing encountered pixels of predefined color with the predefined dimensions of shapes respectively.
  3. Same steps for 3rd and fourth shapes.
  4. Now if all four or any three or any two (top-left and bottom-right) or ( top-right and bottom-left ) shapes are detected, we can crop the required image.

My answer my look vague but the only real answer to is code.

like image 195
Imran Naqvi Avatar answered Oct 20 '22 19:10

Imran Naqvi