Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect simple geometric shapes using PILLOW(PIL)

Tags:

python

pillow

I have this project were I need Python to detect simple geometric shapes inside an image. Only using Pillow, for example:

enter image description here

After searching the internet, I still don't know how to achieve this. Thanks in advance for any help

like image 905
Hernando Salas Avatar asked Jun 05 '15 19:06

Hernando Salas


People also ask

How to detect shapes using OpenCV?

Use the findContours() and approxPolyDP() Functions of OpenCV to Detect Shapes Present in an Image. We can find shapes present in an image using the findContours() and approxPolyDP() function of OpenCV. We can detect shapes depending on the number of corners it has.

Can you draw pictures with Python?

Pillow provides a drawing module called ImageDraw that you can use to create simple 2D graphics on your Image objects.


1 Answers

Get edges first.

Magnitude = sqrt(dx2+dy2)

Threshold and convert to 0,1 magnitude image. Follow lines and look for corners, following perimeters of shapes.

Or write more complex corner detection algorithms as found in OpenCV.

Shape is based in number of corners found. (Looks like GTKbai!)

like image 155
Mark A Mueller Avatar answered Sep 18 '22 13:09

Mark A Mueller