{% extends "base.html" %} {% block title %} findContours {% endblock %} {% block description %}
Finds contours in a binary image.
{% endblock %} {% block signature %}cv2.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) → contours, hierarchy{% endblock %} {% block parameters %}
cv2.RETR_*
): Contour retrieval mode. Choose from:
hierarchy[i][2]=hierarchy[i][3]=-1
for all the contours.cv2.CHAIN_APPROX_*
): Contour approximation method. Choose from:
max(abs(x1-x2),abs(y2-y1))==1
.contours[i]
, the elements hierarchy[i][0]
, hierarchy[i][1]
, hierarchy[i][2]
, and hierarchy[i][3]
are set to 0-based indices in contours of the next and previous contours at the same hierarchical level, the first child contour and the parent contour, respectively. If for the contour i there are no next, previous, parent, or nested contours, the corresponding elements of hierarchy[i]
will be negative.cv2.POINT
): Optional offset by which every contour point is shifted. This is useful if the contours are extracted from the image ROI and then they should be analyzed in the whole image context.The function retrieves contours from the binary image using the algorithm [224]. The contours are a useful tool for shape analysis and object detection and recognition.
{% endblock %} {% block notes %}compare
, inRange
, threshold
, adaptiveThreshold
, Canny
, and others to create a binary image out of a grayscale or color one. In this app, we simply set all pixels above threshold to 255 and all pixels below threshold to 0.