Пример #1
0
def setupCorlDirector(robotSystem,
                      openniDepthPointCloud,
                      setCameraToWorld,
                      logFolder="logs/moving-camera",
                      globalsDict=None,
                      extraInputs=None):
    """
    Setups the necessary callbacks for visualizing Corl data in director

    :param logFolder: The name of folder relative to Corl data dir
    :return:
    """

    filenames = CorlUtils.getFilenames(logFolder)

    # setup camera update callback. Sets pose of camera depending on time in lcmlog
    CorlUtils.initCameraUpdateCallback(openniDepthPointCloud,
                                       setCameraToWorld,
                                       filename=filenames['cameraPoses'])

    CorlUtils.loadObjectMeshes(robotSystem.affordanceManager,
                               filenames['registrationResult'])
    CorlUtils.loadElasticFustionReconstruction(filenames['reconstruction'])

    imageCapture = ImageCapture(extraInputs['imageManager'],
                                filenames['images'])

    # add necessary classes to globalsDict
    globalsDict['imageCapture'] = imageCapture

    globalRegistration = registration.GlobalRegistration(globalsDict['view'])
    globalsDict['globalRegistration'] = globalRegistration
Пример #2
0
def main():
    #TODO: Parse the list of arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-indir', required=True, type=str)
    parser.add_argument('-outdir', required=True, type=str)
    args = parser.parse_args()

    path2InDir = args.indir
    path2OutDir = args.outdir

    if not os.path.exists(path2OutDir):
        os.mkdir(path2OutDir)
    print "Preprocessing ..."
    confPreprocess = {}
    confPreprocess['remove stopword'] = False
    confPreprocess['remove punct'] = True
    nbSkipFile = 0
    lstErrors = []
    lstFiles = getFilenames(path2InDir)
    progress_bar = ProgressBar(len(lstFiles))
    for filename in lstFiles:
        fullPath = os.path.join(path2InDir, filename)
        try:
            content, highlights = getContentAndHighlight(fullPath)
        except ValueError:
            nbSkipFile += 1
            continue
        content, highlights = preprocess(content, highlights, confPreprocess)
        saveContentandHighlights(content, highlights, os.path.join(path2OutDir, filename + '.pre'))
        progress_bar.Increment()
    print 'NOTE: We skip %d file because length of content or highlights is zero.' % nbSkipFile
    print 'DONE!'
Пример #3
0
def playRandom():
    global lastPlayFile
    path = 'data/random/'
    filenames = utils.getFilenames(path)
    playFile = path + random.choice(filenames)
    lastPlayFile = playFile
    playSoundFile(playFile)
Пример #4
0
 def loadDataSourceIds(self, dataSourceType):
     '''
     Given a data source, load all of the ids for that data source.
     This should only be called if the data source is completely uninitialized.
     If it's a single data source, then load the entire data source.
     Otherwise, just get the list of ids from the filenames in the directory.
     '''
     if self.isSingle(dataSourceType):
         self.loadSingleDataSource(dataSourceType)
     else:
         directory = self.getDataSourceDirectory(dataSourceType)
         self.data[dataSourceType] = \
                 {utils.getBaseFilename(filename): None for filename in utils.getFilenames(directory, ext="json")}
