Calculates the derivatives of an image
[img_out, contours] = findContours(img_in, mode, method[, offset])
Input image (single channel 8-bit, or 32-bit if mode is CV_RETR_CCOMP
or CV_RETR_FLOODFILL
) (Mat).
Contour retrieval mode (double):
CV_RETR_EXTERNAL
: returns only the outer contours.CV_RETR_LIST
: returns all the contours.CV_CCOMP
: returns a two level hierarchy in which the top level contains the outer boundaries of components, and the second level contains the holes.CV_RETR_TREE
: returns full hierarchy of contours.Contour approximation method (double).
CV_CHAIN_APPROX_ONE
: stores all the contour points.CV_RETR_LIST
: stores only end points of (horizontal/vertical/diagonal) segments.CV_CHAIN_APPROX_TC89_L1, CV_CHAIN_APPROX_TC89_KCOS
: used the the Tech-Chin algorithm to store points.Optional offset by which every contour point is shifted (default [0, 0]
).
Contour image (Mat).
List of detected contours (VecPoints).
findContours
retrieves the contours from a binary image.
scicv_Init(); img_gray = imread(getSampleImage("shapes.png"), CV_LOAD_IMAGE_GRAYSCALE); subplot(1,2,1); matplot(img_gray); thresh = 100; img_canny = Canny(img_gray, thresh, thresh*2, 3); [img_contours, contours] = findContours(img_canny, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, [0, 0]); subplot(1,2,2); matplot(img_contours); delete_Mat(img_gray); delete_Mat(img_canny); //delete_Mat(img_contours); | ![]() | ![]() |