From the course: OpenCV for Python Developers

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Contour object detection

Contour object detection

- [Instructor] Now that we have an understanding of how contours work, let's see how to use them with Python 3 and OpenCV 4. Contours only work with binary images. So let's first convert our loaded image here into gray scale and then perform a quick threshold. We can do this by typing our variable gray equals CV2 dot cvt capital C for color, and then we'll pass in our img, and then we'll specify the kind of conversion we're doing, which is CV2 dot in all caps COLOR underscore RGB the number 2, and then G-R-A-Y for gray, close parentheses. Next, let's perform our threshold. For this, we will type thresh as our output variable and then equals CV2 dot adaptive threshold. And then we're going to pass in our gray image here followed by 255, specifying that's the maximum value for this kind of image and then the kind of thresholding we're going to perform, which is CV2 dot in all caps ADAPTIVE underscore thresh underscore Gaussian,…

Contents