diff --git a/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown b/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown index f018e111bb..35cb667e1a 100644 --- a/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown +++ b/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.markdown @@ -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) diff --git a/doc/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.markdown b/doc/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.markdown index c2055f75af..a2b89c1c96 100644 --- a/doc/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.markdown +++ b/doc/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.markdown @@ -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. contours 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. +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. @note We will discuss second and third arguments and about hierarchy in details later. Until then, diff --git a/doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown b/doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown index 378099a931..f11f11aed8 100644 --- a/doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown +++ b/doc/py_tutorials/py_imgproc/py_contours/py_contours_more_functions/py_contours_more_functions.markdown @@ -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) diff --git a/modules/imgproc/include/opencv2/imgproc.hpp b/modules/imgproc/include/opencv2/imgproc.hpp index 7f3d1515e5..67d363057b 100644 --- a/modules/imgproc/include/opencv2/imgproc.hpp +++ b/modules/imgproc/include/opencv2/imgproc.hpp @@ -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( InputOutputArray 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( InputOutputArray image, OutputArrayOfArrays contours, +CV_EXPORTS void findContours( InputArray image, OutputArrayOfArrays contours, int mode, int method, Point offset = Point()); /** @example samples/cpp/squares.cpp diff --git a/modules/imgproc/src/contours.cpp b/modules/imgproc/src/contours.cpp index f1c3338340..e584568bf0 100644 --- a/modules/imgproc/src/contours.cpp +++ b/modules/imgproc/src/contours.cpp @@ -1874,7 +1874,7 @@ cvFindContours( void* img, CvMemStorage* storage, return cvFindContours_Impl(img, storage, firstContour, cntHeaderSize, mode, method, offset, 1); } -void cv::findContours( InputOutputArray _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( InputOutputArray _image, OutputArrayOfArrays _contours, +void cv::findContours( InputArray _image, OutputArrayOfArrays _contours, int mode, int method, Point offset) { CV_INSTRUMENT_REGION(); diff --git a/modules/python/test/test_shape.py b/modules/python/test/test_shape.py index fbd705fbcb..1c9f07b7d4 100644 --- a/modules/python/test/test_shape.py +++ b/modules/python/test/test_shape.py @@ -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() diff --git a/modules/python/test/test_squares.py b/modules/python/test/test_squares.py index 92169b64c5..7d008760b4 100644 --- a/modules/python/test/test_squares.py +++ b/modules/python/test/test_squares.py @@ -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) diff --git a/samples/python/contours.py b/samples/python/contours.py index 69b46d493f..555c561c7c 100755 --- a/samples/python/contours.py +++ b/samples/python/contours.py @@ -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): diff --git a/samples/python/digits_video.py b/samples/python/digits_video.py index b2431c65fd..f669639f94 100755 --- a/samples/python/digits_video.py +++ b/samples/python/digits_video.py @@ -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: diff --git a/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py b/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py index e679001bc1..eafd588a44 100644 --- a/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py +++ b/samples/python/tutorial_code/ImgTrans/distance_transformation/imageSegmentation.py @@ -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) diff --git a/samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py b/samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py index fb5d68ac07..1549b33ce5 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py +++ b/samples/python/tutorial_code/ShapeDescriptors/bounding_rects_circles/generalContours_demo1.py @@ -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] diff --git a/samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py b/samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py index 16787718f6..2bc46635a1 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py +++ b/samples/python/tutorial_code/ShapeDescriptors/bounding_rotated_ellipses/generalContours_demo2.py @@ -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 diff --git a/samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py b/samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py index f4cbb5f401..23d2f467bb 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py +++ b/samples/python/tutorial_code/ShapeDescriptors/find_contours/findContours_demo.py @@ -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) diff --git a/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py b/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py index 3254941ac0..e9806a749f 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py +++ b/samples/python/tutorial_code/ShapeDescriptors/hull/hull_demo.py @@ -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 = [] diff --git a/samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py b/samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py index c528110ba1..13d915b883 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py +++ b/samples/python/tutorial_code/ShapeDescriptors/moments/moments_demo.py @@ -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 diff --git a/samples/python/tutorial_code/ShapeDescriptors/point_polygon_test/pointPolygonTest_demo.py b/samples/python/tutorial_code/ShapeDescriptors/point_polygon_test/pointPolygonTest_demo.py index 9b5dadb94c..0819551271 100644 --- a/samples/python/tutorial_code/ShapeDescriptors/point_polygon_test/pointPolygonTest_demo.py +++ b/samples/python/tutorial_code/ShapeDescriptors/point_polygon_test/pointPolygonTest_demo.py @@ -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) diff --git a/samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py b/samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py index af312d58f5..dcadbe6b62 100644 --- a/samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py +++ b/samples/python/tutorial_code/ml/introduction_to_pca/introduction_to_pca.py @@ -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