Extreme Points on Contour

After getting the contour from the image of the person, the second step  would be getting the highest and lowest points on the contour, using the area of the contour, then getting the maximum and minimum points as tuples from the area that we have, that was the approach that we used to get the extreme points that are later on used to get the exact height of the person in pixels [1]:

c = max(contours, key=cv2.contourArea)
extTop = tuple(c[c[:, :, 1].argmin()][0])
extBot = tuple(c[c[:, :, 1].argmax()][0])

The code above will give us the coordinates of the extreme top and extreme bottom pixels. To show the extreme points on the picture I added a code to draw a circle on the points:

extTop = tuple(c[c[:, :, 1].argmin()][0])
cv2.circle(img = img, center = extTop, radius = 5, color = (255,0,0), thickness = -1)
extBot = tuple(c[c[:, :, 1].argmax()][0])
cv2.circle(img = img, center = extBot, radius = 5, color = (0,255,0), thickness = -1)

The result of modifying the previous code will be that a blue circle will be drawn at the extreme top value of the contour, and a green circle will be drawn at the extreme bottom value, as shown below:

resultsV4.JPG

Reference:
[1]A. Rosebrock, “Finding extreme points in contours with OpenCV – PyImageSearch”, PyImageSearch, 2018. [Online]. Available: https://www.pyimagesearch.com/2016/04/11/finding-extreme-points-in-contours-with-opencv/. [Accessed: 25- Nov- 2018].

Leave a comment