def process(self, parent): self.update_status(Stage.STATUS_RUNNING) if parent.label_map: labels = parent.label_map else: labels = label_map_to_dict( load_label_map_file( parent.config[self._name]['LABEL_MAP_LOCATION'])) tf.logging.set_verbosity(tf.logging.WARN) if parent.graph: graph = parent.graph else: graph = load_graph(parent.config[self._name]['GRAPH_LOCATION']) (boxes, scores, classes, num) = self.proceed_with_boxes(graph) w, h = parent.width, parent.height room = Room(_openings=[]) for i in range(int(num[0])): sy, sx, ey, ex = int(boxes[0][i][0] * h), \ int(boxes[0][i][1] * w), \ int(boxes[0][i][2] * h), \ int(boxes[0][i][3] * w) placement = Line(Point(sx, sy), Point(ex, ey)) ch = CHOICE[labels[int(classes[0][i])]] t = ch[1] cl = ch[0] room.openings.append(cl(placement, t=t)) self.desc = room self.update_status(Stage.STATUS_SUCCEEDED)
def addpoint(self, mongolink=None): if isinstance(self.points[0], int): self.loadpoints(mongolink) if 'instance' in self.points[0].owner: self.points[0].owner = '' if mongolink: mongolink.setDirty(self.points[0].suid) return self.points[0] else: temp = Point.getInstance(mongolink, False) temp.parent = self.suid temp.owner = '' self.points.append(temp) if mongolink: mongolink.setDirty(self.points[0].suid) return temp
def render_room(img, room, line_w=1, shift=Point(0, 0), scale=1, gray=False): def tc(c): if gray: return (c[0] + c[1] + c[2]) / 3 return c if room: if room.type == 'kitchen': wall = room.walls[0] p1 = wall.inner_part.point_1.mult(scale).add(shift).int_tuple() p2 = wall.inner_part.point_2.mult(scale).add(shift).int_tuple() point = (int(p1[0] + (p2[0] - p1[0]) / 2) - 30, int(p1[1] + (p2[1] - p1[1]) / 2)) cv2.putText(img, 'k', point, cv2.FONT_HERSHEY_SIMPLEX, 2, tc(COLOR_MAP['bearing_wall']), 3, cv2.LINE_AA) for wall in room.walls: p1 = wall.inner_part.point_1.mult(scale).add(shift).int_tuple() p2 = wall.inner_part.point_2.mult(scale).add(shift).int_tuple() cv2.line(img, p1, p2, tc(COLOR_MAP[wall.wall_type]), 2) for o in room.openings: for p in o.placement: p1 = p.point_1.mult(scale).add(shift).int_tuple() p2 = p.point_2.mult(scale).add(shift).int_tuple() if o._type == 'item': if o.item_type == 'test' or o.item_type == 'test2': continue cv2.rectangle(img, p1, p2, tc(COLOR_MAP[o.item_type]), line_w) else: cv2.line(img, p1, p2, tc(COLOR_MAP[o._type]), line_w) return img
def save_in_dxf(name, desc): z = 0 d = sdxf.Drawing() for room in desc: if room.type == 'kitchen': wall = room.walls[0] p1 = wall.inner_part.point_1 p2 = wall.inner_part.point_2 point = (int(p1.x + (p2.x - p1.x) / 2) - 30, int(p1.y + (p2.x - p1.y) / 2)) d.append( sdxf.Text(text='k', point=[point[0], -point[1], z], height=20)) for wall in room.walls: line = wall.inner_part d.append( sdxf.Line(points=[(line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z)])) for opening in room.openings: if opening._type == 'door': for line in opening.placement: d.append( sdxf.Line(points=[ (line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z) ], color=3)) continue if opening._type == 'window': for line in opening.placement: d.append( sdxf.Line(points=[ (line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z) ], color=4)) continue if opening._type == 'arch': for line in opening.placement: d.append( sdxf.Line(points=[ (line.point_1.x, -int(line.point_1.y), z), (line.point_2.x, -int(line.point_2.y), z) ], color=2)) continue if opening._type == 'item': rect = opening.placement[0] p1 = rect.point_1 p3 = rect.point_2 p2 = Point(p1.x, p3.y) p4 = Point(p3.x, p1.y) lines = [ Line(p1, p2), Line(p2, p3), Line(p3, p4), Line(p1, p4) ] for line in lines: d.append( sdxf.Line(points=[ (line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z) ], color=5)) continue if room.furniture: for furniture in room.furniture: rect = furniture.placement p1 = rect.point_1 p3 = rect.point_2 p2 = Point(p1.x, p3.y) p4 = Point(p3.x, p1.y) lines = [ Line(p1, p2), Line(p2, p3), Line(p3, p4), Line(p1, p4) ] for line in lines: d.append( sdxf.Line(points=[ (line.point_1.x, -line.point_1.y, z), (line.point_2.x, -line.point_2.y, z) ], color=6)) d.saveas(name)
def __init__(self, _placement=None, t=None): self.placement = [_placement] self.item_type = t if _placement: self.center = Point(_placement.point_1.x + abs(_placement.point_1.x - _placement.point_2.x), _placement.point_1.y + abs(_placement.point_1.y - _placement.point_2.y))