def convexity_defect(contour, curvature):
 kinks = []
 mean = np.mean(curvature)
 if (mean > 0):
  kink_index = [i for i in range(len(curvature)) if (curvature[i] < 0)]
 else:
  kink_index = [i for i in range(len(curvature)) if (curvature[i] > 0)]
 for s in kink_index:
  kinks.append(contour[(s + 1)])
 return (kinks, kink_index)

def convexity_defect ( contour , curvature ) : kinks = [ ] mean = np . mean ( curvature ) if ( mean > 0 ) : kink_index = [ i for i in range ( len ( curvature ) ) if ( curvature [ i ] < 0 ) ] else : kink_index = [ i for i in range ( len ( curvature ) ) if ( curvature [ i ] > 0 ) ] for s in kink_index : kinks . append ( contour [ ( s + 1 ) ] ) return ( kinks , kink_index )
contour is array shape=(number of points .