def is_repair_tool(self, img):
""" This uses color to determine if we have a repair tool, and if so, returns where
the button is located within the provided subimage """
lower = np.array([190, 0, 0], dtype = "uint8")
upper = np.array([255, 125, 100], dtype = "uint8")
mask = cv2.inRange(img, lower, upper)
contours = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contours = contours[0] if is_cv2() else contours[1]
if len(contours) == 0:
return None, False
sorted_contours = sorted(contours, cmp=lambda a,b: int(cv2.contourArea(b)) - int(cv2.contourArea(a)))
center, radius = cv2.minEnclosingCircle(sorted_contours[0])
up = True
if center[1] > (img.shape[0] / 2):
up = False
if self.debug:
debug_img = img.copy()
cv2.drawContours(debug_img, [sorted_contours[0]], -1, (0, 255, 0), 2)
cv2.imshow("cont", debug_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
return center, up
评论列表
文章目录