opencvimutils

How to use the contours related functions in the imutils library


Regarding the imutils library related to OpenCV, I have the following questions:

  1. What is the function of contours.sort_contours()?

  2. (cnts, _) = contours.sort_contours(cnts) In the above statement, what is the meaning of (cnts, _), especially '_'

Note: cnts is a variable containing the contours of the recognized image My English is not very good, sorry! Thank you all for your answers and help!


Solution

  • The imutils library is a convenience library written to make basic image processing tasks easier (https://github.com/PyImageSearch/imutils).

    One such task is sorting and labelling contours in images. Based on documentation provided here, there is a separate contours.py file hosting sort_contours() and label_contour functions. (You need to remember that these functions can be used only after finding contours using OpenCV)

    Now to answer your questions:

    1. What is the function of contours.sort_contours() ?

    2. Understanding (cnts, _) = contours.sort_contours(cnts)