コード例 #1
0
ファイル: landmark.py プロジェクト: dpfried/bolt
 def __init__(self, lmk_group, alt_of=None):
     shapes = [lmk.representation.get_geometry() for lmk in lmk_group]
     super(GroupRectangleRepresentation, self).__init__(rect=BoundingBox.from_shapes(shapes),
                                                        landmarks_to_get=['middle'],
                                                        alt_of=alt_of)
     self.alt_representations = []
     self.landmark_group = lmk_group
コード例 #2
0
 def __init__(self, lmk_group, alt_of=None):
     shapes = [lmk.representation.get_geometry() for lmk in lmk_group]
     super(GroupRectangleRepresentation, self).__init__(rect=BoundingBox.from_shapes(shapes),
                                                        landmarks_to_get=['middle'],
                                                        alt_of=alt_of)
     self.alt_representations = []
     self.landmark_group = lmk_group
コード例 #3
0
ファイル: landmark.py プロジェクト: wrightjb/bolt
    def __init__(self,
                 orientation='height',
                 line=LineSegment.from_points([Vec2(0, 0),
                                               Vec2(1, 0)]),
                 alt_of=None):
        super(LineRepresentation, self).__init__(alt_of)
        self.line = line
        # extend the LineSegment to include a bounding_box field, planar doesn't have that originally
        self.line.bounding_box = BoundingBox.from_points(self.line.points)
        self.num_dim = 1
        self.middle = line.mid
        self.alt_representations = [PointRepresentation(self.line.mid, self)]

        classes = [Landmark.END, Landmark.MIDDLE, Landmark.END] if orientation == 'height' \
             else [Landmark.SIDE, Landmark.MIDDLE, Landmark.SIDE]

        self.landmarks = {
            'start':
            Landmark('start', PointRepresentation(self.line.start), self,
                     classes[0]),
            'end':
            Landmark('end', PointRepresentation(self.line.end), self,
                     classes[2]),
            'middle':
            Landmark('middle', PointRepresentation(self.line.mid), self,
                     classes[1]),
        }
コード例 #4
0
def convert_to_bboxes(data):
    BoundingBoxes = []
    for i in data:
        minvec = Vec2(i.bbmin[0], i.bbmin[1])
        maxvec = Vec2(i.bbmax[0], i.bbmax[1])
        BoundingBoxes.append(BoundingBox((minvec, maxvec)))
    return BoundingBoxes
コード例 #5
0
def find_bounding_box(route_coordinates):
    """Returns rough bounding box for given route coordinates to help query tags along route. 
    Currently draws a rectangle around each set of long/lat points that make a path segment. 

    >>> find_bounding_box([(37,122),(36,123),(36,122)])
    [BoundingBox([(35.999, 121.999), (37.001, 123.001)]), BoundingBox([(35.999, 121.999), (36.001, 123.001)])]
    >>>  

    """

    bboxes = []

    for i in range(len(route_coordinates) - 1):
        bbox = BoundingBox([route_coordinates[i], route_coordinates[i + 1]])
        bbox = bbox.inflate(.002)
        bboxes.append(bbox)
        i += 1

    return bboxes
コード例 #6
0
ファイル: route.py プロジェクト: DrewForeman/project_tagline
def find_bounding_box(route_coordinates):
    """Returns rough bounding box for given route coordinates to help query tags along route. 
    Currently draws a rectangle around each set of long/lat points that make a path segment. 

    >>> find_bounding_box([(37,122),(36,123),(36,122)])
    [BoundingBox([(35.999, 121.999), (37.001, 123.001)]), BoundingBox([(35.999, 121.999), (36.001, 123.001)])]
    >>>  

    """

    bboxes = []

    for i in range(len(route_coordinates)-1):
        bbox = BoundingBox([route_coordinates[i],route_coordinates[i+1]])
        bbox = bbox.inflate(.002)
        bboxes.append(bbox)
        i += 1


    return bboxes
コード例 #7
0
def extract_file(file_name):
    """
    This function extract bbox coordinates from the list in the given file
    :param file_name: file path of Ground truth
    :return: a numpy array of bounding boxes
    """
    boxes = np.loadtxt(file_name, delimiter=',')
    b_list = []
    for box in boxes:
        bbox = BoundingBox(list(box.reshape(-1, 2)))
        b_list.append([list(bbox.min_point) + [bbox.width, bbox.height]])

    return np.array(b_list).reshape(-1, 4)
