cv.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:Pacbot 作者: HarvardURC 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号