Ejemplo n.º 1
0
def run(dataset_dir):

    # determine the expected location of necessary files from
    # within the dataset
    timefile = dataset_filepaths.get_timesync_xml(dataset_dir)
    conffile = dataset_filepaths.get_hardware_config_xml(dataset_dir)

    # read the xml configuration file
    conf = backpackconfig.Configuration(conffile, True, dataset_dir)

    # iterate through the available URG scanners
    urgSensors = conf.find_sensors_by_type(URG_TYPE)
    for urg in urgSensors:

        # get the output dat file for this sensor
        datfile = os.path.abspath(os.path.join(dataset_dir, \
                conf.find_sensor_prop(urg, URG_DAT_XPATH, URG_TYPE)))

        # get the fss file that will be generated for this sensor
        fssfile = dataset_filepaths.get_fss_file(datfile)

        # prepare the command-line arguments for the filter_urg_scans code
        args = [FILTER_EXE, datfile, fssfile, timefile]

        # run the filter_urg_scans code
        ret = subprocess.call(args, executable=FILTER_EXE, \
            cwd=dataset_dir, stdout=None, stderr=None, \
            stdin=None, shell=False)
        if ret != 0:
            print "filter_urg_scans program returned error", ret
            return -1

    # success
    return 0
Ejemplo n.º 2
0
def run(datasetDir):

    # Read in the hardware config file
    configFile = dataset_filepaths.get_hardware_config_xml(datasetDir)
    conf = backpackconfig.Configuration(configFile, True, datasetDir)

    # Find all the active cameras in the file
    cameraList = conf.find_sensors_by_type("cameras")
    if len(cameraList) == 0 :
        print "No active cameras found in dataset " + datasetDir
        return 0;

    # get location of masks for any cameras
    MASK_DIR = dataset_filepaths.get_camera_masks_dir(datasetDir)

    # Then we loop over the cameraList generating the required things
    for cameraName in cameraList :

        print ""
        print "==== RECTIFYING : " + cameraName + " ===="

        # now we need to read find out what the input names should be 
        calibFile = conf.find_sensor_prop(cameraName, 
            "configFile/dalsa_fisheye_calibration_file", "cameras")
        calibFile = os.path.join(datasetDir, calibFile)
        metaDataFile = os.path.join(datasetDir, \
            conf.find_sensor_prop(cameraName, \
            "configFile/dalsa_metadata_outfile", "cameras"))
        metaDataFile = dataset_filepaths.get_color_metadata_file( \
            cameraName, metaDataFile)
        rToCommon = conf.find_sensor_prop(cameraName,
            "rToCommon", "cameras").split(",")
        tToCommon = conf.find_sensor_prop(cameraName,
            "tToCommon", "cameras").split(",")
        extrinStr =  " ".join((rToCommon + tToCommon))
        outputDirectory = conf.find_sensor_prop(cameraName, 
            "configFile/dalsa_output_directory", "cameras")
        outputDirectory = os.path.abspath(os.path.join( \
            datasetDir, outputDirectory, '..', 'rectified'))

        # Adjust the maskdir
        maskDir = os.path.join(MASK_DIR, cameraName)

        # VODO The camera serial number
        camSerial = conf.find_sensor_prop(cameraName, 
            "serialNum", "cameras")
        camSerial = re.sub("[^0-9]", "", camSerial)

        ### UP CAMERA
        print "---Up Images"

        # Make vcam specific inputs
        outDir = os.path.join(outputDirectory, 'up')
        K = " ".join([str(max(IMAGESIZE)/FUP), "0", str(IMAGESIZE[1]/2), 
                      "0", str(max(IMAGESIZE)/FUP), str(IMAGESIZE[0]/2), 
                      "0","0","1"])
        rotation = "90 0 0"
        maskfile = os.path.join(maskDir, "up.jpg")
        serial = camSerial + "0"

        # Run the command
        command = [RECTIFY_EXE,
            "-ic", calibFile,
            "-id", datasetDir,
            "-iv", maskfile,
            "-ie", extrinStr,
            "-ik", K,
            "-im",metaDataFile,
            "-ir",rotation,
            "-is",str(IMAGESIZE[0]) + " " + str(IMAGESIZE[1]),
            "-od",outDir,
            "-os",serial]
        command = " ".join(command)
        ret = os.system(command)
        if ret != 0 :
            print "Error Processing " + cameraName + " up images"
            return 2;

        ### LEVEL CAMERA
        print "---Level Images"

        # Make vcam specific inputs
        outDir = os.path.join(outputDirectory, 'level')
        K = " ".join([str(max(IMAGESIZE)/FLEVEL), "0", str(IMAGESIZE[1]/2), 
                      "0", str(max(IMAGESIZE)/FLEVEL), str(IMAGESIZE[0]/2), 
                      "0","0","1"])
        rotation = "0 0 0"
        maskfile = os.path.join(maskDir, "level.jpg")
        serial = camSerial + "1"

        # Run the command
        command = [RECTIFY_EXE,
            "-ic", calibFile,
            "-id", datasetDir,
            "-iv", maskfile,
            "-ie", extrinStr,
            "-ik", K,
            "-im",metaDataFile,
            "-ir",rotation,
            "-is",str(IMAGESIZE[0]) + " " + str(IMAGESIZE[1]),
            "-od",outDir,
            "-os",serial]
        command = " ".join(command)
        ret = os.system(command)
        if ret != 0 :
            print "Error Processing " + cameraName + " level images"
            return 2;

        ### DOWN CAMERA
        print "---Down Images"

        # Make vcam specific inputs
        outDir = os.path.join(outputDirectory, 'down')
        K = " ".join([str(max(IMAGESIZE)/FDOWN), "0", str(IMAGESIZE[1]/2), 
                      "0", str(max(IMAGESIZE)/FDOWN), str(IMAGESIZE[0]/2), 
                      "0","0","1"])
        rotation = "-90 0 0"
        maskfile = os.path.join(maskDir, "down.jpg")
        serial = camSerial + "2"

        # Run the command
        command = [RECTIFY_EXE,
            "-ic", calibFile,
            "-id", datasetDir,
            "-iv", maskfile,
            "-ie", extrinStr,
            "-ik", K,
            "-im",metaDataFile,
            "-ir",rotation,
            "-is",str(IMAGESIZE[0]) + " " + str(IMAGESIZE[1]),
            "-od",outDir,
            "-os",serial]
        command = " ".join(command)
        ret = os.system(command)
        if ret != 0 :
            print "Error Processing " + cameraName + " down images"
            return 2;

    return 0;