コード例 #8
0
def construct_training_scene():
    speaker = Speaker(Vec2(0, 0))
    scene = Scene(3)

    table = Landmark(
        'table',
        RectangleRepresentation(
            rect=BoundingBox([Vec2(-0.4, 0.4), Vec2(0.4, 1.0)])), None,
        ObjectClass.TABLE)

    obj1 = Landmark(
        'green_cup',
        RectangleRepresentation(rect=BoundingBox(
            [Vec2(0.05 - 0.035, 0.9 - 0.035),
             Vec2(0.05 + 0.035, 0.9 + 0.035)]),
                                landmarks_to_get=[]), None, ObjectClass.CUP,
        Color.GREEN)

    obj2 = Landmark(
        'blue_cup',
        RectangleRepresentation(rect=BoundingBox(
            [Vec2(0.05 - 0.035, 0.7 - 0.035),
             Vec2(0.05 + 0.035, 0.7 + 0.035)]),
                                landmarks_to_get=[]), None, ObjectClass.CUP,
        Color.BLUE)

    obj3 = Landmark(
        'pink_cup',
        RectangleRepresentation(rect=BoundingBox(
            [Vec2(0 - 0.035, 0.55 - 0.035),
             Vec2(0 + 0.035, 0.55 + 0.035)]),
                                landmarks_to_get=[]), None, ObjectClass.CUP,
        Color.PINK)

    obj4 = Landmark(
        'purple_prism',
        RectangleRepresentation(rect=BoundingBox(
            [Vec2(-0.3 - 0.03, 0.7 - 0.05),
             Vec2(-0.3 + 0.03, 0.7 + 0.05)]),
                                landmarks_to_get=[]), None, ObjectClass.PRISM,
        Color.PURPLE)

    obj5 = Landmark(
        'orange_prism',
        RectangleRepresentation(rect=BoundingBox(
            [Vec2(0.3 - 0.03, 0.7 - 0.05),
             Vec2(0.3 + 0.03, 0.7 + 0.05)]),
                                landmarks_to_get=[]), None, ObjectClass.PRISM,
        Color.ORANGE)

    scene.add_landmark(table)

    for obj in (obj1, obj2, obj3, obj4, obj5):
        obj.representation.alt_representations = []
        scene.add_landmark(obj)

    return scene, speaker
コード例 #9
0
def geoDataRefactor(dicGeo):
    """
    This function is a refactoring function. It goal is to replace the bounding box data into a single point
    :param dicGeo: Dictionnary which contains the place json from a tweet
    :return rDic: Dictionnary with coordinates instead of bounding box
    """
    rDic = {}
    rDic["place_type"] = dicGeo["place_type"]
    rDic["name"] = dicGeo["name"]
    rDic["full_name"] = dicGeo["full_name"]
    rDic["country_code"] = dicGeo["country_code"]
    rDic["country"] = dicGeo["country"]
    bbox = BoundingBox(dicGeo["bounding_box"]["coordinates"][0])
    centerBbox = [bbox.center[0], bbox.center[1]]
    rDic["coordinates"] = centerBbox

    return rDic
コード例 #10
0
ファイル: landmark.py プロジェクト: marcovzla/bolt
    def __init__(self, orientation='height', line=LineSegment.from_points([Vec2(0, 0), Vec2(1, 0)]), alt_of=None):
        super(LineRepresentation, self).__init__(alt_of)
        self.line = line
        # extend the LineSegment to include a bounding_box field, planar doesn't have that originally
        self.line.bounding_box = BoundingBox.from_points(self.line.points)
        self.num_dim = 1
        self.middle = line.mid
        self.alt_representations = [PointRepresentation(self.line.mid, self)]

        classes = [Landmark.END, Landmark.MIDDLE, Landmark.END] if orientation == 'height' \
             else [Landmark.SIDE, Landmark.MIDDLE, Landmark.SIDE]

        self.landmarks = {
            'start':  Landmark('start',  PointRepresentation(self.line.start), self, classes[0]),
            'end':    Landmark('end',    PointRepresentation(self.line.end),   self, classes[2]),
            'middle': Landmark('middle', PointRepresentation(self.line.mid),   self, classes[1]),
        }
