def find_contour(self, img_src, Rxmin, Rymin, Rxmax, Rymax):
cv2.rectangle(img_src, (Rxmax, Rymax), (Rxmin, Rymin), (0, 255, 0), 0)
crop_res = img_src[Rymin: Rymax, Rxmin:Rxmax]
grey = cv2.cvtColor(crop_res, cv2.COLOR_BGR2GRAY)
_, thresh1 = cv2.threshold(grey, 127, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
cv2.imshow('Thresh', thresh1)
contours, hierchy = cv2.findContours(thresh1.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
# draw contour on threshold image
if len(contours) > 0:
cv2.drawContours(thresh1, contours, -1, (0, 255, 0), 3)
return contours, crop_res
# Check ConvexHull and Convexity Defects
评论列表
文章目录