Пример #5
0
def setupCorlDirector(affordanceManager,
                      openniDepthPointCloud,
                      logFolder="logs/moving-camera",
                      globalsDict=None):
    """
    Setups the necessary callbacks for visualizing Corl data in director

    :param logFolder: The name of folder relative to Corl data dir
    :return:
    """

    filenames = CorlUtils.getFilenames(logFolder)

    # setup camera update callback. Sets pose of camera depending on time in lcmlog
    # if os.path.isfile(filenames['cameraPoses']):
    #     CorlUtils.initCameraUpdateCallback(openniDepthPointCloud, setCameraToWorld, filename=filenames['cameraPoses'])

    # check if we have already figured out a transform for this or not
    firstFrameToWorldTransform = CorlUtils.getFirstFrameToWorldTransform(
        filenames['transforms'])

    # only load these files in info.yaml exists
    if os.path.isfile(filenames['registrationResult']):
        CorlUtils.loadObjectMeshes(affordanceManager,
                                   filenames['registrationResult'],
                                   firstFrameToWorldTransform)

        imageCapture = ImageCapture(globalsDict['imageManager'],
                                    filenames['images'])
        globalsDict['imageCapture'] = imageCapture

    # firstFrameToWorldTransform = vtk.vtkTransform()
    CorlUtils.loadElasticFusionReconstruction(
        filenames['reconstruction'], transform=firstFrameToWorldTransform)

    globalRegistration = registration.GlobalRegistration(
        globalsDict['view'],
        globalsDict['cameraView'],
        globalsDict['measurementPanel'],
        globalsDict['affordanceManager'],
        logFolder=logFolder,
        firstFrameToWorldTransform=firstFrameToWorldTransform)
    globalsDict['globalRegistration'] = globalRegistration
    globalsDict['gr'] = globalRegistration  # hack for easy access
Пример #6
0
def main():
    # TODO: Parse the list of arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('-indir', required=True, type=str)
    parser.add_argument('-outdir', required=True, type=str)
    args = parser.parse_args()

    path2InDir = args.indir
    path2OutDir = args.outdir

    path2TrainDir = os.path.join(path2OutDir, 'training')
    path2DevDir = os.path.join(path2OutDir, 'dev')
    path2TestDir = os.path.join(path2OutDir, 'test')

    if not os.path.exists(path2OutDir):
        os.mkdir(path2OutDir)
    if not os.path.exists(path2TrainDir):
        os.mkdir(path2TrainDir)
    if not os.path.exists(path2DevDir):
        os.mkdir(path2DevDir)
    if not os.path.exists(path2TestDir):
        os.mkdir(path2TestDir)

    lstFiles = getFilenames(path2InDir)

    shuffle(lstFiles)

    trainingRatio = 0.9
    devRatio = 0.05

    nbDoc = len(lstFiles)

    nbInsTrain = int(round(nbDoc * trainingRatio, 0))
    if nbInsTrain < nbDoc * trainingRatio:
        nbInsTrain += 1

    nbInsDev = int(round(nbDoc * devRatio, 0))
    if nbInsDev < nbDoc * devRatio:
        nbInsDev += 1

    lstFilesTrain = lstFiles[:nbInsTrain]
    lstFilesDev = lstFiles[nbInsTrain: nbInsTrain + nbInsDev]
    lstFilesTest = lstFiles[nbInsTrain+nbInsDev:]

    assert len(lstFilesTrain) + len(lstFilesDev) + len(lstFilesTest) == nbDoc, \
        "Total documents in training, dev, test set are not matched with the original dataset!"

    print "Copy files in to Training Directory..."
    progress_bar = ProgressBar(len(lstFilesTrain))
    for filename in lstFilesTrain:
        copyfile(os.path.join(path2InDir, filename), os.path.join(path2TrainDir, filename))
        progress_bar.Increment()

    print "Copy files in to Dev Directory..."
    progress_bar = ProgressBar(len(lstFilesDev))
    for filename in lstFilesDev:
        copyfile(os.path.join(path2InDir, filename), os.path.join(path2DevDir, filename))
        progress_bar.Increment()

    print "Copy files in to Test Directory..."
    progress_bar = ProgressBar(len(lstFilesTest))
    for filename in lstFilesTest:
        copyfile(os.path.join(path2InDir, filename), os.path.join(path2TestDir, filename))
        progress_bar.Increment()
Пример #7
0
 def makeDefault(globalsDict, logFolder="logs/moving-camera"):
     pathDict = cutils.getFilenames("logs/moving-camera")
     rti = RenderTrainingImages(globalsDict, pathDict)
     globalsDict['renderTrainingImages'] = rti
     return rti
Пример #8
0
def captureImages(logFolder):
    corlPaths = CorlUtil.getFilenames(logFolder)
    ImageCapture.readFromLogFile(corlPaths['lcmlog'], corlPaths['images'])
Пример #9
0
def getRandomSounds():
    return utils.getFilenames('data/random/')