Exemple #1
0
def matrix_cluster(boxes):
    sizes = np.array([[b,b.x_size()] for b in boxes])
    normal = reject_outliers(sizes)[:,0]
    x_clusters = cluster(list(normal))
    y_clusters = cluster(list(normal),x=False)
    numbers = []
    for c in x_clusters:
        new_clust = []
        for y_c in y_clusters:
            new_clust.append(Cluster(list(set(tuple(c.boxes)) & set(tuple(y_c.boxes)))))
        numbers.append(new_clust)
        
    root = tk.Tk()
    vis = Visualizer(root,1000,600)
    #return the clusters of boxes
    for i in numbers:
        for c in i:
            for b in c.boxes:
                box = Box2D((b.x1,b.y1),size=b.size_t())
                vis.add_drawable(box)
            box = Box2D((c.bounding_box().x1,c.bounding_box().y1),
                        size=c.bounding_box().size_t())
            box.fill = None
            box.outline = "green"
            vis.add_drawable(box)
    #vis.run()
    #root.mainloop()

    return numbers
Exemple #2
0
def display_boxes(boxes):
    root = tk.Tk()
    vis = Visualizer(root, 1000, 600)

    for b in boxes:
        box = Box2D((b.x1, b.y1), size=b.size_t())
        vis.add_drawable(box)

    vis.run()
    root.mainloop()
Exemple #3
0
def cluster(boxes,x=True):
    clusters = []
    while boxes:
        cluster = Cluster()
        b = boxes.pop()
        cluster.boxes.append(b)

        changed = True
        while changed:
            changed = False
            for other in list(boxes):
                if x:
                    if cluster.bounding_box().overlaps_x(other):
                        changed = True
                        cluster.boxes.append(other)
                        boxes.remove(other)
                else:
                    if cluster.bounding_box().overlaps_y(other):
                        changed = True
                        cluster.boxes.append(other)
                        boxes.remove(other)
        #boxes = tmp

        #if len(cluster.boxes)<5 and cluster.bounding_box().size()>10:
        clusters.append(cluster)

    root = tk.Tk()
    vis = Visualizer(root,1000,600)

    if x:
        clusters = sorted(clusters,key = lambda c:c.mid_x())
    else:
        clusters = sorted(clusters,key = lambda c:c.mid_y())

    #return the clusters of boxes
    for c in clusters:
        for b in c.boxes:
            box = Box2D((b.x1,b.y1),size=b.size_t())
            vis.add_drawable(box)
        box = Box2D((c.bounding_box().x1,c.bounding_box().y1),
                    size=c.bounding_box().size_t())
        box.fill = None
        box.outline = "green"
        vis.add_drawable(box)
    #vis.run()
    #root.mainloop()

    return clusters
Exemple #4
0
        for h in handle.neighbors():
            vs = h.face_vertices()
            vis.add_drawable(Polygon2D(vs,fill="blue"))
        """
    draw_skeleton()
    vis.draw()

    lock.release()

def click_callback(event):
    lock.acquire()

    v = Vertex(event.x,event.y)
    print v
    if dt.dag_locate(v):
        dt.insert_site(v)
        vis.clear()
        draw_faces()
        draw_skeleton()
        vis.draw()

    lock.release()

vis = Visualizer(root,800,600,key_callback=key_callback,mouse_callback=mouse_callback,click_callback=click_callback)

draw_faces()
draw_skeleton()

vis.run()
root.mainloop()
Exemple #5
0
    ]
    colors = ["red", "blue", "green", "yellow"]

    sizes = np.array([[b, b.y_size()] for b in boxes])
    abnormal = accept_outliers(sizes)[:, 0]
    normal = reject_outliers(sizes)[:, 0]

    first = -1
    num = 0
    for i in range(100):
        num = i + 1
        clusters, error = cluster_boxes(normal, num_clusters=i + 1)
        if first != -1 and error / (first - error) < 0.15:
            break
        first = error
    colors *= len(clusters) / len(colors)
    root = tk.Tk()
    vis = Visualizer(root, 1000, 600)

    for cluster, color in zip(clusters, colors):
        for b in cluster.boxes:
            box = Box2D((b.x1, b.y1), size=b.size_t())
            box.fill = color
            vis.add_drawable(box)
        box = Box2D((cluster.bounding_box().x1, cluster.bounding_box().y1), size=cluster.bounding_box().size_t())
        box.fill = None
        vis.add_drawable(box)

    vis.run()
    root.mainloop()
Exemple #6
0
root = tk.Tk()


def key_callback(event):
    def draw_callback():
        draw()
        vis.draw()
        root.update_idletasks()

    #path.benchmark(env,draw_callback=draw_callback,iterations=10)
    path.update(env)
    draw_callback()


vis = Visualizer(root, 800, 600, key_callback=key_callback)

b = structures.Box(np.array([250, 150]), np.array([150, 200]))
b2 = structures.Box(np.array([450, 250]), np.array([150, 200]))
env = structures.Environment()
env.add_polygon(b)
env.add_polygon(b2)

path = structures.Path()
path.generate_path()
path.perturb_path()
path.generate_path_normals()


def draw():
    vis.clear()
Exemple #7
0
        await goToCubes(robot, markersMap, robot_pose, cmap)
        # await goToCubes(robot, testMarkersMap, robot_pose, cmap)


class RobotThread(threading.Thread):
    """Thread to run cozmo code separate from main thread
	"""
    def __init__(self):
        threading.Thread.__init__(self, daemon=True)

    def run(self):
        # Please refrain from enabling use_viewer since it uses tk, which must be in main thread
        cozmo.run_program(run, use_3d_viewer=False, use_viewer=False)
        stopevent.set()


if __name__ == '__main__':
    # global cmap,
    global stopevent
    stopevent = threading.Event()

    robot_thread = RobotThread()
    robot_thread.start()

    visualizer = Visualizer(cmap)
    visualizer.start()
    stopevent.set()

    # robot = None
    # run(robot)