Skip to content

Commit c3e3594

Browse files
committed
review cont begin
1 parent cb84fae commit c3e3594

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed
-925 Bytes
Loading

source/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ Goal
88

99
* Understand what contours are.
1010
* 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()**
1212

1313
What are contours?
1414
===================
1515

1616
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.
1717

1818
* 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.
2020
* 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.
2121

2222
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:
3030
ret,thresh = cv2.threshold(imgray,127,255,0)
3131
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
3232

33-
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.
3434

3535
.. 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.
3636

@@ -43,20 +43,20 @@ To draw the contours, ``cv2.drawContours`` function is used. It can also be used
4343
To draw all the contours in an image:
4444
::
4545

46-
cv2.drawContour(img, contours, -1, (0,255,0), 3)
46+
img = cv2.drawContour(img, contours, -1, (0,255,0), 3)
4747
4848
To draw an individual contour, say 4th contour:
4949
::
5050
51-
cv2.drawContours(img, contours, 3, (0,255,0), 3)
51+
img = cv2.drawContours(img, contours, 3, (0,255,0), 3)
5252

5353
But most of the time, below method will be useful:
5454
::
5555

5656
cnt = contours[4]
57-
cv2.drawContours(img, [cnt], 0, (0,255,0), 3)
57+
img = cv2.drawContours(img, [cnt], 0, (0,255,0), 3)
5858
59-
.. 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.
6060

6161
Contour Approximation Method
6262
================================
@@ -65,9 +65,9 @@ This is the third argument in ``cv2.findContours`` function. What does it denote
6565

6666
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.
6767

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.
6969

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!!!
7171

7272
.. image:: images/none.jpg
7373
:alt: Contour Retrieval Method

0 commit comments

Comments
 (0)