Ejemplo n.º 1
0
ItemToRoom = np.array(wanted['ItemToRoom'])
RoomList = wanted['RoomList']
SurfaceList = wanted['SurfaceList']
wantedClass = wanted['wantedClass']

for target_classname in wantedClass:   

    for env_id in range(7): # env_id ranges from 0 to 6   
    
        # start simulation (only once for each apartment)
        comm = UnityCommunication()
        comm.reset(env_id)
        #comm.setBathroomTexture(env_id)
        
        #============================ START PYTHON SCRIPT ===========================
        response, origraph = comm.environment_graph()
        origraph = deleteGraphByClassname(origraph, target_classname) 
        success, message = comm.expand_scene(origraph)
        #print(origraph)
        #exit()
        #loop through all nodes and check whether we have wanted
        DestIds, DestPrefabs, destRooms, destSurface = findAllPossibleDestNodes(target_classname, wantedClass, ItemToRoom, SurfaceToRoom, RoomList, SurfaceList, origraph) 
         
        #loop through missed classes
        #randomly sample prefab from it and add to the graph        
        for i, destid in enumerate(DestIds):
            
            newIDs = 1000 #fixed; dont change; always starts from 1000 and onwards
            comm.reset(env_id)
            response, origraph = comm.environment_graph()    
            #print(origraph)
Ejemplo n.º 2
0
    else:
        os.mkdir(writedir)

    writedirjason = jasondirname + '/apartment_' + str(env_id) + '/'
    if os.path.exists(writedirjason):
        print('folder already exists')
    else:
        os.mkdir(writedirjason)

    # start simulation (only once for each apartment)
    comm = UnityCommunication()
    comm.reset(env_id)
    #comm.setBathroomTexture(env_id)
    #wantedgraph = pickle.load( open( graphdirname + '/apartment_' + str(env_id) + ".pkl", "rb" ) )
    #print(wantedgraph)
    res, origraph = comm.environment_graph()

    for node in origraph['nodes']:

        target_id = node['id']  #target object to recognize
        targetprefabname = node['prefab_name']

        #remove those objects not belong to these general cateogires
        if node['class_name'] not in wantedClass:
            continue

        print('Processing prefab id: ' + str(target_id))
        targetroomname = find_rooms(origraph, node)
        targetroombbox = find_nodes_byclassname(
            origraph, targetroomname)[0]['bounding_box']
        avgtargetsize = np.mean(node['bounding_box']['size'])
Ejemplo n.º 3
0
        _ = comm.camera_image(cameras_select, mode='normal', image_height=480,  image_width=640)
        ok, imgs = comm.camera_image(cameras_select, mode='normal', image_height=480,  image_width=640)
        images.append(imgs)

    return messages_expand, images


comm = UnityCommunication()

print('Inferring preconditions...')
preconds = add_preconds.get_preconds_script(script).printCondsJSON()
print(preconds)

print('Loading graph')
comm.reset(0)
_, graph_input = comm.environment_graph()
print('Executing script')
print(script)
info = check_programs.check_script(
        script, preconds, graph_path=None, inp_graph_dict=graph_input)

message, final_state, graph_state_list, graph_dict, id_mapping, info, helper, modif_script = info
success = (message == 'Script is executable')

if success:
    print('Generating snapshots')
    messages, images = obtain_snapshots(graph_state_list, graph_input, comm)
    grid_img = build_grid_images(images)
    cv2.imwrite('snapshot_test.png', grid_img)
    print('Snapshot saved in demo/snapshot_test.png')