Object Shape Detection

Can you detect shapes of an object from image?

What is object shape detection?

In our life we tend to come upon many objects of many shapes and with the assistance of our sense we are able to simply classify and distinguish among them except for a laptop, that doesn’t have any sense, we’d like to coach or program it for such a classification or detection of various object.

For example:

figure 1

From our establishment we are able to simply say that the thing in fig.1 may be a circle or a sphere. however what about laptop, however can it identify this object. we've got to supply it with a synthetic intuition to try to to thus. consequent chapter provides with one among the approach to coach a machine like laptop to acknowledge objects.

Objective

Our main goal of the project is to form such a software system which can detect any object from image and identify a shape of that object. The system should recognize objects like circle, rectangles, squares, pentagon and triangular from the input image.

Tools and Technology

Tools needed

  • Operating System: Windows

  • IDE: Jupyter or PyCharm

  • Languages: Python3

Libraries

  • OpenCV

  • Numpy

  • Matplotlib

  • Imageio

  • SciPy

Algorithms and Flowchart

Canny Edge Detection Algorithm

  1. History of canny edge detection:

It had been developed by John F. canny in 1986. canny conjointly made a procedure theory of edge detection explaining why the technique works. The canny edge observer is an edge detection operator that uses a multi-stage algorithm to detect a good vary of edges in pictures.


  1. Algorithm:

Canny edge detection algorithm runs primarily in four consecutive stages..

Stage no. 1, Smoothing: pictures taken from camera can contain some quantity of noise. As noise will mislead the lead to finding edges, we've got to scale back the noise. thus the pictures is that the initial smoothed by applying a Gaussian filter.

Stage no. 2, Finding gradients: Here we are going to notice the sting strength by taking the gradient of the image. The Sobel operator performs a 2-D abstraction gradient measuring on an image. The Sobel operator uses a combine of 3x3 convolution masks, one estimating the gradient within the x-direction and also the different estimating the gradient within the ydirection.

Stage no. 3, Non-maximum suppression: this can be necessary to convert the blurred edges in the image of the gradient magnitudes to sharp edges. truly this can be performed by considering solely all native maxima within the gradient image and deleting everything rest. The formula is applied for every element within the gradient image. Finally, solely native maxima are marked as edges.

Stage no. 4, hysteresis thresholding: The received image should still contain false edge points. mistreatment threshold, Potential edges are determined by doble thresholding(High and low).


  1. Flow Chart:


Flow Of System

This is the flow chart of the system. In this system the user first has to give the input image. After that we apply canny edge detection algorithm to find a edges of given image. Then after we discover a contour of that image using findcountour function. From number of contours of any object that is in image we determine shape of that image. Then we border that object and write that shape name on that object in given image. And at the end we display that resultant image.

How does it work?

  1. Load Image

First we load the image from the given path

in program.

2. Gray Scale Image

After loading image from folder we convert it to gray scale to help extraction of edges and plot it.


3. Blur Image

Blur the gray scale image in order that solely necessary edges are extracted and therefore the noisy ones neglected.

4.Apply Sobel Filter

Sobel X-direction
Sobel Y-direction

Sobel Operator is attempting to search out the amount of the distinction by putting the gradient matrix over every pixel of our image. we have a tendency to get 2 pictures as output, one for X-Direction and alternative for Y-Direction.

5. Calculate the magnitude

Calculate the magnitude of the gradients obtained.

6.Calculate direction of the gradients

Calculate direction of the gradients that we obtained using the inbuilt sober function.

7. Do Non Maximum suppression

Perform Non maximum Suppression with interpolation to induce a higher estimate of the magnitude values of the pixels within the gradient direction. this is often done to urge to induce edges.

8. Double Threshold Hysterisis

In this we have a tendency to classified every component in 2 half robust component and week component. pixel is classified as a strong edge pixel, if its gradient magnitude is larger than higher threshold. A pixel is labelled as weak edge, if the worth of gradient magnitude of the pixel is in between the lower and higher threshold. strong edges are those which may be enclosed instantly as edges within the final edge image. Weak edges may be marked as long as they're joined to the strong edges.

9. Canny edge detection Output

This is the output of the canny edge detection algorithm.

10. Find contours

In this we find contours from canny edge detected image. We find contour of the image to identify the shape of the object in given image.

11. Find shape based on contour

We find the shape of object based on the contours that we find in above step. we tend to approximate a contour shape to a different shape with less number of vertices relying upon the precision we tend to specify. this can be done through the approxPolyDP function. Example, If result length of approxpolyDp function is three we are able to say that this can be a triangle. then we draw border on the detected image and write the shape name of that object.


Applications

Computer vision continues to be a developing discipline, it's not been matured to it level wherever it can be applied on to real world issues. For now, i can consider object recolonization as a sub branch of machine learning. Some common and wide used.

Application of object detection are:

• Face Detection have you ever ever questioned how Facebook detects your face after you upload photo? Not solely it detects, it remembers the face too. this can be a straightforward application of object detection that we tend to see in our lifestyle.

• Counting objects/peoples Object detection will be conjointly used for count purpose, it's used for keeping a count of specific or all objects in an current frame or a frame. For e.g. from group photograph it will count the number of persons and if enforced neatly you may conjointly ascertain totally different individuals with different dresses.

• Vehicle detection similarly, when the object may be a vehicle, object detection on with tracking will be used for locating the type of car, this application is also extended to even build a traffic calculator.

• Security Identification of unwanted or suspicious objects in any specific space or additional specifically object detection techniques are used for detection bombs/explosives. it's conjointly even used for private security purpose.

• Bio-metric recognition uses physical or activity traits of humans to acknowledge any people for security and authentication purpose. It uses distinct biological traits like retina, fingerprints, iris patterns, hand geometry, and etc.

• Surveillance Objects will be recognized and tracked in videos for security purpose. object recognition is needed so the suspected person or vehicle will be tracked . Medical analysis Object notation is employed to detect diseases sort of a tumor, stones, cancer in magnetic resonance imaging current frames.

• Optical character recognition Characters in scanned documents will be recognized victimisation object recognition.

Limitation

• It takes 3D object as 2d object therefore it will generate only number of shape.

• Accuracy of this module isn't good when we try to find shape of multiple objects.

• Canny edge detector consumes lot of your time because of its complicated computation.

• It’s tough to achieve the real-time response.

Conclusion

The potentialities of using computer vision to resolve world issues are immense. the fundamental of object detection in conjunction with various ways of achieving it and scope has been mentioned. and how we can determine shape of any object is learn using various ways. canny edge detection algorithm provides correct edge of any object. using that edges we will accurately realize form of any objects. Python has been most popular over matlab for integration with OpenCV as a result of when a matlab program is run on a pc, it gets busy attempting to interpret all that matlab code as matlab code is made on java. OpenCV is essentially library of function written in C\C++. in addition, OpenCV is simpler to use for somebody with very little programming background. So, it's better to begin researching on any concept of object detection using OpneCV-Python.

Project Documentation