- Finding Contours ->
cv2.findContoursto locate object boundaries - Shape Detection -> Approximate shapes using
approxPolyDPfor object recognition - Drawing Contours -> Highlight detected objects by drawing around their edges.
Contour -> is the curve holding all the continuous points having same color or intensity of edges.
[!note] Use only binary images
mode:
In here we need to tell two things about contours;
- How many contours?
- What kind of contours ?
Then these are the two most frequently used mode of retrieval;
- Retrieval mode tree (RETR_TREE) : hierarchical shapes (shaped inside shapes)
- Retrieval mode external (RETR_EXTERNAL) : Only outermost shapes
- Retrieval list (RETR_LIST) : all contours without hierachy
many more are there also.
method :
Approximation method used which tells us how much detailed to be returned. (CHAIN_APPROX_SIMPLE) -> only stores info regarding corner points (CHAIN_APPROX_NONE) -> every pixel
contours: list of continuous points will be returned , or list of all detected outlines.
hierarchy : will return the contour level information , parent -> child etc.
Till this we are able to find contours now to display we need to move onto the next function.
It basically draws over contours to show them clearly and easily using color and thickness.
contour_index tells OpenCV which contour to be shown;
- 0 -> only first shape
- 1 -> second shape
- -1 -> all shapes
Shape detection i.e. now OpenCV will automatically detect the shape during contours with the help of approxPolyDP() by counting their corners.
approxPolyDP() -> function for approving polygonal curve in shape detection
Some functionalities:
- Shape Approximation -> reduces vertices while preserving objects overall shape
- Object Recognition -> facilitates identification of geometric shapes in images
- Classification -> enable categorization of objects based on shape analysis
- Accuracy Enhancement -> improves precision of shape detection algorithm
- Performance Improvement -> enhance efficiency of shape detection process.
epsilon = 0.01 * cv2.arclength(contour , True) it tells that how much similarity to have to get same as original one.
if smaller -> more precise , more points else rough , fewer points.