Exemplo n.º 1
0
    def get_views(self):
        """
        get UI views using cv module
        opencv-python need to be installed for this function
        :return: a list of views
        """
        if not self.last_screen:
            self.logger.warning("last_screen is None")
            return None
        if self.last_views:
            return self.last_views

        import cv
        img = cv.load_image_from_buf(self.last_screen)
        view_bounds = cv.find_views(img)
        root_view = {
            "class": "CVViewRoot",
            "bounds": [[0, 0], [self.width, self.height]],
            "enabled": True,
            "temp_id": 0
        }
        views = [root_view]
        temp_id = 1
        for x, y, w, h in view_bounds:
            view = {
                "class": "CVView",
                "bounds": [[x, y], [x + w, y + h]],
                "enabled": True,
                "temp_id": temp_id,
                "signature": cv.calculate_dhash(img[y:y + h, x:x + w]),
                "parent": 0,
                "children": []
            }
            views.append(view)
            temp_id += 1
        root_view["children"] = list(range(1, temp_id))

        self.last_views = views
        return views
Exemplo n.º 2
0
    def get_views(self):
        """
        get UI views using cv module
        opencv-python need to be installed for this function
        :return: a list of views
        """
        if not self.last_screen:
            self.logger.warning("last_screen is None")
            return None
        if self.last_views:
            return self.last_views

        import cv
        img = cv.load_image_from_buf(self.last_screen)
        view_bounds = cv.find_views(img)
        root_view = {
            "class": "CVViewRoot",
            "bounds": [[0, 0], [self.width, self.height]],
            "enabled": True,
            "temp_id": 0
        }
        views = [root_view]
        temp_id = 1
        for x,y,w,h in view_bounds:
            view = {
                "class": "CVView",
                "bounds": [[x,y], [x+w, y+h]],
                "enabled": True,
                "temp_id": temp_id,
                "signature": cv.calculate_dhash(img[y:y+h, x:x+w]),
                "parent": 0
            }
            views.append(view)
            temp_id += 1
        root_view["children"] = list(range(1, temp_id))

        self.last_views = views
        return views