You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: source/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.rst
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,15 +8,15 @@ Goal
8
8
9
9
* Understand what contours are.
10
10
* Learn to find contours, draw contours etc
11
-
* You will see these functions : :ocv:pyfunction:`findContours`, :ocv:pyfunction:`drawContours`
11
+
* You will see these functions : **cv2.findContours()**, **cv2.drawContours()**
12
12
13
13
What are contours?
14
14
===================
15
15
16
16
Contours can be explained simply as a curve joining all the continuous points (along the boundary), having same color or intensity. The contours are a useful tool for shape analysis and object detection and recognition.
17
17
18
18
* For better accuracy, use binary images. So before finding contours, apply threshold or canny edge detection.
19
-
* findContours function modifies the source image. So if you want source iamge even after finding contours, already store it to some other location.
19
+
* findContours function modifies the source image. So if you want source image even after finding contours, already store it to some other variables.
20
20
* In OpenCV, finding contours is like finding white object from black background. So remember, object to be found should be white and background should be black.
21
21
22
22
Let's see how to find contours of a binary image:
@@ -30,7 +30,7 @@ Let's see how to find contours of a binary image:
See, there are three arguments in :ocv:pyfunction:`findContours` function, first one is source image, second is contour retrieval mode, third is contour approximation method. And it outputs the image, contours and hierarchy. ``contours`` is a Python list of all the contours in the image. Each individual contour is a Numpy array of (x,y) coordinates of boundary points of the object.
33
+
See, there are three arguments in **cv2.findContours()** function, first one is source image, second is contour retrieval mode, third is contour approximation method. And it outputs the image, contours and hierarchy. ``contours`` is a Python list of all the contours in the image. Each individual contour is a Numpy array of (x,y) coordinates of boundary points of the object.
34
34
35
35
.. note:: We will discuss second and third arguments and about hierarchy in details later. Until then, the values given to them in code sample will work fine for all images.
36
36
@@ -43,20 +43,20 @@ To draw the contours, ``cv2.drawContours`` function is used. It can also be used
.. note:: Last two methods are same, but when you go forward, you will see last one is more useful
59
+
.. note:: Last two methods are same, but when you go forward, you will see last one is more useful.
60
60
61
61
Contour Approximation Method
62
62
================================
@@ -65,9 +65,9 @@ This is the third argument in ``cv2.findContours`` function. What does it denote
65
65
66
66
Above, we told that contours are the boundaries of a shape with same intensity. It stores the (x,y) coordinates of the boundary of a shape. But does it store all the coordinates ? That is specified by this contour approximation method.
67
67
68
-
If you pass ``cv2.CHAIN_APPROX_NONE``, all the boundary points are stored. But actually do we need all the points? For eg, you found the contour of a straight line. Do you need all the points on the line to represent that line? No, we need just two end points of that line. This is what ``cv2.CHAIN_APPROX_SIMPLE`` does. It removes all redundant points and compresses the contour thereby saving memory.
68
+
If you pass ``cv2.CHAIN_APPROX_NONE``, all the boundary points are stored. But actually do we need all the points? For eg, you found the contour of a straight line. Do you need all the points on the line to represent that line? No, we need just two end points of that line. This is what ``cv2.CHAIN_APPROX_SIMPLE`` does. It removes all redundant points and compresses the contour, thereby saving memory.
69
69
70
-
Below image of a rectangle demonstrate this technique. Just draw a circle on all the coordinates in the contour array (drawn in blue color). First image shows points I got with ``cv2.CHAIN_APPROX_NONE`` (734 points) and second image shows the one with ``cv2.CHAIN_APPROX_SIMPLE`` (only 4 points). See, how much memory it saves.
70
+
Below image of a rectangle demonstrate this technique. Just draw a circle on all the coordinates in the contour array (drawn in blue color). First image shows points I got with ``cv2.CHAIN_APPROX_NONE`` (734 points) and second image shows the one with ``cv2.CHAIN_APPROX_SIMPLE`` (only 4 points). See, how much memory it saves!!!
0 commit comments