-1

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

Rares
  • 597
  • 1
  • 5
  • 21
  • Why don't you try it? And see if you get better results? – DarkCygnus Jul 04 '17 at 18:14
  • I don't know how to implement it. I never used it. Can you help? Java code would be great. – Rares Jul 04 '17 at 18:15
  • Why do you suspect `approxPolyDP` will help you? In general the [docs](http://docs.opencv.org/3.1.0/dd/d49/tutorial_py_contour_features.html) indicate that when using that method you will get a contour that fits better to the object (that is without many surrounding area). Therefore, you will be getting less area on your contours so you may have to edit your `>=` criteria – DarkCygnus Jul 04 '17 at 18:20
  • Ok. Thanks for clearing that out. I have one more question, maybe you can answer it here. It's about BackgroundSubtractorMOG2. Can you tell me how should I set the history value? I saw someone doing: mog2.apply(input, output, 1/history); – Rares Jul 04 '17 at 18:25
  • You should ask a new question or research on that, as it is a different subject and is not ok (and also not useful for users) to answer questions on comments. Anyways, if you want, I could write an answer for *this* question based on my comment and elaborate more if it helps you. – DarkCygnus Jul 04 '17 at 18:28
  • Ok answer for this question maybe in the future someone will need the help. Thanks! – Rares Jul 04 '17 at 18:30
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/148346/discussion-between-rares-and-graycygnus). – Rares Jul 04 '17 at 18:38

1 Answers1

1

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.

DarkCygnus
  • 7,420
  • 4
  • 36
  • 59