Calculates the derivatives of an image
[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]).
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); [contours] = findContours(img_canny, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, [0, 0]); subplot(1,2,2); img_contours = new_Mat(size(img, 'c'), size(img, 'r'), CV_8UC1, 0); img_contours_out = drawContours(img_contours, contours, -1, [255, 0, 0], -1); matplot(img_contours_out); title("contours"); delete_Mat(img_gray); delete_Mat(img_canny); delete_Mat(img_contours); | ![]() | ![]() |
| Version | Description |
| 4.8.1 | findContours() no more returns image. |