/// <summary>
        ///   Finds the convexity defects in a contour given a convex hull.
        /// </summary>
        ///
        /// <param name="contour">The contour.</param>
        /// <param name="convexHull">The convex hull of the contour.</param>
        /// <returns>A list of <see cref="ConvexityDefect"/>s containing each of the
        /// defects found considering the convex hull of the contour.</returns>
        ///
        public List <ConvexityDefect> FindDefects(List <IntPoint> contour, List <IntPoint> convexHull)
        {
            if (contour.Count < 4)
            {
                throw new ArgumentException("Point sequence size should have at least 4 points.");
            }

            if (convexHull.Count < 3)
            {
                throw new ArgumentException("Convex hull must have at least 3 points.");
            }


            // Find all convex hull points in the contour
            int[] indexes = new int[convexHull.Count];
            for (int i = 0, j = 0; i < contour.Count; i++)
            {
                if (convexHull.Contains(contour[i]))
                {
                    indexes[j++] = i;
                }
            }


            List <ConvexityDefect> defects = new List <ConvexityDefect>();

            // For each two consecutive points in the convex hull
            for (int i = 0; i < indexes.Length - 1; i++)
            {
                ConvexityDefect current = extractDefect(contour, indexes[i], indexes[i + 1]);

                if (current.Depth > MinimumDepth)
                {
                    defects.Add(current);
                }
            }

            // Consider area between the last point and the first point
            {
                ConvexityDefect current = extractDefect(contour, indexes[indexes.Length - 1], indexes[0]);

                if (current.Depth > MinimumDepth)
                {
                    defects.Add(current);
                }
            }

            return(defects);
        }