Ejemplo n.º 3
0
def main() :
	
	# Parse the args from the command line
	args = handle_args()

	# Ensure that the given input files actually exist
	check_files_exist(args)

	# Read in the hardware config file so that we have access to the list of 
	# active sensors that were used in this dataset
	conf = backpackconfig.Configuration( \
		os.path.join(args.dataset_directory[0],CONFIGFILE_PATH), \
		True, \
		args.dataset_directory[0])
	args.scanner_list = collect_scanners(args.scanner_list, conf)

	# if there are any time-of-flight (or any depth) cameras present
	# then we should include them in the geometry
	tof_list          = collect_tof(conf)
	all_scanners = args.scanner_list + tof_list

	# Resolve the camera names that will be used in the colorizing the point 
	# cloud
	args.camera_list = collect_cameras(args.color_by, args.camera_list, conf)

	# Ensure that the output folder exists
	args.output_directory = create_output_folder(args)

	# Create common filenames
	timeFile = os.path.join(args.dataset_directory[0], TIMEFILE_PATH)
	configFile = os.path.join(args.dataset_directory[0], CONFIGFILE_PATH)
	pathFileBase = os.path.splitext(os.path.basename(args.path_file[0]))[0]

	# Handle the units
	args.units = handle_units(args.units[0])

	# Lastly run the executable for each scanner
	for scanner in all_scanners :

		print ""
		print "##### Generating Pointcloud for " + scanner + ". Colored by " \
			+ args.color_by + ". #####"
		print ""

		# Here is where the input arguments will be created
		cargs = [POINTCLOUD_EXE]

		# Tack on the time flag
		cargs.append('-t')
		cargs.append(timeFile)

		# Tack on the hardware config file
		cargs.append('-c')
		cargs.append(configFile)

		# Tack on the path
		cargs.append('-p')
		cargs.append(args.path_file[0])

		# give the geometry scanner info
		if scanner in args.scanner_list:

			# Tack on the laser scanner info
			scannerDataFile = conf.find_sensor_prop(scanner, \
				URG_DAT_XPATH, \
				URG_TYPE)
			scannerDataFile = os.path.join(args.dataset_directory[0], \
				scannerDataFile)
			cargs.append('-l')
			cargs.append(scanner)
			cargs.append(scannerDataFile)

		elif scanner in tof_list:

			# this is a tof sensor, which should have
			# a .fss file
			tofDatFile = conf.find_sensor_prop(scanner, \
				TOF_DAT_XPATH, \
				TOF_TYPE)
			tofFssFile = os.path.join( \
				args.dataset_directory[0], \
				dataset_filepaths.get_fss_file( \
				tofDatFile))
			cargs.append('--fss')
			cargs.append(tofFssFile)

		# Handle tacking on the colorization flag
		if args.color_by == 'cameras' :
			for camera in args.camera_list :

				# Give the information for the camera
				cmetadata = conf.find_sensor_prop(camera, \
					DALSA_METADATA_XPATH, \
					CAMERA_TYPE)
				cmetadata = os.path.dirname(cmetadata)
				cmetadata = os.path.join(args.dataset_directory[0], \
					cmetadata, \
					'color_'+camera+'_metadata.txt')
				calibFile = conf.find_sensor_prop(camera, \
					DALSA_CALIB_XPATH, \
					CAMERA_TYPE)
				calibFile = os.path.join(args.dataset_directory[0], \
					calibFile)
				imgDir = conf.find_sensor_prop(camera, \
					DALSA_OUTPUTDIR_XPATH, \
					CAMERA_TYPE)
				imgDir = os.path.normpath(os.path.join( \
					args.dataset_directory[0], imgDir, '..', 'color'))
				cargs.append('-f')
				cargs.append(cmetadata)
				cargs.append(calibFile)
				cargs.append(imgDir)

				#Check if a mask exists and if so register it for the camera
				maskFile = conf.find_sensor_prop(camera, \
					DALSA_MASKFILE_XPATH, \
					CAMERA_TYPE)
				if maskFile != None :
					maskFile = os.path.join(args.dataset_directory[0], \
						maskFile)
					cargs.append('-m')
					cargs.append(camera)
					cargs.append(maskFile)

		elif args.color_by == 'ir_cameras' :
			for camera in args.camera_list :

				# Give the information for the camera
				cmetadata = conf.find_sensor_prop(camera, \
					FLIR_METADATA_XPATH, \
					FLIR_TYPE)
				cmetadata = os.path.dirname(cmetadata)
				cmetadata = os.path.join(args.dataset_directory[0], \
					cmetadata, \
					'normalized_'+camera+'_metadata.txt')
				calibFile = conf.find_sensor_prop(camera, \
					FLIR_CALIB_XPATH, \
					FLIR_TYPE)
				calibFile = os.path.join(args.dataset_directory[0], \
					calibFile)
				imgDir = conf.find_sensor_prop(camera, \
					FLIR_OUTPUTDIR_XPATH, \
					FLIR_TYPE)
				imgDir = os.path.normpath(os.path.join( \
					args.dataset_directory[0], imgDir, '..', 'normalized'))
				cargs.append('-q')
				cargs.append(cmetadata)
				cargs.append(calibFile)
				cargs.append(imgDir)
				
		elif args.color_by == 'time' :
			cargs.append('--color_by_time')
		elif args.color_by == 'height' :
			cargs.append('--color_by_height')

		# Tack on the units flag
		cargs.append('-u')
		cargs.append(str(args.units))

		# Tack on the range limit flag
		if args.range_limit != None :
			cargs.append('-r')
			cargs.append(str(args.range_limit[0]))

		# Tack on the time buffer settings
		if not args.disable_time_buffer :
			cargs.append('--time_buffer')
			cargs.append(str(args.time_buffer[0]))
			cargs.append(str(args.time_buffer[1]))

		# if we are removing uncolored points tack them on
		if not args.keep_noncolored_points :
			cargs.append('--remove_noncolored_points')
		else :
			cargs.append('--default_color')
			cargs.append(str(args.default_color[0]))
			cargs.append(str(args.default_color[1]))
			cargs.append(str(args.default_color[2]))

		# Make the output file
		outFileName = os.path.join(args.output_directory,
			pathFileBase + "_" + scanner + "." + args.output_filetype)
		cargs.append("-o")
		cargs.append(outFileName)
		
		# Run the pointcloud code
		ret = os.system(" ".join(cargs))
		if ret != 0 :
			exit(1)