コード例 #11
0
ファイル: utils.py プロジェクト: wrightjb/bolt
    def __init__(self, scene=None, speaker=None):
        self.scene = scene
        if scene is None:
            self.scene = Scene(3)

            # not a very furnished scene, we only have one table
            table = Landmark('table',
                             RectangleRepresentation(rect=BoundingBox([Vec2(5,5), Vec2(6,7)])),
                             None,
                             ObjectClass.TABLE)

            self.scene.add_landmark(table)
            self.table = table

        self.table = self.scene.landmarks['table']

        # there is a person standing at this location
        # he will be our reference
        if speaker is None:
            self.speaker = Speaker(Vec2(5.5, 4.5))
        else:
            self.speaker = speaker

        # NOTE we need to keep around the list of landmarks so that we can
        # access them by id, which is the index of the landmark in this list
        # collect all possible landmarks
        self.landmarks = []
        for scene_lmk in self.scene.landmarks.itervalues():
            self.landmarks.append(scene_lmk)

            # a scene can be represented as a plane, line, etc
            # each representation of a scene has different landmarks
            rs = [scene_lmk.representation]
            rs.extend(scene_lmk.representation.get_alt_representations())

            for r in rs:
                for lmk in r.get_landmarks():
                    self.landmarks.append(lmk)

        # FIXME we are using sentences with 1 or 2 LANDMARK-PHRASEs
        # so we need to restrict the landmarks to 0 or 1 ancestors
        self.landmarks = [l for l in self.landmarks if l.get_ancestor_count() < 2]
コード例 #12
0
ファイル: landmark.py プロジェクト: dpfried/bolt
    def __init__(self, ratio=None, line=LineSegment.from_points([Vec2(0, 0), Vec2(1, 0)]), alt_of=None):
        super(LineRepresentation, self).__init__(alt_of)
        self.line = line
        # extend the LineSegment to include a bounding_box field, planar doesn't have that originally
        self.line.bounding_box = BoundingBox.from_points(self.line.points)
        self.num_dim = 1
        self.middle = line.mid
        self.alt_representations = [PointRepresentation(self.line.mid, self)]
        self.ratio_limit = 2


        if ratio is None or ratio >= self.ratio_limit:
            self.landmarks = {
                'start':  Landmark('start',  PointRepresentation(self.line.start), self, Landmark.END),
                'middle': Landmark('middle', PointRepresentation(self.line.mid),   self, Landmark.MIDDLE),
                'end':    Landmark('end',    PointRepresentation(self.line.end),   self, Landmark.END),
            }
        else:
            self.landmarks = {
                'start':  Landmark('start',  PointRepresentation(self.line.start), self, Landmark.SIDE),
                'end':    Landmark('end',    PointRepresentation(self.line.end),   self, Landmark.SIDE)
            }
コード例 #13
0
    def __init__(self, ratio=None, line=LineSegment.from_points([Vec2(0, 0), Vec2(1, 0)]), alt_of=None):
        super(LineRepresentation, self).__init__(alt_of)
        self.ratio = ratio
        self.line = line
        # extend the LineSegment to include a bounding_box field, planar doesn't have that originally
        self.line.bounding_box = BoundingBox.from_points(self.line.points)
        self.num_dim = 1
        self.middle = line.mid
        self.alt_representations = [PointRepresentation(self.line.mid, self)]
        self.ratio_limit = 2

        if ratio is None or ratio >= self.ratio_limit:
            self.landmarks = {
                'start':  Landmark('start',  PointRepresentation(self.line.start), self, Landmark.END),
                'middle': Landmark('middle', PointRepresentation(self.line.mid),   self, Landmark.MIDDLE),
                'end':    Landmark('end',    PointRepresentation(self.line.end),   self, Landmark.END),
            }
        else:
            self.landmarks = {
                'start':  Landmark('start',  PointRepresentation(self.line.start), self, Landmark.SIDE),
                'end':    Landmark('end',    PointRepresentation(self.line.end),   self, Landmark.SIDE)
            }
コード例 #14
0
ファイル: bolt_gui.py プロジェクト: ntrntr/ua-ros-pkg
    def construct_abstract_scene(self, scene_msg):
        scene = Scene(3)

        for i, (obj, name) in enumerate(zip(scene_msg.bboxes,
                                            scene_msg.names)):
            BB = BoundingBox(
                [point_to_vec(obj.points[0]),
                 point_to_vec(obj.points[1])])
            polygon, _ = self.get_image_polygon(obj)

            if name == 'table':
                l = Landmark(name, RectangleRepresentation(BB), None,
                             ObjectClass.TABLE)
            else:
                for center, color, category in zip(
                        self.object_centers_msg.centers,
                        self.object_centers_msg.color_labels,
                        self.object_centers_msg.category_labels):
                    if polygon.contains_point(
                            Vec2(center.pixel.x, center.pixel.y)):
                        l = Landmark(
                            name,
                            RectangleRepresentation(BB, landmarks_to_get=[]),
                            None, category.upper(), color.upper())
                        l.representation.alt_representations = []

                        scene_msg.colors[i] = color.upper()
                        scene_msg.categories[i] = category.upper()

                        break

            scene.add_landmark(l)
            self.scene_lmk_to_bbox[l] = obj

        self.scene_pub.publish(scene_msg)
        rospy.loginfo('Constructed a scene')
        return scene
コード例 #15
0
ファイル: landmark.py プロジェクト: marcovzla/bolt
 def get_bounding_box(self):
     return BoundingBox.from_shapes([lmk.representation.get_geometry() for lmk in self.landmarks.values()])
コード例 #16
0
 def get_bounding_box(self):
     return BoundingBox.from_shapes([
         lmk.representation.get_geometry()
         for lmk in self.landmarks.values()
     ])
コード例 #17
0
    def __init__(self, rect=BoundingBox([Vec2(0, 0), Vec2(1, 2)]),
                 landmarks_to_get=['ll_corner','ur_corner','lr_corner','ul_corner',
                                   'middle',
                                   'l_edge','r_edge','n_edge','f_edge',
                                   'l_surf','r_surf','n_surf','f_surf',
                                   'm_surf',
                                   'll_corner_surf','ur_corner_surf','lr_corner_surf','ul_corner_surf',
                                   'l_edge_surf','r_edge_surf','n_edge_surf','f_edge_surf'],
                 alt_of=None):
        super(RectangleRepresentation, self).__init__(alt_of)
        self.rect = rect
        self.num_dim = 2
        self.middle = rect.center
        self.landmarks_to_get = landmarks_to_get
        vert_ratio = self.rect.height / self.rect.width
        horiz_ratio = self.rect.width / self.rect.height
        self.alt_representations = [LineRepresentation( horiz_ratio,
                                                        LineSegment.from_points([Vec2(self.rect.min_point.x, self.rect.center.y),
                                                                                 Vec2(self.rect.max_point.x, self.rect.center.y)],),
                                                        self),
                                    LineRepresentation( vert_ratio,
                                                        LineSegment.from_points([Vec2(self.rect.center.x, self.rect.min_point.y),
                                                                                 Vec2(self.rect.center.x, self.rect.max_point.y)]),
                                                        self)]

        lrc = Vec2(self.rect.min_point.x + self.rect.width, self.rect.min_point.y)
        ulc = Vec2(self.rect.max_point.x - self.rect.width, self.rect.max_point.y)

        min_dimension = min(self.rect.height,self.rect.width)
        landmark_constructors = {
                'll_corner': '''Landmark('ll_corner', PointRepresentation(self.rect.min_point), self, Landmark.CORNER)''',
                'ur_corner': '''Landmark('ur_corner', PointRepresentation(self.rect.max_point), self, Landmark.CORNER)''',
                'lr_corner': '''Landmark('lr_corner', PointRepresentation(lrc), self, Landmark.CORNER)''',
                'ul_corner': '''Landmark('ul_corner', PointRepresentation(ulc), self, Landmark.CORNER)''',
                'middle':    '''Landmark('middle',    PointRepresentation(self.rect.center), self, Landmark.MIDDLE)''',
                'l_edge_surf':    '''Landmark('l_edge',    LineRepresentation(vert_ratio, LineSegment.from_points([self.rect.min_point, ulc])), self, Landmark.EDGE)''',
                'r_edge':    '''Landmark('r_edge',    LineRepresentation(vert_ratio, LineSegment.from_points([lrc, self.rect.max_point])), self, Landmark.EDGE)''',
                'n_edge':    '''Landmark('n_edge',    LineRepresentation(horiz_ratio, LineSegment.from_points([self.rect.min_point, lrc])), self, Landmark.EDGE)''',
                'f_edge':    '''Landmark('f_edge',    LineRepresentation(horiz_ratio, LineSegment.from_points([ulc, self.rect.max_point])), self, Landmark.EDGE)''',

                'l_surf':    '''Landmark('l_surf',    SurfaceRepresentation( BoundingBox([rect.min_point,
                                                                                       Vec2(rect.min_point.x+rect.width/2.0,
                                                                                            rect.max_point.y)]),
                                                                          landmarks_to_get=['ll_corner','ul_corner','l_edge']),
                                      self, Landmark.HALF)''',
                'r_surf':    '''Landmark('r_surf',    SurfaceRepresentation( BoundingBox([Vec2(rect.min_point.x+rect.width/2.0,
                                                                                            rect.min_point.y),
                                                                                       rect.max_point]),
                                                                          landmarks_to_get=['lr_corner','ur_corner','r_edge']),
                                      self, Landmark.HALF)''',
                'n_surf':    '''Landmark('n_surf',    SurfaceRepresentation( BoundingBox([rect.min_point,
                                                                                       Vec2(rect.max_point.x,
                                                                                            rect.min_point.y+rect.height/2.0)]),
                                                                          landmarks_to_get=['ll_corner','lr_corner','n_edge']),
                                      self, Landmark.HALF)''',
                'f_surf':    '''Landmark('f_surf',    SurfaceRepresentation( BoundingBox([Vec2(rect.min_point.x,
                                                                                            rect.min_point.y+rect.height/2.0),
                                                                                       rect.max_point]),
                                                                          landmarks_to_get=['ul_corner','ur_corner','f_edge']),
                                      self, Landmark.HALF)''',

                'm_surf':    '''Landmark('m_surf',    SurfaceRepresentation( BoundingBox([Vec2(rect.min_point.x+rect.width/4.0,
                                                                                            rect.min_point.y+rect.height/4.0),
                                                                                       Vec2(rect.max_point.x-rect.width/4.0,
                                                                                            rect.max_point.y-rect.height/4.0)])), self, Landmark.MIDDLE)''',
                'll_corner_surf': '''Landmark('ll_corner_surf', SurfaceRepresentation( BoundingBox([rect.min_point,
                                                                                                    Vec2(rect.min_point.x+min_dimension/4.0,
                                                                                                         rect.min_point.y+min_dimension/4.0)])), self, Landmark.CORNER)''',
                'ur_corner_surf': '''Landmark('ur_corner_surf', SurfaceRepresentation( BoundingBox([Vec2(rect.max_point.x-min_dimension/4.0,
                                                                                                         rect.max_point.y-min_dimension/4.0),
                                                                                                    rect.max_point])), self, Landmark.CORNER)''',
                'lr_corner_surf': '''Landmark('lr_corner_surf', SurfaceRepresentation( BoundingBox([Vec2(rect.max_point.x-min_dimension/4.0,
                                                                                                         rect.min_point.y),
                                                                                                    Vec2(rect.max_point.x,
                                                                                                         rect.min_point.y+min_dimension/4.0)])), self, Landmark.CORNER)''',
                'ul_corner_surf': '''Landmark('ul_corner_surf', SurfaceRepresentation( BoundingBox([Vec2(rect.min_point.x,
                                                                                                         rect.max_point.y-min_dimension/4.0),
                                                                                                    Vec2(rect.min_point.x+min_dimension/4.0,
                                                                                                         rect.max_point.y)])), self, Landmark.CORNER)''',
                'l_edge_surf':    '''Landmark('l_edge_surf', SurfaceRepresentation( BoundingBox([rect.min_point,
                                                                                                 Vec2(rect.min_point.x+min_dimension/8.0,
                                                                                                      rect.max_point.y)])), self, Landmark.EDGE)''',
                'r_edge_surf':    '''Landmark('r_edge_surf', SurfaceRepresentation( BoundingBox([Vec2(rect.max_point.x-min_dimension/8.0,
                                                                                                      rect.min_point.y),
                                                                                                 rect.max_point])), self, Landmark.EDGE)''',
                'n_edge_surf':    '''Landmark('n_edge_surf', SurfaceRepresentation( BoundingBox([rect.min_point,
                                                                                                 Vec2(rect.max_point.x,
                                                                                                      rect.min_point.y+min_dimension/8.0)])), self, Landmark.EDGE)''',
                'f_edge_surf':    '''Landmark('f_edge_surf', SurfaceRepresentation( BoundingBox([Vec2(rect.min_point.x,
                                                                                                      rect.max_point.y-min_dimension/8.0),
                                                                                                 rect.max_point])), self, Landmark.EDGE)''',
        }

        self.landmarks = {}
        for lmk_name in landmarks_to_get:
            if lmk_name in landmark_constructors:
                self.landmarks[lmk_name] = eval(landmark_constructors[lmk_name])
コード例 #18
0
 def bounding_box(self) -> BoundingBox:
     return BoundingBox.from_shapes(segment.region for segment in self.segments)
コード例 #19
0
 def __init__(self, rect=BoundingBox([Vec2(0, 0), Vec2(1, 2)]), landmarks_to_get=[]):
     super(SurfaceRepresentation, self).__init__(rect, landmarks_to_get)
     self.alt_representations = []
コード例 #20
0
    count = 0
    for x in range(1, (int(cols) + 1)):
        for y in range(1, (int(rows) + 1)):
            data = {}
            count += 1
            # minx = minx + (x * tile_size)
            # miny = miny + (y * tile_size)
            minx = x * tile_size
            miny = y * tile_size
            minx = minx + dict1['patch_minx']
            miny = miny + dict1['patch_miny']
            maxx = minx + tile_size
            maxy = miny + tile_size
            # print((minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy))
            bbox = BoundingBox([(minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy)])
            tile = slide.read_region((minx, miny), 0, (tile_size, tile_size))
            tile.save('tile' + str(count) + '.png', "png")

            # print(bbox)
            df = pandas.read_csv('x63488_y49152-features.csv')
            row_list = []
            df2 = pandas.DataFrame()
            for index, row in df.iterrows():
                poly_data = row['Polygon']
                tmp_str = str(poly_data)
                tmp_str = tmp_str.replace('[', '')
                tmp_str = tmp_str.replace(']', '')
                split_str = tmp_str.split(':')
                # Get list of points
                for i in range(0, len(split_str) - 1, 2):
コード例 #21
0
ファイル: serialize.py プロジェクト: arebgun/bolt-semantics
def bbox_from_dict(dikt):
    return BoundingBox(
        [vec2_from_dict(dikt['min_point']),
         vec2_from_dict(dikt['max_point'])])
コード例 #22
0
ファイル: geometry.py プロジェクト: arebgun/bolt-semantics
 def __init__(self, center, radius):
     self.center = center
     self.radius = radius
     rad_point = Vec2(radius, radius)
     self.bounding_box = BoundingBox(
         [self.center - rad_point, self.center + rad_point])
コード例 #23
0
 def handle_scene(self, msg):
     
     def get_image_polygon(obj):
         minps = PointStamped()
         minps.header.stamp = rospy.Time(0)
         minps.header.frame_id = 'base_footprint'
         minps.point.x = obj.points[0].y
         minps.point.y = -obj.points[0].x
         minps.point.z = obj.points[0].z
         
         minp = self.tf.transformPoint('kinect_rgb_optical_frame', minps).point
         
         minps.point.x = obj.points[1].y
         minps.point.y = -obj.points[1].x
         minps.point.z = obj.points[1].z
         
         maxp = self.tf.transformPoint('kinect_rgb_optical_frame', minps).point
         
         ct = np.array( [(minp.x,minp.y,minp.z), (maxp.x,minp.y,minp.z), (maxp.x,maxp.y,maxp.z), (minp.x,maxp.y,maxp.z)] )
         corners = cv.fromarray(ct)
         out = cv.fromarray(np.zeros((4,2)))
         cam_mat = np.array( [(525, 0, 319.5), (0, 525, 239.5), (0, 0, 1)] )
         cv.ProjectPoints2(corners,
                           cv.fromarray(np.zeros((1,3))),
                           cv.fromarray(np.zeros((1,3))),
                           cv.fromarray(cam_mat),
                           cv.fromarray(np.zeros((1,4))),
                           out)
         
         vs = []
         for l in np.asarray(out):
             vs.append( Vec2(*l) )
         
         return Polygon(vs)
     
     obj_centers = rospy.wait_for_message('/object_centers', ObjectCenters)
     
     scene = Scene(3)
     
     for obj,name in zip(msg.bboxes, msg.names):
         BB = BoundingBox([point_to_vec(obj.points[0]), point_to_vec(obj.points[1])])
         polygon = get_image_polygon(obj)
         if name == 'table':
             l = Landmark(name,
                          RectangleRepresentation( BB ),
                          None,
                          ObjectClass.TABLE)
         else:
             for center,color,category in zip(obj_centers.centers, obj_centers.color_labels, obj_centers.category_labels):
                 if polygon.contains_point( Vec2(center.pixel.x,center.pixel.y) ):
                     l = Landmark(name,
                                  RectangleRepresentation( BB, landmarks_to_get=[] ),
                                  None,
                                  category.upper(),
                                  color.upper())
                     l.representation.alt_representations= []
                     break
         scene.add_landmark(l)
         
     self.last_scene = scene
     rospy.loginfo('Constructed a scene')
コード例 #24
0
DETAILS:
    The returned boundingBox box is with the minimum area i.e it exactly
    encloses all the points (max and min values lie  on the BoundingBox).

    Our requirement could be interpreted as: keeping this bounding box within
    the FOV. We also need to consider that the points would be in motion. It
    would be efficient to have some slack in the heading direction (derived
    from the predicitPath module) and keeping the FOV closer to the lower edge
    of the BoundingBox. This way we could increase the duration of the targets
    lying within the FOV.

    Also before calculating the FOV and maneuvering the UAV, stand-off distance
    must be calculated (Move closer if distance is more or vice versa).
"""
bbox = BoundingBox([(0,0), (1,2), (-5,6), (-3,2), (0.5,-1)])

#for math verification
print(bbox)


def check_targets(input_coordinates):
   """
PRIMARY FUNCTION WHICH INVOKES VARIOUS OTHER MINOR FUNCTIONS

   :param       input_coordinates
   :return:     none

   :details:
   Verify if the targets exist within the current FOV. Complex : Need to project
   the UAV's current FOV in terms of GPS co-ordinates (with only current GPS
コード例 #25
0
ファイル: run.py プロジェクト: arebgun/bolt-semantics
def load_scene(file, normalize=False):
    jtoclass = {
        u'Box': ObjectClass.BOX,
        u'Cylinder': ObjectClass.CYLINDER,
        u'Sphere': ObjectClass.SPHERE,
    }

    jtocolor = {
        u'yellow': Color.YELLOW,
        u'orange': Color.ORANGE,
        u'red': Color.RED,
        u'green': Color.GREEN,
        u'purple': Color.PURPLE,
        u'blue': Color.BLUE,
        u'pink': Color.PINK,
    }

    json_data = open(file)
    data = json.load(json_data)
    json_data.close()

    #pprint(data)

    scene = Scene(3)

    table_spec = data[u'table']
    t_min = Vec2(table_spec[u'aabb'][u'min'][2],
                 table_spec[u'aabb'][u'min'][0])
    t_max = Vec2(table_spec[u'aabb'][u'max'][2],
                 table_spec[u'aabb'][u'max'][0])

    width = t_max.x - t_min.x
    height = t_max.y - t_min.y
    if normalize: norm_factor = width if width >= height else height

    t_min = Vec2(t_min.x / norm_factor, t_min.y / norm_factor)
    t_max = Vec2(t_max.x / norm_factor, t_max.y / norm_factor)

    table = Landmark('table',
                     RectangleRepresentation(rect=BoundingBox([t_min, t_max])),
                     None, ObjectClass.TABLE)

    scene.add_landmark(table)

    object_specs = data[u'objects']
    print 'there are', len(object_specs), 'objects on the table'

    for i, obj_spec in enumerate(object_specs):
        o_min = Vec2(obj_spec[u'aabb'][u'min'][2],
                     obj_spec[u'aabb'][u'min'][0])
        o_max = Vec2(obj_spec[u'aabb'][u'max'][2],
                     obj_spec[u'aabb'][u'max'][0])

        width = o_max.x - o_min.x
        height = o_max.y - o_min.y

        o_min = Vec2(o_min.x / norm_factor, o_min.y / norm_factor)
        o_max = Vec2(o_max.x / norm_factor, o_max.y / norm_factor)

        obj = Landmark(
            'object_%s' % obj_spec[u'name'],
            RectangleRepresentation(rect=BoundingBox([o_min, o_max]),
                                    landmarks_to_get=[]), None,
            jtoclass[obj_spec[u'type']], jtocolor[obj_spec[u'color-name']])

        obj.representation.alt_representations = []
        scene.add_landmark(obj)

    camera_spec = data[u'cam']
    speaker = Speaker(
        Vec2(camera_spec[u'loc'][2] / norm_factor,
             camera_spec[u'loc'][0] / norm_factor))

    # speaker.visualize(scene, obj, Vec2(0,0), None, None, '')
    return scene, speaker
コード例 #26
0
ファイル: run.py プロジェクト: arebgun/bolt-semantics
def construct_training_scene(random=False):
    speaker = Speaker(Vec2(0, 0))
    scene = Scene(3)

    table_ll = (-0.4, 0.4)
    table_ur = (0.4, 1.6)
    if random:
        x_range = (table_ll[0] + 0.035, table_ur[0] - 0.035)
        y_range = (table_ll[1] + 0.045, table_ur[1] - 0.045)
        centers = []
        for _ in range(5):
            condition = True
            while condition:
                new_point = (randrange(*x_range), randrange(*y_range))
                condition = (sum([too_close(new_point, p)
                                  for p in centers]) > 0)
            centers.append(new_point)
    else:
        centers = [(0.05, 0.9), (0.05, 0.7), (0, 0.55), (-0.3, 0.7),
                   (0.3, 0.7)]

    table = Landmark(
        'table',
        RectangleRepresentation(
            rect=BoundingBox([Vec2(
                *table_ll), Vec2(*table_ur)])), None, ObjectClass.TABLE)

    obj1 = Landmark(
        'green_cup',
        RectangleRepresentation(rect=BoundingBox([
            Vec2(centers[0][0] - 0.035, centers[0][1] - 0.035),
            Vec2(centers[0][0] + 0.035, centers[0][1] + 0.035)
        ]),
                                landmarks_to_get=[]), None, ObjectClass.CUP,
        Color.GREEN)

    obj2 = Landmark(
        'blue_cup',
        RectangleRepresentation(rect=BoundingBox([
            Vec2(centers[1][0] - 0.035, centers[1][1] - 0.035),
            Vec2(centers[1][0] + 0.035, centers[1][1] + 0.035)
        ]),
                                landmarks_to_get=[]), None, ObjectClass.CUP,
        Color.BLUE)

    obj3 = Landmark(
        'pink_cup',
        RectangleRepresentation(rect=BoundingBox([
            Vec2(centers[2][0] - 0.035, centers[2][1] - 0.035),
            Vec2(centers[2][0] + 0.035, centers[2][1] + 0.035)
        ]),
                                landmarks_to_get=[]), None, ObjectClass.CUP,
        Color.PINK)

    obj4 = Landmark(
        'purple_prism',
        RectangleRepresentation(rect=BoundingBox([
            Vec2(centers[3][0] - 0.035, centers[3][1] - 0.045),
            Vec2(centers[3][0] + 0.035, centers[3][1] + 0.045)
        ]),
                                landmarks_to_get=[]), None, ObjectClass.PRISM,
        Color.PURPLE)

    obj5 = Landmark(
        'orange_prism',
        RectangleRepresentation(rect=BoundingBox([
            Vec2(centers[4][0] - 0.035, centers[4][1] - 0.045),
            Vec2(centers[4][0] + 0.035, centers[4][1] + 0.045)
        ]),
                                landmarks_to_get=[]), None, ObjectClass.PRISM,
        Color.ORANGE)

    # t_rep = table.to_dict()
    scene.add_landmark(table)
    # scene.add_landmark(serialize.landmark_from_dict(t_rep))

    for obj in (obj1, obj2, obj3, obj4, obj5):
        # o_rep = obj.to_dict()
        obj.representation.alt_representations = []
        scene.add_landmark(obj)
        # scene.add_landmark(serialize.landmark_from_dict(o_rep))

    return scene, speaker