top astronomy and space articles

[astronomy][bleft]

interesting blogs

[interesting][bleft]

How to Detect The Edges of the Object In 8 Minutes | Object Tracking First Basic Concepts and Code

Edges detected of different type of balls
Detected Edges of different type of balls!



Object Tracking is one of the coolest projects that you can work on. But before you do Object Tracking, you should know how you can Detect the Edges of Object in a picture or in live webcam feed. This video explains how you can achieve that.

This project is made in C++ so it is assumed that you have an IDE installed for C++ coding and OpenCV installed in your computer.

We have this input image to work with an objective to find the edges of all the balls regardless of their color and shape. By edges, it means we need to find the Closed Curves/Area. As this is an image, it can have a lot of noise. Therefore, before detecting the edges you must have to reduce or eliminate the noise. If you don't, many small unwanted closed curves might also get detected.
Image of Balls used as Input
Input Image


To reduce this noise we have two methods to work with. First method is to blur the image, this is also known as smoothing the image.

In this project, we are using Gaussian blur method.

It is an easy method to apply as you will have to write just a single line of code but it can create a problem when there is too much noise in the picture as you will need to do too much blurring and it can cause the aimed object also to get blurry. Second method is called Morphological transformation and this is perhaps the best noise reduction method in OpenCV. We will use this method in the upcoming projects and will discuss why do we normally give importance to Morphological transformation over blur method.

Blur Documentation: http://bit.ly/2qfBfEh
Morphological Documentation: http://bit.ly/2gmZU7C

After you have successfully removed the noise from the picture, it's time to work on detecting the edges. OpenCV provides another method that can do this job: Canny! This method will return the detected edges as a Mat object. Because Canny applies Binary threshold, therefore, the edge pixels are 1's and all other pixels are 0's.

Canny Documentation: http://bit.ly/1Yv9LXR

The only thing left now is to mask the original image Mat object over the canny Mat object using copyTo() method. This will only mask the pixels from the original image on the destination image which are 1's in the canny image. All other pixels in original image will not be masked as they are 0's in the canny image. You can now show the destination image on the window.

Detected Edges of all the Balls as output image
Detected Edges of all the Balls

Download the complete project folder with OpenCV property sheets: http://bit.ly/2wPRi0d
Zain Ul Mustafa

Cakes, conspiracies, and computers are my daily pills.

Post A Comment
  • Blogger Comment using Blogger
  • Facebook Comment using Facebook
  • Disqus Comment using Disqus

No comments :