Ejemplo n.º 4
0
def run(settings):

    # The first thing we need to do is import the
    # backpack configuration file
    # so that we can deduce the locations of all the files names
    confFile = path.join(settings['datasetDir'], "config",
                         "backpack_config.xml")
    conf = backpackconfig.Configuration(confFile, True, \
                settings['datasetDir'])

    # Create the image maps dir
    imagemapdir = path.join(settings['datasetDir'], 'imagemaps')

    # Then we need to get a list of all active cameras for this dataset
    cameras = conf.find_sensors_by_type("cameras")
    code_args = []

    for camera in cameras:
        # We need to create first the camera pose file
        poseFiles = glob.glob(path.join(settings['datasetDir'], \
            'localization',settings['datasetName'], \
            'cameraposes',camera+"_poses.txt"))
        if (len(poseFiles) == 0):
            print ("No camera pose file for " \
                 + camera + " found in " \
                 + path.join(settings['datasetDir'], \
                    'localization', \
                    settings['datasetName'], \
                    'cameraposes'))
            return 1
        poseFile = poseFiles[0]

        # Then we need to create the names of the depth
        # and normal files
        depthfile = path.join(imagemapdir, camera, "depthmaps",
                              camera + "_imagelog.txt")
        normalfile = path.join(imagemapdir, camera, "normalmaps",
                               camera + "_imagelog.txt")

        code_args.append(tuple([poseFile, depthfile, normalfile]))

    # Create the binary file name
    binFile = path.join(settings['binaryDir'], 'create_image_mapping')

    # Create the output file name
    imapfile = path.join(imagemapdir, "imagemap.imap")
    keyfile = path.join(imagemapdir, "imgids.txt")

    args = [
        binFile, "-dir", settings['datasetDir'], "-o", imapfile, keyfile, "-r",
        str(settings['resolution'])
    ]
    for argset in code_args:
        args += ["-i"]
        args += argset[:]

    # Run the code
    ret = system(" ".join(args))
    if ret != 0:
        print "Image mapping returned error : " + str(ret)

    # Return success
    return ret
