Block 117: Contours & Object Detection
Find and draw contours for shape analysis.
Concepts
- cv2.findContours() on binary image
- cv2.drawContours()
- Contour properties: area, perimeter, bounding box
- cv2.contourArea(), cv2.arcLength(), cv2.boundingRect()
Code Examples
See exercise below.
Exercise
Find all contours in a binary image. Draw the 3 largest ones. Draw bounding boxes around all detected contours with area > 500.
Homework
What preprocessing steps (threshold, blur, morph) give the best contour detection results? Experiment.