What dilation kernel should be used to "fill" object in image?

178 views Asked by At

I have some python code which uses cv2 to perform motion detection and tracking. However it often detects one object as two or more separate objects. I think this might be due to kernel size. Increasing iterations only makes the white bits larger, instead of filling in the object properly. The line in question is:

thresh = cv2.dilate(thresh, None, iterations=2)

Where None is, I can input the kernel size. I've attached two pictures, one is the result of a kernel size of 3x3:

enter image description here

the other 5x5:

enter image description here

As you can see, neither are successful, and the result is 3 or 4 small boxes drawn over the animal rather than one large one with the correct outline eg:

enter image description here

How can I determine correct kernel size? Does image resolution matter? I have been doing reading on morphology and just don't really understand it.

Any help appreciated.

0

There are 0 answers