First of all, sorry for taking so long for this post, I´ve been really busy with work and couldn´t find the time to write this.
Let´s start! This fifth part of the tutorial will cover basic transformations.
Esentially, we will use erosion and dialtion on binarized images (black and white). In a very general manner, erosion expands a black portion of the image into a white portion. Dilation, on the other hand, expands a white portion of the image into a black portion.
To do this operations you also need to specify a kernel or structuring element (strel). This is a matrix that is convoluted on the image of size n*n that defines the area to use when calculating the value of each pixel.
Let try them on this image:
Use this code:
We´re useing the threshold method to binarize the image. Convert it from color to only black and white, two values (not the same as grayscale). Look at how it works here.
Run it and look at the output images. Also, try changing the kernel´s size (5,5 or 9,9, for example) and see what happens.
You can also combine both operations, running one after the other.
Doing and erosion and then a dilation is called opening.
On the other hand, doing a dilation and then an erosion is called closing.
Let´s try them on this image:
Use the following code:
Look at the output and try to understand what happened during closing and opening.
Now try incorporating this code to our people counter, right after background substraction, to take the shadows (gray color) out and make the video stream clear (take out any noise), to take it from this:
It´s right to even try combining opening and closing operations, even with different sizes of kernel. Experiment with them!
You can also use this operations on color images to get cool results, although that´s not useful for the counter.
(Click on the images to view them full size)
|Original||Opening (9,9)||Closing (9,9)|
That´s it for now. If you have any questions leave them in the comments.
Next, we´ll look at finding contours from the clean clean image to later detect them as moving people.