Ejemplo n.º 5
0
def run(dataset_dir, pathfile, debug=False):

    # ensure abspath for input files
    dataset_dir = os.path.abspath(dataset_dir)
    pathfile = os.path.abspath(pathfile)

    # check that executable exists
    if not os.path.exists(SCANORAMA_EXE):
        print "Error!  Could not find pointcloud", \
            "generation executable:", \
            SCANORAMA_EXE
        return None

    # verify that output directory exists
    scanoramadir = dataset_filepaths.get_scanorama_dir(dataset_dir)
    if not os.path.exists(scanoramadir):
        os.makedirs(scanoramadir)

    # get necessary files for this dataset
    scanoprefix = dataset_filepaths.get_scanorama_ptx_prefix(dataset_dir)
    metafile = dataset_filepaths.get_scanorama_metadata_file(dataset_dir)
    modelfile = dataset_filepaths.get_full_mesh_file(dataset_dir)
    config_xml = dataset_filepaths.get_hardware_config_xml(dataset_dir)
    conf = backpackconfig.Configuration(config_xml, True, dataset_dir)

    # Prepare arguments for program
    args = [SCANORAMA_EXE, '-c', config_xml, '-s', SETTINGS_XML, \
                '-m', modelfile, \
                '-p', pathfile, \
                '-o', scanoprefix, \
                '--meta', metafile]
    if debug:
        args = ['gdb', '--args'] + args

    #--------------------------------------------
    # find all active FISHEYE cameras in the file
    #--------------------------------------------
    cam_metas = []
    cam_calibs = []
    cam_dirs = []
    cameraList = conf.find_sensors_by_type("cameras")
    for cameraName in cameraList:

        # check if this sensor is enabled
        e = conf.find_sensor_prop(cameraName, 'enable', 'cameras')
        if e == '0':
            continue

    # prepare the command-line arguments for this camera
        metafile = os.path.join(dataset_dir, \
                conf.find_sensor_prop(cameraName, \
                    'configFile/dalsa_metadata_outfile', 'cameras'))
        metafile = dataset_filepaths.get_color_metadata_file( \
                cameraName, metafile)
        calibfile = os.path.join(dataset_dir, \
                conf.find_sensor_prop(cameraName, \
                    'configFile/dalsa_fisheye_calibration_file', 'cameras'))
        imgdir = os.path.join(dataset_dir, \
                dataset_filepaths.get_color_image_dir( \
                    conf.find_sensor_prop(cameraName, \
                        'configFile/dalsa_output_directory', 'cameras')))

        # add to arguments lists
        cam_metas.append(metafile)
        cam_calibs.append(calibfile)
        cam_dirs.append(imgdir)

    # add FISHEYE camera information
    for ci in range(len(cam_metas)):
        args += ['-f', cam_metas[ci], \
                cam_calibs[ci], cam_dirs[ci]]

    #-----------------------------------------
    # find all active FLIR cameras in the file
    #-----------------------------------------
    cam_metas = []
    cam_calibs = []
    cam_dirs = []
    cameraList = conf.find_sensors_by_type("flirs")
    for cameraName in cameraList:

        # check if this sensor is enabled
        e = conf.find_sensor_prop(cameraName, 'enable', 'flirs')
        if e == '0':
            continue

    # prepare the command-line arguments for this camera
        metafile = os.path.join(dataset_dir, \
                conf.find_sensor_prop(cameraName, \
                    'configFile/flir_metadata_outfile', 'flirs'))
        metafile = dataset_filepaths.get_ir_normalized_metadata_file( \
                cameraName, metafile)
        calibfile = os.path.join(dataset_dir, \
                conf.find_sensor_prop(cameraName, \
                    'configFile/flir_rectilinear_calibration_file', \
                    'flirs'))
        imgdir = os.path.join(dataset_dir, \
                dataset_filepaths.get_ir_normalized_image_dir( \
                    conf.find_sensor_prop(cameraName, \
                        'configFile/flir_output_directory', 'flirs')))

        # add to arguments lists
        cam_metas.append(metafile)
        cam_calibs.append(calibfile)
        cam_dirs.append(imgdir)

    # add RECTILINEAR camera information
    for ci in range(len(cam_metas)):
        args += ['-r', cam_metas[ci], \
                cam_calibs[ci], cam_dirs[ci]]

    #----------------------------------
    # run pointcloud generation program
    #----------------------------------
    exe_to_run = SCANORAMA_EXE
    if debug:
        exe_to_run = 'gdb'
    ret = subprocess.call(args, executable=exe_to_run, \
            cwd=dataset_dir, stdout=None, stderr=None, \
            stdin=None, shell=False)
    if ret != 0:
        print "Error! Scanorama generation program", \
                "returned",ret
        return ret

    # success
    return 0
