things.py 文件源码

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

项目:srcsim2017 作者: ZarjRobotics 项目源码 文件源码
def _find_habitat_things(self):
        """ Find interesting objects in the habitat world """
        self._find_repair_button_thing()

        # Start by grey scale, blur, and thresholding
        gray = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY)
        blurred = cv2.GaussianBlur(gray, (5, 5), 0)
        thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]

        # find contours in the thresholded image
        contours = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
        contours = contours[0] if is_cv2() else contours[1]

        debug_img = self.img.copy()

        for c in contours:
            thing = self._find_a_thing(c, self.MINIMUM_TOOL_LENGTH, self.MAXIMUM_TOOL_LENGTH,
                                     self.MINIMUM_TOOL_WIDTH, self.MAXIMUM_TOOL_WIDTH,
                                     self.TOOL_MUST_BE_WITHIN, debug_img)
            if thing is None:
                continue

            x,y,w,h = cv2.boundingRect(c)
            detector_center, up = self.is_detector(self.img[y:y+h,x:x+w].copy())

            if detector_center is not None:
                adjusted_detector = (int(detector_center[0] + x), int(detector_center[1] + y))
                thing.set_detector(adjusted_detector, up)
                self.things.append(thing)
                self.leak_detector = thing

            repair_center, up = self.is_repair_tool(self.img[y:y+h,x:x+w].copy())
            if repair_center is not None:
                adjusted_repair = (int(repair_center[0] + x), int(repair_center[1] + y))
                thing.set_repair_tool(adjusted_repair, up)
                self.things.append(thing)
                self.repair_tool = thing



        if self.debug:
            for c in contours:
                cv2.drawContours(debug_img, [c], -1, (0, 255, 0), 2)
            cv2.imshow("habitat things", debug_img)
            cv2.setMouseCallback("habitat things", self.handle_mouse)
            cv2.waitKey(0)
            cv2.destroyAllWindows()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号