Can I use approxPolyDP
to improve the people detection?
I am trying to detect people using BackgroundSubtractorMOG2
. So after I receive the foreground of the image I obtain all the contours of the image using this function:
Imgproc.findContours(contourImg, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);
I iterate each element of contours variable and if the contour has a specified contour area
=> it's a person
My question is if I can detect the people shapes better ussing approxPolyDP
.
Is it possible? If so can you tell me how?
I already used CLOSE
morphological
operation before finding counturs
My question is if I can detect the people shapes better ussing
approxPolyDP
.
Although "better" is somewhat ambiguous, you could improve your classification by using that method. From the docs we can see:
The functions
approxPolyDP
approximate a curve or a polygon with another curve/polygon with less vertices so that the distance between them is less or equal to the specified precision.
That "precision" refers to the epsilon
parameter, which stands for the "maximum distance between the original curve and its approximation" (also from the docs). It is basically an accuracy parameter obtained from the arc length (the lower the more precise the contour will be).
We can see from this tutorial that a way to achieve this is:
epsilon = 0.1*cv2.arcLength(contour,True)
approx = cv2.approxPolyDP(contour,epsilon,True)
resulting in a better approximation for the contour. In the example in that tutorial they achieve an optimal contour using 1% of arc length, although you should carefully select this percentage for your specific situation.
By using these procedures you will surely obtain higher precision on your contour areas, which will better enable you to correctly classify people from other objects that have similar areas. You will also have to modify your classification criterion (the >= some_area) accordingly to correctly discriminate between people and non-people objects now that you have a more precise area.