Ejemplo n.º 6
0
def run(datasetDir, datasetName):

    # The first thing we need to do is import the backpack i
    # configuration file
    # so that we can deduce the locations of all the files names
    configFile = dataset_filepaths.get_hardware_config_xml(datasetDir)
    conf = backpackconfig.Configuration(configFile, True, datasetDir)
    meshfile = dataset_filepaths.get_full_mesh_file(datasetDir)

    # Then we need to get a list of all active cameras for this dataset
    cameras = conf.find_sensors_by_type("cameras")
    if len(cameraList) == 0:
        print "No active cameras found in dataset " + datasetDir
        return 0

    # For each camera create the triplet of inputs
    code_args = []
    for camera in cameras:

        # get the folder for this camera in the dataset
        datadir = conf.find_sensor_prop(camera,
                                        "configFile/dalsa_output_directory",
                                        "cameras")
        imageDir = path.normpath(path.join(datasetDir, datadir, '..'))

        # Then find the mcd file for this camera
        mcdFiles = glob.glob(path.join(imageDir, \
            'rectified', 'level', '*.mcd'))
        if (len(mcdFiles) == 0):
            print "No .mcd files found in " \
                + path.join(imageDir,'rectified', 'level')
            return 1
        if (len(mcdFiles) > 1):
            print(
                str(len(mcdFiles)) + " .mcd files found in " +
                path.join(imageDir, 'rectified', 'level'))
            return 2

        # Store the final mcd file
        mcdFile = mcdFiles[0]

        # Then locate the pose file for the camera
        poseFiles = glob.glob(
            path.join(datasetDir, 'localization', datasetName, 'cameraposes',
                      camera + "_poses.txt"))
        if (len(poseFiles) == 0):
            print(
                "No camera pose file for " + camera + " found in " +
                path.join(settings['datasetDir'], 'localization', datasetName,
                          'cameraposes'))
            return 1

        # Store the pose file
        poseFile = poseFiles[0]

        # Create the output directory name
        outDir = path.join(datasetDir, 'imagemaps', camera)

        # Store as a tuple
        code_args.append(tuple([mcdFile, poseFile, outDir, camera]))

    # Create the arguments for the C++ code
    args = [
        MESH2IMAGE_EXE, "-dir", datasetDir, "-model", meshfile, "-depth", '12'
    ]
    for argset in code_args:
        args += ["-i"]
        args += argset[:]

    # Run the code
    ret = system(" ".join(args))
    if ret != 0:
        print "Depth mapping returned error : " + str(ret)

    # Return success
    return ret
