def detectEndGesture(defects, contour, contourProps): positiveDefects = 0 for defect in defects: start_i, end_i, far_i, distancePointHull = defect[0] distancePointHull = round(distancePointHull/256.0) end = tuple(contour[end_i][0]) #line from center of contour to convexhull point center = (int(contourProps["Centroid"][0]), int(contourProps["Centroid"][1])) # relations of gesture distanceCenterHull = tools.getDistanceBetweenPoints(center, end) relationCenterHull_EndHull = (distanceCenterHull/distancePointHull) relationCenterHull_ClosestPerimeter = (distanceCenterHull/cv2.pointPolygonTest(contour, center, True)) if( (relationCenterHull_EndHull > 10.0) and (relationCenterHull_ClosestPerimeter <= 2.0)): positiveDefects = positiveDefects + 1 return positiveDefects
def drawDefects(image, defects, contour, contourProps): #try: center = (int(contourProps["Centroid"][0]), int(contourProps["Centroid"][1])) for defect in defects: start_i, end_i, far_i, distance = defect[0] distance = round(distance/256.0) start = tuple(contour[start_i][0]) end = tuple(contour[end_i][0]) far = tuple(contour[far_i][0]) #convexhull cv2.line(image, start, end, [0,0,255], 1) #line from farthest point to convexhull cv2.line(image, far, end, [0,0,255], 1) #line from center of contour to convexhull point cv2.line(image, end, center, [255,0,255], 1) #points cv2.circle(image, end, 5, [0,0,255], -1) cv2.circle(image, far, 5, [0,0,255], -1) #write distance between hull and farthest point tools.setText(image, end, str(distance)) distanceCenterHull = tools.getDistanceBetweenPoints(center, end) centerLine = tools.getMidPointInLine(center, end) tools.setText(image, centerLine, str(distanceCenterHull))