Learn R Programming

Rvision (version 0.6.0)

convexityDefects: Find the Convexity Defects of a Contour

Description

convexityDefects finds the convexity defects of a contour, that is area that do not belong to an object but are located inside of its convex hull.

Usage

convexityDefects(contours, id = NULL)

Arguments

contours

A list of two matrices as produced by findContours.

id

An optional vector indicating the identity of the specific contours for which to run the function.

Value

A matrix with 5 columns:

  • "id": the contour identity (indicates the set of points belonging to the same contour).

  • "start_index": index of the first point of the contour belonging to a convexity defect.

  • "end_index": index of the last point of the contour belonging to a convexity defect.

  • "farthest_pt_index": index of the point of the contour belonging to a convexity defect and that is the farthest away from the convex hull.

  • "fixpt_depth": distance between the farthest contour point and the convex hull.

See Also

findContours, convexHull

Examples

Run this code
# NOT RUN {
dots <- image(system.file("sample_img/dots.jpg", package = "Rvision"))
dots_gray <- changeColorSpace(dots, "GRAY")
dots_bin <- dots_gray < 200
contours <- findContours(dots_bin)
convexityDefects(contours, id = c(3, 5))

# }

Run the code above in your browser using DataLab