def _detect_bot(self, hsv_image):
BOT_MIN = np.array([28,8,100], np.uint8)
BOT_MAX = np.array([32,255,255], np.uint8)
thresholded_image = cv2.inRange(hsv_image, BOT_MIN, BOT_MAX)
thresholded_image = cv2.medianBlur(thresholded_image, 15)
_, contours, hierarchy = cv2.findContours(thresholded_image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
if not contours:
(bot_x, bot_y) = (-1000,-1000)
else:
bot = contours[0]
M = cv2.moments(bot)
if len(bot) > 2:
bot_x = int(M['m10']/M['m00'])
bot_y = int(M['m01']/M['m00'])
else:
(bot_x, bot_y) = (-1000,-1000)
return thresholded_image, (bot_x, bot_y)
评论列表
文章目录