Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
8eb987e3
Commit
8eb987e3
authored
Sep 27, 2018
by
Suleyman TURKMEN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update findContours parameter type
parent
29e88e50
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
25 additions
and
25 deletions
+25
-25
py_contour_features.markdown
...contours/py_contour_features/py_contour_features.markdown
+1
-1
py_contours_begin.markdown
.../py_contours/py_contours_begin/py_contours_begin.markdown
+4
-4
py_contours_more_functions.markdown
...ntours_more_functions/py_contours_more_functions.markdown
+3
-3
imgproc.hpp
modules/imgproc/include/opencv2/imgproc.hpp
+2
-2
contours.cpp
modules/imgproc/src/contours.cpp
+2
-2
test_shape.py
modules/python/test/test_shape.py
+2
-2
test_squares.py
modules/python/test/test_squares.py
+1
-1
contours.py
samples/python/contours.py
+1
-1
digits_video.py
samples/python/digits_video.py
+1
-1
imageSegmentation.py
...ode/ImgTrans/distance_transformation/imageSegmentation.py
+1
-1
generalContours_demo1.py
...scriptors/bounding_rects_circles/generalContours_demo1.py
+1
-1
generalContours_demo2.py
...iptors/bounding_rotated_ellipses/generalContours_demo2.py
+1
-1
findContours_demo.py
..._code/ShapeDescriptors/find_contours/findContours_demo.py
+1
-1
hull_demo.py
...s/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py
+1
-1
moments_demo.py
...on/tutorial_code/ShapeDescriptors/moments/moments_demo.py
+1
-1
pointPolygonTest_demo.py
...peDescriptors/point_polygon_test/pointPolygonTest_demo.py
+1
-1
introduction_to_pca.py
...torial_code/ml/introduction_to_pca/introduction_to_pca.py
+1
-1
No files found.
doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown
View file @
8eb987e3
...
...
@@ -23,7 +23,7 @@ import cv2 as cv
img = cv.imread('star.jpg',0)
ret,thresh = cv.threshold(img,127,255,0)
im2,
contours,hierarchy = cv.findContours(thresh, 1, 2)
contours,hierarchy = cv.findContours(thresh, 1, 2)
cnt = contours
[
0
]
M = cv.moments(cnt)
...
...
doc/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.markdown
View file @
8eb987e3
...
...
@@ -17,7 +17,7 @@ detection and recognition.
-
For better accuracy, use binary images. So before finding contours, apply threshold or canny
edge detection.
-
Since OpenCV 3.2, findContours() no longer modifies the source image
but returns a modified image as the first of three return parameters
.
-
Since OpenCV 3.2, findContours() no longer modifies the source image.
-
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.
...
...
@@ -29,11 +29,11 @@ import cv2 as cv
im = cv.imread('test.jpg')
imgray = cv.cvtColor(im, cv.COLOR_BGR2GRAY)
ret, thresh = cv.threshold(imgray, 127, 255, 0)
im2,
contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
@endcode
See, there are three arguments in
**cv.findContours()**
function, first one is source image, second
is contour retrieval mode, third is contour approximation method. And it outputs
a modified image, the contours and
hierarchy. c
ontours is a Python list of all the contours in the image. Each individual contour is a
is contour retrieval mode, third is contour approximation method. And it outputs
the contours and hierarchy.
C
ontours 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.
@note We will discuss second and third arguments and about hierarchy in details later. Until then,
...
...
doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown
View file @
8eb987e3
...
...
@@ -39,7 +39,7 @@ import numpy as np
img = cv.imread('star.jpg')
img_gray = cv.cvtColor(img,cv.COLOR_BGR2GRAY)
ret,thresh = cv.threshold(img_gray, 127, 255,0)
im2,
contours,hierarchy = cv.findContours(thresh,2,1)
contours,hierarchy = cv.findContours(thresh,2,1)
cnt = contours
[
0
]
hull = cv.convexHull(cnt,returnPoints = False)
...
...
@@ -93,9 +93,9 @@ img2 = cv.imread('star2.jpg',0)
ret, thresh = cv.threshold(img1, 127, 255,0)
ret, thresh2 = cv.threshold(img2, 127, 255,0)
im2,
contours,hierarchy = cv.findContours(thresh,2,1)
contours,hierarchy = cv.findContours(thresh,2,1)
cnt1 = contours
[
0
]
im2,
contours,hierarchy = cv.findContours(thresh2,2,1)
contours,hierarchy = cv.findContours(thresh2,2,1)
cnt2 = contours
[
0
]
ret = cv.matchShapes(cnt1,cnt2,1,0.0)
...
...
modules/imgproc/include/opencv2/imgproc.hpp
View file @
8eb987e3
...
...
@@ -3885,12 +3885,12 @@ parent, or nested contours, the corresponding elements of hierarchy[i] will be n
contours are extracted from the image ROI and then they should be analyzed in the whole image
context.
*/
CV_EXPORTS_W
void
findContours
(
Input
Output
Array
image
,
OutputArrayOfArrays
contours
,
CV_EXPORTS_W
void
findContours
(
InputArray
image
,
OutputArrayOfArrays
contours
,
OutputArray
hierarchy
,
int
mode
,
int
method
,
Point
offset
=
Point
());
/** @overload */
CV_EXPORTS
void
findContours
(
Input
Output
Array
image
,
OutputArrayOfArrays
contours
,
CV_EXPORTS
void
findContours
(
InputArray
image
,
OutputArrayOfArrays
contours
,
int
mode
,
int
method
,
Point
offset
=
Point
());
/** @example samples/cpp/squares.cpp
...
...
modules/imgproc/src/contours.cpp
View file @
8eb987e3
...
...
@@ -1874,7 +1874,7 @@ cvFindContours( void* img, CvMemStorage* storage,
return
cvFindContours_Impl
(
img
,
storage
,
firstContour
,
cntHeaderSize
,
mode
,
method
,
offset
,
1
);
}
void
cv
::
findContours
(
Input
Output
Array
_image
,
OutputArrayOfArrays
_contours
,
void
cv
::
findContours
(
InputArray
_image
,
OutputArrayOfArrays
_contours
,
OutputArray
_hierarchy
,
int
mode
,
int
method
,
Point
offset
)
{
CV_INSTRUMENT_REGION
();
...
...
@@ -1939,7 +1939,7 @@ void cv::findContours( InputOutputArray _image, OutputArrayOfArrays _contours,
}
}
void
cv
::
findContours
(
Input
Output
Array
_image
,
OutputArrayOfArrays
_contours
,
void
cv
::
findContours
(
InputArray
_image
,
OutputArrayOfArrays
_contours
,
int
mode
,
int
method
,
Point
offset
)
{
CV_INSTRUMENT_REGION
();
...
...
modules/python/test/test_shape.py
View file @
8eb987e3
...
...
@@ -10,8 +10,8 @@ class shape_test(NewOpenCVTests):
a
=
self
.
get_sample
(
'samples/data/shape_sample/1.png'
,
cv
.
IMREAD_GRAYSCALE
)
b
=
self
.
get_sample
(
'samples/data/shape_sample/2.png'
,
cv
.
IMREAD_GRAYSCALE
)
_
,
ca
,
_
=
cv
.
findContours
(
a
,
cv
.
RETR_CCOMP
,
cv
.
CHAIN_APPROX_TC89_KCOS
)
_
,
cb
,
_
=
cv
.
findContours
(
b
,
cv
.
RETR_CCOMP
,
cv
.
CHAIN_APPROX_TC89_KCOS
)
ca
,
_
=
cv
.
findContours
(
a
,
cv
.
RETR_CCOMP
,
cv
.
CHAIN_APPROX_TC89_KCOS
)
cb
,
_
=
cv
.
findContours
(
b
,
cv
.
RETR_CCOMP
,
cv
.
CHAIN_APPROX_TC89_KCOS
)
hd
=
cv
.
createHausdorffDistanceExtractor
()
sd
=
cv
.
createShapeContextDistanceExtractor
()
...
...
modules/python/test/test_squares.py
View file @
8eb987e3
...
...
@@ -31,7 +31,7 @@ def find_squares(img):
bin
=
cv
.
dilate
(
bin
,
None
)
else
:
_retval
,
bin
=
cv
.
threshold
(
gray
,
thrs
,
255
,
cv
.
THRESH_BINARY
)
bin
,
contours
,
_hierarchy
=
cv
.
findContours
(
bin
,
cv
.
RETR_LIST
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
_hierarchy
=
cv
.
findContours
(
bin
,
cv
.
RETR_LIST
,
cv
.
CHAIN_APPROX_SIMPLE
)
for
cnt
in
contours
:
cnt_len
=
cv
.
arcLength
(
cnt
,
True
)
cnt
=
cv
.
approxPolyDP
(
cnt
,
0.02
*
cnt_len
,
True
)
...
...
samples/python/contours.py
View file @
8eb987e3
...
...
@@ -54,7 +54,7 @@ if __name__ == '__main__':
img
=
make_image
()
h
,
w
=
img
.
shape
[:
2
]
_
,
contours0
,
hierarchy
=
cv
.
findContours
(
img
.
copy
(),
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours0
,
hierarchy
=
cv
.
findContours
(
img
.
copy
(),
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
=
[
cv
.
approxPolyDP
(
cnt
,
3
,
True
)
for
cnt
in
contours0
]
def
update
(
levels
):
...
...
samples/python/digits_video.py
View file @
8eb987e3
...
...
@@ -41,7 +41,7 @@ def main():
bin
=
cv
.
adaptiveThreshold
(
gray
,
255
,
cv
.
ADAPTIVE_THRESH_MEAN_C
,
cv
.
THRESH_BINARY_INV
,
31
,
10
)
bin
=
cv
.
medianBlur
(
bin
,
3
)
_
,
contours
,
heirs
=
cv
.
findContours
(
bin
.
copy
(),
cv
.
RETR_CCOMP
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
heirs
=
cv
.
findContours
(
bin
.
copy
(),
cv
.
RETR_CCOMP
,
cv
.
CHAIN_APPROX_SIMPLE
)
try
:
heirs
=
heirs
[
0
]
except
:
...
...
samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py
View file @
8eb987e3
...
...
@@ -91,7 +91,7 @@ cv.imshow('Peaks', dist)
dist_8u
=
dist
.
astype
(
'uint8'
)
# Find total markers
_
,
contours
,
_
=
cv
.
findContours
(
dist_8u
,
cv
.
RETR_EXTERNAL
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
_
=
cv
.
findContours
(
dist_8u
,
cv
.
RETR_EXTERNAL
,
cv
.
CHAIN_APPROX_SIMPLE
)
# Create the marker image for the watershed algorithm
markers
=
np
.
zeros
(
dist
.
shape
,
dtype
=
np
.
int32
)
...
...
samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py
View file @
8eb987e3
...
...
@@ -16,7 +16,7 @@ def thresh_callback(val):
## [findContours]
# Find contours
_
,
contours
,
_
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
_
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
## [findContours]
## [allthework]
...
...
samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py
View file @
8eb987e3
...
...
@@ -16,7 +16,7 @@ def thresh_callback(val):
## [findContours]
# Find contours
_
,
contours
,
_
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
_
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
## [findContours]
# Find the rotated rectangles and ellipses for each contour
...
...
samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py
View file @
8eb987e3
...
...
@@ -13,7 +13,7 @@ def thresh_callback(val):
canny_output
=
cv
.
Canny
(
src_gray
,
threshold
,
threshold
*
2
)
# Find contours
_
,
contours
,
hierarchy
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
hierarchy
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
# Draw contours
drawing
=
np
.
zeros
((
canny_output
.
shape
[
0
],
canny_output
.
shape
[
1
],
3
),
dtype
=
np
.
uint8
)
...
...
samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py
View file @
8eb987e3
...
...
@@ -13,7 +13,7 @@ def thresh_callback(val):
canny_output
=
cv
.
Canny
(
src_gray
,
threshold
,
threshold
*
2
)
# Find contours
_
,
contours
,
_
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
_
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
# Find the convex hull object for each contour
hull_list
=
[]
...
...
samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py
View file @
8eb987e3
...
...
@@ -17,7 +17,7 @@ def thresh_callback(val):
## [findContours]
# Find contours
_
,
contours
,
_
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
_
=
cv
.
findContours
(
canny_output
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
## [findContours]
# Get the moments
...
...
samples/python/tutorial_code/ShapeDescriptors/point_polygon_test/pointPolygonTest_demo.py
View file @
8eb987e3
...
...
@@ -21,7 +21,7 @@ for i in range(6):
cv
.
line
(
src
,
vert
[
i
],
vert
[(
i
+
1
)
%
6
],
(
255
),
3
)
# Get the contours
_
,
contours
,
_
=
cv
.
findContours
(
src
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
contours
,
_
=
cv
.
findContours
(
src
,
cv
.
RETR_TREE
,
cv
.
CHAIN_APPROX_SIMPLE
)
# Calculate the distances to the contour
raw_dist
=
np
.
empty
(
src
.
shape
,
dtype
=
np
.
float32
)
...
...
samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py
View file @
8eb987e3
...
...
@@ -81,7 +81,7 @@ _, bw = cv.threshold(gray, 50, 255, cv.THRESH_BINARY | cv.THRESH_OTSU)
## [contours]
# Find all the contours in the thresholded image
_
,
contours
,
_
=
cv
.
findContours
(
bw
,
cv
.
RETR_LIST
,
cv
.
CHAIN_APPROX_NONE
)
contours
,
_
=
cv
.
findContours
(
bw
,
cv
.
RETR_LIST
,
cv
.
CHAIN_APPROX_NONE
)
for
i
,
c
in
enumerate
(
contours
):
# Calculate the area of each contour
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment