Esempio n. 1
0
def rects_intersection(rects, maxwidth, maxheight):
    if not rects:
        return
    intersection = cv.CreateImage((maxwidth,
                         maxheight),
                         cv.IPL_DEPTH_8U,1)
    cv.FillPoly(intersection, [rects[0]], im.color.blue)
    for r in rects:
        canvas = cv.CreateImage((maxwidth,
                         maxheight),
                         cv.IPL_DEPTH_8U,1)
        cv.FillPoly(canvas, [r], im.color.blue)
        cv.And(canvas, intersection, intersection)
    return im.find_contour(intersection)
Esempio n. 2
0
    def get_near_region_mask(self, blds):
        regions = [bd.near_region_poly for bd in blds]
        c = cg.rects_intersection(regions, self.label_img.width,
                                  self.label_img.height)
        # subtract buildings
        equ_class_region = cv.CreateImage(
            (self.label_img.width, self.label_img.height), cv.IPL_DEPTH_8U, 1)
        canvas = cv.CloneImage(self.label_img)
        cv.FillPoly(equ_class_region, [c], im.color.blue)
        cv.CmpS(canvas, 0, canvas, cv.CV_CMP_EQ)
        cv.And(equ_class_region, canvas, equ_class_region)

        # subtract near of near's neighbor
        near_of_near = set(self.buildings)
        for bd in blds:
            near_of_near = near_of_near.union(bd.near_set)
        near_of_near.difference_update(set(blds))
        near_regions = [bd.near_region_poly for bd in near_of_near]
        for reg, bd in zip(near_regions, near_of_near):
            if cg.has_intersection(equ_class_region, reg, self.label_img.width,
                                   self.label_img.height):
                cg.sub_intersection(equ_class_region, reg,
                                    self.label_img.width,
                                    self.label_img.height)
        # equ_class_region -= near of near via nearest
        for bd in near_of_near:
            eq_region = self.get_equivalent_region_via_nearest(bd)
            c = im.find_contour(eq_region)
            while c:
                if cg.has_intersection(equ_class_region, list(c),
                                       self.label_img.width,
                                       self.label_img.height):
                    cg.sub_intersection(equ_class_region, list(c),
                                        self.label_img.width,
                                        self.label_img.height)
                c = c.h_next()

        return equ_class_region
Esempio n. 3
0
def init_buildings(buildingIDs, label_img):
    bld_mask = cv.CreateImage((label_img.width, label_img.height),
                              cv.IPL_DEPTH_8U, 1)
    buildings = []
    for bid in buildingIDs:
        cv.CmpS(label_img, bid, bld_mask, cv.CV_CMP_EQ)
        buildings.append(Building(bid, im.find_contour(bld_mask)))

    for rb in buildings:
        for sb in buildings:
            if sb.bid == rb.bid:
                continue
            if rb.is_near_me(sb):
                rb.near_set.add(sb)
            if rb.is_north_me(sb):
                rb.north_set.add(sb)
            if rb.is_south_me(sb):
                rb.south_set.add(sb)
            if rb.is_east_me(sb):
                rb.east_set.add(sb)
            if rb.is_west_me(sb):
                rb.west_set.add(sb)

    return buildings
Esempio n. 4
0
 def draw_region(equ_class_region, color=im.color.red):
     c = im.find_contour(equ_class_region)
     while c:
         cv.FillPoly(self.show_img, [list(c)], color)
         c = c.h_next()