GithubHelp home page GithubHelp logo

pete1313 / object-detection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from abdelrahmanradwan/object-detection

0.0 1.0 0.0 128.36 MB

A tool used for recognizing and counting the number of occurrences of four different shapes (i.e. square, rectangle, circle, triangle) in a given image.

License: MIT License

Python 100.00%

object-detection's Introduction

Shape Recognition

Example 1

Example 2

Example 3

Example 4

Example 5

A tool used for recognizing and counting the number of occurrences of four different shapes (i.e. square, rectangle, circle, triangle) in a given image. [Easily scalable in terms of new shapes]

The tool takes an image path as input and returns three comma separated integers as output:

<int>,<int>,<int>

Where the first integer corresponds to the number of squares in the image, the second integer corresponds to the number of circles, and the third integer corresponds to the number of triangles.

๐Ÿ’ซ Version 0.1 out now!

๐Ÿ“– Documentation

How to Run

Install the requirements:

pip3 install -r requirements.txt 

To run the main tool:

python3 shapes_counter.py -i <image_path>
example:
python3 shapes_counter.py -i training_data/001979900122A9-0017558-00101E4-001F3DE-00118C8001FC1B0016C37.jpg

and you can also run the visualization tool with any image to see the visual edits and effects happened in the picture:

python3 evaluation/visualization.py  -i <image_path>

example:

python3 evaluation/visualization.py  -i training_data/00170820010925-001146F-0011FF9-001E987-0019C5D001A322001AEF8.jpg

Algorithm

I'm using simple image processing techniques using OpenCV-Python, the algorithm steps:

  1. Do image pre-processing and reduce the noise.
  2. Select the contours from the image.
  3. Select the core approximate corners from each contour.
  4. Determine the shape of the main contour; based on its number of vertices.
  5. Draw the picture with its shapes tagged by their types.
  6. Count the shapes occupancies and print the numbers, comma separated.

I tried to use a training dataset of a lot of labeled pictures, but I had two issues:

  1. The labeling technique seems to be not so useful for me; as if I know exactly the shapes in the picture but I don't know their places, then I can not use this info.
  2. I didn't find a lot of free papers discussing 2D geometric shapes recognition using machine learning and advanced models, most of them are using contours detection and edge detection.

Results

The results are not bad at all! a lot of test cases gonna be true, the algorithm can pass a lot of corner cases.

Example 1 Example 2
Example 1 Example 2
Example 3 Example 4
Example 3 Example 4
Example 5 Example 5
Example 5 Example 6
Example 7 Example 8
Example 7 Example 8

Comparison

Original Image Resultant Image
Example 1-1 Example 1-2
Example 2-1 Example 2-2
Example 3-1 Example 3-2
Example 4-1 Example 4-2

On the other hand, the algorithm fails in some cases:

  1. With small shapes (very small).
  2. With the unionized shapes.
  3. With objects on the image borders.

I run with more than one experiment before reaching this accuracy:

Further work

  1. As a post-processing step, we need to sharpen the shapes after the pre-processing phase, to avoid minimizing the shape which leads to unrecognizable shape with hard to detect edges.
  2. As a post-processing step, we need to separate the shapes from each other and from the borders if they are hardly connected together.
  3. Try using Lattice-Computing (LC) Techniques to enhance the results.
  4. Try Neural Network to detect 2D shapes in images using a GANN approach, This combines the heuristic approach of a Genetic Algorithm, and the precision of gradient descent, to reach optimum convergence.
  5. Use PIL for preprocessing.

object-detection's People

Contributors

abdelrahmanradwan avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.