Ejemplo n.º 7
0
def pointcloud_gen(dataset_dir, madfile):

	# the following constants are used to interface with the system
	# hardware configuration
	CAMERA_TYPE            = 'cameras'
	CAMERA_METAFILE_XPATH  = 'configFile/dalsa_metadata_outfile'
	CAMERA_RECTCALIB_XPATH = 'configFile/flir_rectilinear_calibration_file'
	CAMERA_IMAGEDIR_XPATH  = 'configFile/dalsa_output_directory'
	CAMERA_WHITELIST       = ['tango_color']

	# get the necessary file paths from the dataset
	conffile = dataset_filepaths.get_hardware_config_xml(dataset_dir)
	timefile = dataset_filepaths.get_timesync_xml(dataset_dir)
	fssfiles = dataset_filepaths.get_all_fss_files(dataset_dir)
	xyzfile  = os.path.join( \
			dataset_filepaths.get_colored_pc_dir(dataset_dir), \
			dataset_filepaths.get_name_from_madfile(madfile) \
				+ '_tango.xyz')

	# check if the appropriate camera(s) is/are defined
	conf = backpackconfig.Configuration(conffile, True, dataset_dir)
	cameraSensors = conf.find_sensors_by_type(CAMERA_TYPE)

	# prepare the command-line arguments for this executable
	args = [POINTCLOUD_EXE, \
			'-t', timefile, \
			'-c', conffile, \
			'-p', madfile, \
			'-u', '1000', \
			]

	# add all available sensors
	for f in fssfiles:
		args += ['--fss', f]

	# add all available cameras that are in the whitelist
	colorbycamera = False
	for c in cameraSensors:
		if c in CAMERA_WHITELIST:
			# we should use this camera for color
			colorbycamera = True
			
			# get the argument files for this camera
			cmetadata = dataset_filepaths.get_color_metadata_file( \
					c, \
					os.path.join(dataset_dir, \
					conf.find_sensor_prop(c, \
					CAMERA_METAFILE_XPATH, \
					CAMERA_TYPE)))
			crectcalib = os.path.join(dataset_dir, \
					conf.find_sensor_prop(c, \
					CAMERA_RECTCALIB_XPATH, \
					CAMERA_TYPE))
			cimagedir = os.path.join(dataset_dir, \
					conf.find_sensor_prop(c, \
					CAMERA_IMAGEDIR_XPATH, \
					CAMERA_TYPE))

			# add to the command-line args
			args += ['-q', cmetadata, crectcalib, cimagedir]
	
	# prepare output file
	outdir = os.path.dirname(xyzfile)
	if not os.path.exists(outdir):
		os.makedirs(outdir)
	args += ['-o', xyzfile]

	# call the pointcloud executable
	ret = subprocess.call(args, executable=POINTCLOUD_EXE, \
			cwd=dataset_dir, stdout=None, stderr=None, \
			stdin=None, shell=False)
	if ret != 0:
		print "Pointcloud generation code returned error",ret
		return None

	# return the xyzfile as success
	return xyzfile