示例#1
0
def discover_7scenes(config, scenes_train, scenes_test, base_dir=None):
    base_dir = base_dir or pp(config.dir_datasets, '7scenes')

    scenes = [
        (subdir, pp(base_dir, subdir)) for subdir in sorted(
            next(os.walk(base_dir))[1])  # list of dir names in base_dir
    ]

    train_dsets = []
    test_dsets = []

    for scene_name, scene_path in scenes:
        #train_ids = load_split_file_7scenes(pp(scene_path, 'TrainSplit.txt'))
        #test_ids = load_split_file_7scenes(pp(scene_path, 'TestSplit.txt'))

        seq_dirs = next(os.walk(scene_path))[1]
        seq_ids = [
            int(RE_7SC_SEQ_DIR.match(dir_name).group(1))
            for dir_name in seq_dirs
        ]
        seq_ids.sort()
        seqs = [
            Dataset7Scenes(config, scene_name, seq_id) for seq_id in seq_ids
        ]

        if scene_name in scenes_train:
            train_dsets += seqs
        elif scene_name in scenes_test:
            test_dsets += seqs

    return dict(train=train_dsets, test=test_dsets)
示例#2
0
def build(platform, build_dir):
	dir_install = pp(dir_opencv_root, 'install', platform_dirs[platform])

	print('Task:', color.MAGENTA + 'build')
	print('- platform:', color.CYAN + platform)
	print('- build directory:', color.CYAN + build_dir)
	print('- install directory:', color.CYAN + dir_install)

	# create build dir if it does not exist
	os.makedirs(build_dir, exist_ok=True)

	# move to that directory as cmake likes to be executed in the build dir
	os.chdir(build_dir)

	print('Running ', color.GREEN + 'CMake')

	if platform == 'windows':
		print('To play video files, install ', color.CYAN + 'GStreamer', ' (and its development files)')
		print('and set env variable ', color.RED + 'GSTREAMER_DIR', ' to ', color.YELLOW + '(gstreamer_install_dir)/1.0/x86_64')
	
	print(color_background.GREEN + 80*' ')

	# run cmake
	cmd_cmake = [
		'cmake'
	]

	if platform == 'windows':
		cmd_cmake += [
			'-G', 'Visual Studio 15 2017 Win64'
		]

	cmd_cmake += [	
		'-C', pp(dir_cmake, platform + '.cmake'), # load predefined cache
		'-DCMAKE_INSTALL_PREFIX={d}'.format(d=dir_install),
		dir_src # source dir
	]

	print('CMD ='+'\n	'.join(cmd_cmake))

	# twice because sometimes there are error at first time
	out_code = subprocess.call(cmd_cmake)

	if out_code:
		print('Retrying')
		out_code = subprocess.call(cmd_cmake)

	if out_code:
		print(color_background.RED + 80*' ')
		print(color.RED + 'CMake returned an error, the build files may be wrong')

	else:
		print(color_background.GREEN + 80*' ')
		print('Build files have been generated')
		print('To continue build, go to ', color.YELLOW + build_dir + color.RESET, ' and:')

		if platform in {'linux', 'android'}:
			print('	run command ', color.GREEN + 'make -j8 install')
		elif platform == 'windows':
			print('	build the project with ', color.GREEN + 'Visual Studio')
示例#3
0
    def __init__(self, config):
        config = AttrDict(config)
        config.dataset_name = 'freiburg'
        config.dir_input = pp(config.dir_datasets, 'freiburg',
                              'rgbd_dataset_freiburg3_long_office_household')
        config.dir_input_img = pp(config.dir_input, 'rgb')
        config.dir_input_depth = pp(config.dir_input, 'depth')

        self.set_geometry(537.3, (640, 480))

        # "The depth images are scaled by a factor of 5000,
        # i.e., a pixel value of 5000 in the depth image corresponds to a distance of 1 meter from the camera"
        self.depth_scale_value_to_m = 1 / 5000.0

        # Load images ordered by time
        self.ts_img = DatasetFreiburg.TimeseriesImageCollection(
            config.dir_input_img)
        self.ts_depth = DatasetFreiburg.TimeseriesImageCollection(
            config.dir_input_depth)

        # Load poses
        self.time_and_pose_array = np.loadtxt(
            pp(config.dir_input, 'groundtruth.txt'))
        self.ts_pose = DatasetFreiburg.TimeseriesArray(
            self.time_and_pose_array[:, 0], self.time_and_pose_array[:, 1:])

        super().__init__(config)
示例#4
0
	def func_copy_includes():
		print('-- Includes --')

		if platform != 'android':
			includes_src = pp(dir_install, 'include')
		else:
			includes_src = pp(dir_install, 'sdk', 'native', 'jni', 'include')

		includes_dest = pp(dir_opencv_root, 'include')
		copy_tree(includes_src, includes_dest)
示例#5
0
    def func_copy_includes():
        print('-- Includes --')

        if platform != 'android':
            includes_src = pp(dir_install, 'include')
        else:
            includes_src = pp(dir_install, 'sdk', 'native', 'jni', 'include')

        includes_dest = pp(dir_opencv_root, 'include')
        copy_tree(includes_src, includes_dest)
示例#6
0
def main(args):
    opencv_root = os.path.dirname(__file__)
    plugin_root = os.path.join(opencv_root, '..', '..')

    build_src = pp(opencv_root, 'build', args.platform)
    install_src = pp(build_src, 'install')

    binaries_dest = pp(plugin_root, 'Binaries', args.platform)

    def copy_tree(src, dest):
        print('copy dir:', src, ' -> ', dest)

        if not os.path.isdir(src):
            raise Exception('Source directory not found at ' + src)

        if os.path.exists(dest):
            print('delete existing dir:', dest)
            shutil.rmtree(dest,
                          onerror=lambda *err: print('	rmtree err: ', err))

        print('copying dir')
        shutil.copytree(src, dest)

    def copy_single(src, dest):
        print('copy file: ', src, ' to ', dest)
        shutil.copy(src, dest)

    def copy_includes():
        print('-- Includes --')
        includes_src = pp(install_src, 'include')
        includes_dest = pp(opencv_root, 'include')
        copy_tree(includes_src, includes_dest)

    def copy_libs():
        print('-- Libs --')
        if args.platform == 'Win64':
            binaries_src = pp(install_src, 'x64', 'vc14')

            shared_lib_src = pp(binaries_src, 'bin')
            shared_lib_dest = binaries_dest
            for mod in modules:
                copy_single(pp(shared_lib_src, mod + '310.dll'),
                            shared_lib_dest)

            static_lib_src = pp(binaries_src, 'lib')
            static_lib_dest = pp(opencv_root, 'lib', args.platform)
            for mod in modules:
                copy_single(pp(static_lib_src, mod + '310.lib'),
                            static_lib_dest)

    if args.include_files:
        copy_includes()

    if args.libs:
        copy_libs()
示例#7
0
def discover_synthetic_dsets(cfg, base_dir=None):
    base_dir = base_dir or pp(cfg.dir_datasets, 'synthetic')

    subdirs = os.listdir(base_dir)
    subdirs.sort()

    dss = []
    for subd in subdirs:
        ds = DatasetSyntheticGen(cfg, pp(base_dir, subd))
        dss.append(ds)

    return dss
示例#8
0
def main(args):
	opencv_root = os.path.dirname(__file__)
	plugin_root = os.path.join(opencv_root, '..', '..')

	build_src = pp(opencv_root, 'build', args.platform)
	install_src = pp(build_src, 'install')

	binaries_dest = pp(plugin_root, 'Binaries', args.platform)

	def copy_tree(src, dest):
		print('copy dir:', src, ' -> ', dest)

		if not os.path.isdir(src):
			raise Exception('Source directory not found at '+ src)

		if os.path.exists(dest):
			print('delete existing dir:', dest)
			shutil.rmtree(dest, onerror=lambda *err: print('	rmtree err: ', err))

		print('copying dir')
		shutil.copytree(src, dest)

	def copy_single(src, dest):
		print('copy file: ', src, ' to ', dest)
		shutil.copy(src, dest)

	def copy_includes():
		print('-- Includes --')
		includes_src = pp(install_src, 'include')
		includes_dest = pp(opencv_root, 'include')
		copy_tree(includes_src, includes_dest)
		
	def copy_libs():
		print('-- Libs --')
		if args.platform == 'Win64':
			binaries_src = pp(install_src, 'x64', 'vc14')

			shared_lib_src = pp(binaries_src, 'bin')
			shared_lib_dest = binaries_dest
			for mod in modules:
				copy_single(pp(shared_lib_src, mod + '310.dll'), shared_lib_dest)

			static_lib_src = pp(binaries_src, 'lib')
			static_lib_dest = pp(opencv_root, 'lib', args.platform)
			for mod in modules:
				copy_single(pp(static_lib_src, mod + '310.lib'), static_lib_dest)

	if args.include_files:
		copy_includes()

	if args.libs:
		copy_libs()
示例#9
0
def synth_demo_chans(gen_name):
	dir_base = pp('{dset.dir_out}', gen_name, 'demo', gen_name + '{dset.split}')

	tmpl_part = pp(dir_base, 'parts', '{frame.fid_no_subdir}_{channel.suffix}{channel.img_ext}')
	tmpl_fused = pp(dir_base, '{frame.fid_no_subdir}_{channel.suffix}{channel.img_ext}')

	return {
		# 'demo_image': ChannelResultImage(f'{gen_name}/demo/parts', suffix='_image', img_ext='.jpg')
		'demo_image_contour': ChannelLoaderImage(tmpl_part, suffix='image_contour', img_ext='.jpg'),
		'demo_gen_image_contour': ChannelLoaderImage(tmpl_part, suffix='gen_image_contour', img_ext='.jpg'),
		'demo_pred_labels': ChannelLoaderImage(tmpl_part, suffix='pred_labels', img_ext='.png'),
		'demo_fake_labels': ChannelLoaderImage(tmpl_part, suffix='fake_labels', img_ext='.png'),
		'demo_synth_grid': ChannelLoaderImage(tmpl_fused, suffix='grid', img_ext='.jpg'),
	}
示例#10
0
	def copy_libs():
		print('-- Libs --')
		if args.platform == 'Win64':
			binaries_src = pp(args.gstreamer_root)

			shared_lib_src = pp(binaries_src, 'bin')
			shared_lib_dest = binaries_dest

			for lib_file in os.listdir(shared_lib_src):
				#if os.path.splitext(lib_file)[1].lower() == '.dll':
				if lib_file.lower() in  modules:
					copy_single(pp(shared_lib_src, lib_file), shared_lib_dest)

		elif args.platform == 'Linux':
			print('No linux binaries so far')
示例#11
0
    def copy_libs():
        print('-- Libs --')
        if args.platform == 'Win64':
            binaries_src = pp(args.gstreamer_root)

            shared_lib_src = pp(binaries_src, 'bin')
            shared_lib_dest = binaries_dest

            for lib_file in os.listdir(shared_lib_src):
                #if os.path.splitext(lib_file)[1].lower() == '.dll':
                if lib_file.lower() in modules:
                    copy_single(pp(shared_lib_src, lib_file), shared_lib_dest)

        elif args.platform == 'Linux':
            print('No linux binaries so far')
示例#12
0
def main(args):
    print('Platform:', args.platform)
    print('GStreamer:', args.gstreamer_root)

    plugin_root = os.path.join(os.path.dirname(__file__), '..', '..')
    binaries_dest = pp(plugin_root, 'Binaries', args.platform)

    def copy_single(src, dest):
        print('copy file: ', src, ' to ', dest)
        shutil.copy(src, dest)

    def copy_libs():
        print('-- Libs --')
        if args.platform == 'Win64':
            binaries_src = pp(args.gstreamer_root)

            shared_lib_src = pp(binaries_src, 'bin')
            shared_lib_dest = binaries_dest

            for lib_file in os.listdir(shared_lib_src):
                #if os.path.splitext(lib_file)[1].lower() == '.dll':
                if lib_file.lower() in modules:
                    copy_single(pp(shared_lib_src, lib_file), shared_lib_dest)

        elif args.platform == 'Linux':
            print('No linux binaries so far')

    if args.libs:
        copy_libs()
示例#13
0
def save_rgbd_frames_to_hdf(sequence):
    file_path = pp(sequence.config.dir_out,
                   sequence.config.dataset_name + '.hdf5')

    # hdf5 does not overwrite files
    if os.path.exists(file_path):
        os.remove(file_path)

    #print('Saving to', file_path)

    with h5py.File(file_path, libver='latest') as out:

        out.create_dataset('intrinsic', data=sequence.frames[0].intrinsic_mat)

        # Configs
        cfg_group = out.create_group("config")
        cfg_group.attrs["frame_count"] = len(sequence.frames)
        for key, val in sequence.config.items():
            cfg_group.attrs[key] = val

        # Frames
        for fid, frame in enumerate(sequence.frames):
            fgroup = out.create_group("frame_{n}".format(n=fid))

            fgroup.attrs['name'] = frame.name
            fgroup.attrs['focal'] = frame.focal

            fgroup.create_dataset("rgb", data=frame.photo)
            fgroup.create_dataset("depth", data=frame.depth)
            fgroup.create_dataset("pose_cam_to_world",
                                  data=frame.camera_to_world)
示例#14
0
def main(args):
	print('Platform:', args.platform)
	print('GStreamer:', args.gstreamer_root)

	plugin_root = os.path.join(os.path.dirname(__file__), '..', '..')
	binaries_dest = pp(plugin_root, 'Binaries', args.platform)

	def copy_single(src, dest):
		print('copy file: ', src, ' to ', dest)
		shutil.copy(src, dest)

	def copy_libs():
		print('-- Libs --')
		if args.platform == 'Win64':
			binaries_src = pp(args.gstreamer_root)

			shared_lib_src = pp(binaries_src, 'bin')
			shared_lib_dest = binaries_dest

			for lib_file in os.listdir(shared_lib_src):
				#if os.path.splitext(lib_file)[1].lower() == '.dll':
				if lib_file.lower() in  modules:
					copy_single(pp(shared_lib_src, lib_file), shared_lib_dest)

		elif args.platform == 'Linux':
			print('No linux binaries so far')

	if args.libs:
		copy_libs()
示例#15
0
def demo_chans(sem_cat):
	dir_base = pp('{dset.dir_out}', 'eval_' + sem_cat, '{dset.name}_demo_{dset.split}_'+sem_cat)

	tmpl_part = pp(dir_base, 'parts', '{frame.fid_no_subdir}_{channel.suffix}{channel.img_ext}')
	tmpl_fused = pp(dir_base, '{frame.fid_no_subdir}_{channel.suffix}{channel.img_ext}')

	return {
		'demo_image': ChannelLoaderImage(tmpl_part, suffix='image', img_ext='.jpg'),
		'demo_gt_contour': ChannelLoaderImage(tmpl_part, suffix='gt_contour', img_ext='.jpg'),
		'demo_pred_labels': ChannelLoaderImage(tmpl_part, suffix='pred_labels', img_ext='.png'),
		'demo_gen_image': ChannelLoaderImage(tmpl_part, suffix='gen_image', img_ext='.jpg'),
		'demo_anomaly_uncertainty': ChannelLoaderImage(tmpl_part, suffix='anomaly_uncertainty', img_ext='.jpg'),
		'demo_anomaly_ours': ChannelLoaderImage(tmpl_part, suffix='anomaly_ours', img_ext='.jpg'),
		'demo_anomaly_rbm': ChannelLoaderImage(tmpl_part, suffix='anomaly_rbm', img_ext='.jpg'),

		'demo_pipeline': ChannelLoaderImage(tmpl_fused, suffix='pipeline', img_ext='.jpg'),
		'demo_scores': ChannelLoaderImage(tmpl_fused, suffix='scores', img_ext='.jpg'),
	}
示例#16
0
def summarize_seq(seq, b_save=True):
    photo_0 = seq.frames[0].photo
    dep_0 = displayable_depth(seq.frames[0].depth)
    photo_n = seq.frames[-1].photo
    dep_n = displayable_depth(seq.frames[-1].depth)

    show_multidim(
        [[photo_0, photo_n, dep_0, dep_n]],
        col_titles=["frame 0", "frame N", "depth 0", "depth N"],
        save=pp(seq.config.dir_out, '01_dataset_overview.jpg')
        if b_save else False,
    )
示例#17
0
	def copy_libs():
		print('-- Libs --')
		modules = MODULES

		if platform == 'windows':
			#modules = MODULES + ["opencv_aur_allocator"]

			binaries_src = pp(dir_install, 'x64', 'vc15')

			shared_lib_src = pp(binaries_src, 'bin')
			for mod in modules:
				copy_single(pp(shared_lib_src, mod + '341.dll'), dir_binaries_dest)

			# static_lib_src = pp(binaries_src, 'lib')
			# static_lib_dest = pp(opencv_root, 'lib', args.platform)
			# for mod in modules:
			# 	copy_single(pp(static_lib_src, mod + '310.lib'), static_lib_dest)

		elif platform == 'linux':
			shared_lib_src = pp(dir_install, 'lib')
			for mod in modules:
				symlink_name = pp(dir_binaries_dest, 'lib' + mod + '.so')
				out_name = symlink_name + '.3.4'

				copy_single(pp(shared_lib_src, 'lib' + mod + '.so.3.4.1'), out_name)

				try:
					os.remove(symlink_name)
				except:
					pass
				os.symlink(out_name, symlink_name)

		elif platform == 'android':
			print(color.GREEN + 'Android libraries are statically linked so no need to move them')
示例#18
0
	def copy_libs():
		print('-- Libs --')
		modules = MODULES

		if platform == 'windows':
			#modules = MODULES + ["opencv_aur_allocator"]

			binaries_src = pp(dir_install, 'x64', 'vc14')

			shared_lib_src = pp(binaries_src, 'bin')
			for mod in modules:
				copy_single(pp(shared_lib_src, mod + '310.dll'), dir_binaries_dest)

			# static_lib_src = pp(binaries_src, 'lib')
			# static_lib_dest = pp(opencv_root, 'lib', args.platform)
			# for mod in modules:
			# 	copy_single(pp(static_lib_src, mod + '310.lib'), static_lib_dest)

		elif platform == 'linux':
			shared_lib_src = pp(dir_install, 'lib')
			for mod in modules:
				symlink_name = pp(dir_binaries_dest, 'lib' + mod + '.so')
				out_name = symlink_name + '.3.1'

				copy_single(pp(shared_lib_src, 'lib' + mod + '.so.3.1.0'), out_name)

				try:
					os.remove(symlink_name)
				except:
					pass
				os.symlink(out_name, symlink_name)

		elif platform == 'android':
			print(color.GREEN + 'Android libraries are statically linked so no need to move them')
示例#19
0
def set_metadata(ts, gi):
    for t in ts:
        if not pp(t.p):
            print("Error: File %s does not exist" % t.p, file=sys.stderr)
            continue
        f = open(t.p, "rb")
        mm = mime(f.read(), mime=True)
        if mm != "audio/mpeg" and mm != "audio/x-wav":
            print("Error: Can't set file %s's metadata. file is of type %s" %
                  (t.p, mm),
                  file=sys.stderr)
            f.close()
            continue
        print("Changing metadata: %s" % t.p)
        f.close()
        if mm == "audio/mpeg":
            a = ID3(t.p, v2_version=3)
            a.add(TIT2(encoding=3, text=t.n))
            a.add(TRCK(encoding=3, text=str(t.i)))
            a.add(TLEN(encoding=3, text=str(t.l)))
            a.save(v2_version=3)
        elif mm == "audio/x-wav":
            wf = open(t.p, "rb")
            ck = rp.get_riff(wf)
            ckp = rp.riff_path(ck, [])
            mp = rp.path_to_metadata(ckp, new=True)
            mm = rp.get_metadata(wf, mp.ebl)
            mm[b'INAM'] = bytes(t.n, "utf-8") + b'\x00'
            mm[b'ITRK'] = bytes(str(t.i), "utf-8") + b'\x00'
            mm[b'TLEN'] = bytes(str(t.l), "utf-8") + b'\x00'
            if t.alb:
                mm[b'IPRD'] = bytes(str(t.alb), "utf-8") + b'\x00'
            elif gi.alb:
                mm[b'IPRD'] = bytes(str(gi.alb), "utf-8") + b'\x00'

            if t.art:
                mm[b'IART'] = bytes(str(t.art), "utf-8") + b'\x00'
            elif gi.art:
                mm[b'IART'] = bytes(str(gi.art), "utf-8") + b'\x00'

            if t.gn:
                mm[b'IGNR'] = bytes(str(t.gn), "utf-8") + b'\x00'
            elif gi.genre:
                mm[b'IGNR'] = bytes(str(gi.genre), "utf-8") + b'\x00'

            rp.set_metadata(mp, mm)
            wo = open(t.p + "._.wav", "wb")
            rp.save_riff(wo, wf, ck)
            wo.close()
            wf.close()
            brr(t.p, t.p + ".old.wav")
            brr(t.p + "._.wav", t.p)
示例#20
0
    def get_sequence(self, initial_index, frame_count, stride=1):

        idx_list = np.arange(frame_count) * stride + initial_index
        frames = []

        for idx in idx_list:
            photo = cv2.imread(
                pp(self.config.dir_input_imgs, self.paths_imgs[idx]),
                cv2.IMREAD_UNCHANGED)[:, :, (2, 1, 0)]

            depth = read_colmap_img_file(
                pp(self.config.dir_input_depth, self.paths_depths[idx]))
            depth = cv2.resize(depth, photo.shape[:2][::-1])
            depth[depth < 0] = np.nan

            fr = RgbdFrame(
                name=str(idx),
                photo=photo,
                depth=depth,
            )

            frame_def = self.frame_defs[idx]
            fr.set_intrinsic_mat(frame_def.intrinsic_mat)
            fr.set_pose_matrix_cam_to_world(frame_def.pose_cam_to_world)

            #fr.set_intrinsic_mat(self.intrinsic_mat)
            #fr.set_pose_matrix_cam_to_world(self.poses_cam_to_world[idx])
            #fr.params = poses[idx][2]
            frames.append(fr)

        cfg = AttrDict(self.config)
        cfg.sequence_name = '{si:06d}_{ei:06d}_{s:02d}'.format(si=idx_list[0],
                                                               ei=idx_list[-1],
                                                               s=stride)

        seq = FrameSequence(frames, config=cfg, dset=self)
        seq.focal = frames[0].focal  #self.focal
        seq.intrinsic_mat = frames[0].intrinsic_mat  #self.intrinsic_mat
        return seq
示例#21
0
    def __init__(self, config, name, dirname):
        config = AttrDict(config)
        config.dataset_scene = name
        config.dataset_name = name

        config.dir_input = pp(config.dir_datasets, 'architectural', dirname)
        config.dir_input_imgs = pp(config.dir_input, 'images')
        self.paths_imgs = os.listdir(config.dir_input_imgs)
        self.paths_imgs.sort()

        config.dir_input_depth = pp(config.dir_input, 'depth_maps')
        self.paths_depths = os.listdir(config.dir_input_depth)
        self.paths_depths.sort()

        #config.dir_input_normals = pp(config.dir_input, 'normal_maps')
        #paths_normals = os.listdir(config.dir_input_normals)
        #paths_normals.sort()

        # each frame has 2 images
        self.frame_count = len(os.listdir(config.dir_input_imgs))

        super().__init__(config)

        self.load_cameras()
示例#22
0
    def copy_libs():
        print('-- Libs --')
        if args.platform == 'Win64':
            binaries_src = pp(install_src, 'x64', 'vc14')

            shared_lib_src = pp(binaries_src, 'bin')
            shared_lib_dest = binaries_dest
            for mod in modules:
                copy_single(pp(shared_lib_src, mod + '310.dll'),
                            shared_lib_dest)

            static_lib_src = pp(binaries_src, 'lib')
            static_lib_dest = pp(opencv_root, 'lib', args.platform)
            for mod in modules:
                copy_single(pp(static_lib_src, mod + '310.lib'),
                            static_lib_dest)

        elif args.platform == 'Linux':
            shared_lib_src = pp(build_src, 'lib')
            shared_lib_dest = binaries_dest
            for mod in modules:
                copy_single(pp(shared_lib_src, 'lib' + mod + '.so.3.1.0'),
                            pp(shared_lib_dest, 'lib' + mod + '.so'))
示例#23
0
    def get_sequence(self, initial_index, frame_count, stride=1):

        idx_list = np.arange(frame_count,
                             dtype=np.int32) * stride + initial_index
        idx_list = idx_list.astype(np.int32)
        dir_in = self.config.dir_input
        frames = []

        for idx in idx_list:
            name_base = pp(dir_in, '{fi:04d}'.format(fi=idx))

            photo_path = name_base + '_image0032.jpg'
            photo = cv2.imread(photo_path, cv2.IMREAD_UNCHANGED)

            if photo is None:
                print('File fail', photo_path)

            photo = photo[:, :, (2, 1, 0)]

            depth = cv2.imread(name_base + '_depth0032.exr',
                               cv2.IMREAD_UNCHANGED)
            depth = depth[:, :, 0]
            depth[depth == 0] = np.nan
            depth[depth > 1e6] = np.nan

            trans_mat = np.loadtxt(name_base + '_pose.csv')

            fr = RgbdFrame(
                name=str(idx),
                photo=photo,
                depth=depth,
            )
            fr.set_intrinsic_mat(self.intrinsic_mat)
            fr.set_pose_matrix_cam_to_world(trans_mat)
            frames.append(fr)

        cfg = AttrDict(self.config)
        cfg.sequence_name = '{si:06d}_{ei:06d}_{s:02d}'.format(si=idx_list[0],
                                                               ei=idx_list[-1],
                                                               s=stride)

        seq = FrameSequence(frames, config=cfg, dset=self)
        seq.focal = self.focal
        seq.intrinsic_mat = self.intrinsic_mat
        return seq
示例#24
0
    def __init__(self, config, scene_name, seq_index):
        config = AttrDict(config)
        config.dataset_scene = scene_name
        config.dataset_sequence = seq_index
        config.dataset_name = '7scenes_{sn}_{si:02d}'.format(sn=scene_name,
                                                             si=seq_index)

        config.dir_input = pp(config.dir_datasets, '7scenes', scene_name,
                              'seq-{si:02d}'.format(si=seq_index))
        # each frame has 2 images and pose file
        self.frame_count = len(os.listdir(config.dir_input)) // 3

        # Principle point (320,240), Focal length (585,585).
        self.set_geometry(585, (640, 480))

        self.depth_scale_value_to_m = 1 / 1000.0

        super().__init__(config)
示例#25
0
	def copy_libs():
		print('-- Libs --')
		if args.platform == 'Win64':
			binaries_src = pp(install_src, 'x64', 'vc14')

			shared_lib_src = pp(binaries_src, 'bin')
			shared_lib_dest = binaries_dest
			for mod in modules:
				copy_single(pp(shared_lib_src, mod + '310.dll'), shared_lib_dest)

			static_lib_src = pp(binaries_src, 'lib')
			static_lib_dest = pp(opencv_root, 'lib', args.platform)
			for mod in modules:
				copy_single(pp(static_lib_src, mod + '310.lib'), static_lib_dest)
示例#26
0
def load_plane_estimations(sequence):
    file_path = pp(sequence.config.dir_out,
                   sequence.config.dataset_name + '.hdf5')

    #print('Loading from', file_path)

    with h5py.File(file_path, libver='latest') as in_file:

        for fid, frame in enumerate(sequence.frames):
            fgroup = in_file["frame_{n}".format(n=fid)]

            frame.normals = fgroup['normals'].value
            frame.point_cloud = fgroup['points'].value
            frame.plane_map = fgroup['plane_map'].value

            try:
                frame.plane_coefficients = fgroup[
                    'plane_coefficients'].value[:, 0, :]
            except Exception as e:
                print('Faulty planes')
示例#27
0
    def get_sequence(self, initial_index, frame_count, stride=1):

        idx_list = np.arange(frame_count,
                             dtype=np.int) * int(stride) + int(initial_index)

        frames = []

        for idx in idx_list:
            name_base = pp(self.config.dir_input,
                           'frame-{fi:06d}.'.format(fi=idx))

            photo = cv2.imread(name_base + 'color.png',
                               cv2.IMREAD_UNCHANGED)[:, :, (2, 1, 0)]
            if photo is None:
                raise Exception('Loaded image is None')

            depth = cv2.imread(name_base + 'depth.png',
                               cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
            depth = depth.astype(np.float32)
            depth *= self.depth_scale_value_to_m

            trans_mat = np.loadtxt(name_base + 'pose.txt')

            fr = RgbdFrame(
                name=str(idx),
                photo=photo,
                depth=depth,
            )
            fr.set_intrinsic_mat(self.intrinsic_mat)
            fr.set_pose_matrix_cam_to_world(trans_mat)
            frames.append(fr)

        cfg = AttrDict(self.config)
        cfg.sequence_name = '{si:06d}_{ei:06d}_{s:02d}'.format(si=idx_list[0],
                                                               ei=idx_list[-1],
                                                               s=stride)

        seq = FrameSequence(frames, config=cfg, dset=self)
        seq.focal = self.focal
        seq.intrinsic_mat = self.intrinsic_mat
        return seq
示例#28
0
#!/usr/bin/env python3
import click, subprocess, os
import shutil, glob
from os.path import join as pp
from platform import system as system_name
from colorama import init
from colorama import Fore as color
from colorama import Back as color_background
init(autoreset=True)

# Dirs
dir_opencv_root = os.path.dirname(os.path.realpath(__file__))
dir_src = pp(dir_opencv_root, 'src', 'opencv')
dir_cmake = pp(dir_opencv_root, 'cmake_settings')
dir_plugin_root = pp(dir_opencv_root, '..', '..')

# Platform
platform_dirs = {
	'windows': 'Win64',
	'linux': 'Linux',
	'android': 'Android',
}
platforms = list(platform_dirs.keys())
platforms.sort()

platform_current = system_name().lower()
if platform_current not in platform_dirs:
	print('Warning: unrecognized platform: ', platform_current)
	platform_current = platforms[0]

# OpenCV Modules
示例#29
0
def copy(platform, copy_includes, copy_binaries):
    # where the "make install" wrote its files:
    dir_install = pp(dir_opencv_root, 'install', platform_dirs[platform])

    # where we want to copy the files
    dir_binaries_dest = pp(dir_plugin_root, 'Binaries',
                           platform_dirs[platform])

    print('Task:', color.MAGENTA + 'build')
    print('- platform:', color.CYAN + platform)
    print('- source directory:', color.CYAN + dir_install)
    print('- destination directory:', color.CYAN + dir_binaries_dest)

    def copy_tree(src, dest):
        print('copy directory: ', color.YELLOW + src + color.RESET, ' ---> ',
              color.CYAN + dest)

        if not os.path.isdir(src):
            raise Exception('Source directory not found at ' + src)

        if os.path.exists(dest):
            print('	delete existing dir:', dest)
            shutil.rmtree(dest,
                          onerror=lambda *err: print('	rmtree err: ', err))

        print('	copying dir')
        shutil.copytree(src, dest)

    def copy_single(src, dest):
        print('copy : ', color.YELLOW + src + color.RESET, ' ---> ',
              color.CYAN + dest)
        shutil.copy(src, dest)

    def func_copy_includes():
        print('-- Includes --')

        if platform != 'android':
            includes_src = pp(dir_install, 'include')
        else:
            includes_src = pp(dir_install, 'sdk', 'native', 'jni', 'include')

        includes_dest = pp(dir_opencv_root, 'include')
        copy_tree(includes_src, includes_dest)

    def copy_libs():
        print('-- Libs --')
        modules = MODULES

        if platform == 'windows':
            #modules = MODULES + ["opencv_aur_allocator"]

            binaries_src = pp(dir_install, 'x64', 'vc15')

            shared_lib_src = pp(binaries_src, 'bin')
            for mod in modules:
                copy_single(pp(shared_lib_src, mod + '340.dll'),
                            dir_binaries_dest)

            # static_lib_src = pp(binaries_src, 'lib')
            # static_lib_dest = pp(opencv_root, 'lib', args.platform)
            # for mod in modules:
            # 	copy_single(pp(static_lib_src, mod + '310.lib'), static_lib_dest)

        elif platform == 'linux':
            shared_lib_src = pp(dir_install, 'lib')
            for mod in modules:
                symlink_name = pp(dir_binaries_dest, 'lib' + mod + '.so')
                out_name = symlink_name + '.3.4'

                copy_single(pp(shared_lib_src, 'lib' + mod + '.so.3.4.0'),
                            out_name)

                try:
                    os.remove(symlink_name)
                except:
                    pass
                os.symlink(out_name, symlink_name)

        elif platform == 'android':
            print(
                color.GREEN +
                'Android libraries are statically linked so no need to move them'
            )

    if copy_includes:
        func_copy_includes()

    if copy_binaries:
        copy_libs()
示例#30
0
#!/usr/bin/env python3
import click, subprocess, os
import shutil, glob
from os.path import join as pp
from platform import system as system_name
from colorama import init
from colorama import Fore as color
from colorama import Back as color_background
init(autoreset=True)

# Dirs
dir_opencv_root = os.path.dirname(os.path.realpath(__file__))
dir_src = pp(dir_opencv_root, 'src', 'opencv')
dir_cmake = pp(dir_opencv_root, 'cmake_settings')
dir_plugin_root = pp(dir_opencv_root, '..', '..')

# Platform
platform_dirs = {
    'windows': 'Win64',
    'linux': 'Linux',
    'android': 'Android',
}
platforms = list(platform_dirs.keys())
platforms.sort()

platform_current = system_name().lower()
if platform_current not in platform_dirs:
    print('Warning: unrecognized platform: ', platform_current)
    platform_current = platforms[0]

# OpenCV Modules
示例#31
0
def discover_files(directory):
    fns = os.listdir(directory)
    fns = natsort.natsorted(fns)
    return [pp(directory, fn) for fn in fns]
示例#32
0
	def copy_includes():
		print('-- Includes --')
		includes_src = pp(install_src, 'include')
		includes_dest = pp(opencv_root, 'include')
		copy_tree(includes_src, includes_dest)
示例#33
0
 def copy_includes():
     print('-- Includes --')
     includes_src = pp(install_src, 'include')
     includes_dest = pp(opencv_root, 'include')
     copy_tree(includes_src, includes_dest)
示例#34
0
    def load_cameras(self):
        self.poses_cam_to_world = []

        # Example file:
        # # Camera list with one line of data per camera:
        # #   CAMERA_ID, MODEL, WIDTH, HEIGHT, PARAMS[]
        # # Number of cameras: 330
        # 330 SIMPLE_RADIAL 1404 936 967.328 702 468 -0.0558808
        # 329 SIMPLE_RADIAL 1404 936 950.169 702 468 -0.0521315
        # 328 SIMPLE_RADIAL 1404 936 965.562 702 468 -0.0542226
        # 327 SIMPLE_RADIAL 1404 936 952.185 702 468 -0.0531098
        intrinsics = dict()

        with open(pp(self.config.dir_input, 'cameras', 'cameras.txt'),
                  'r') as f_cameras:
            is_pose_line = True
            for line in f_cameras:
                if line[0] == '#':
                    pass  # commant
                else:
                    #print(line)
                    params = line.split()
                    # CAMERA_ID, MODEL, WIDTH, HEIGHT, PARAMS[]
                    cam_id = int(params[0])

                    # model, width, height -> not needed
                    # 1 2 3

                    # params[] = focal, center_x, center_y, distortion?
                    focal = float(params[4])
                    center_x = float(params[5])
                    center_y = float(params[6])

                    intrinsics[cam_id] = intrinsic_matrix(
                        focal, (center_x * 2, center_y * 2))

        frame_defs = {}

        with open(pp(self.config.dir_input, 'cameras', 'images.txt'),
                  'r') as f_poses:
            is_pose_line = True
            for line in f_poses:
                if line[0] == '#':
                    pass  # commant
                elif is_pose_line:
                    #print(line)
                    params = line.split()
                    # IMAGE_ID, QW, QX, QY, QZ, TX, TY, TZ, CAMERA_ID, NAME
                    # img id
                    img_id = int(params[0])
                    # qw qx qy qz
                    quat_rot = np.array(list(map(float, params[1:5])))
                    # but we want qx qy qz qw
                    quat_rot = np.roll(quat_rot, -1)
                    # tx ty tz
                    t = np.array(list(map(float, params[5:8])))
                    # camera_id
                    cam_id = int(params[8])
                    intrinsic_mat = intrinsics[cam_id]

                    # file name
                    file_name = params[9]

                    pose_mat = quat_pose_to_transform(quat=quat_rot,
                                                      position=t)
                    pose_mat = spatial_inverse(pose_mat)

                    frame_defs[img_id] = AttrDict(
                        intrinsic_mat=intrinsic_mat,
                        pose_cam_to_world=pose_mat,
                    )

                is_pose_line = not is_pose_line

        self.frame_defs = list(frame_defs.items())
        self.frame_defs.sort()
        self.frame_defs = [fd for _, fd in self.frame_defs]
示例#35
0
def copy(platform, copy_includes, copy_binaries):
	# where the "make install" wrote its files:
	dir_install = pp(dir_opencv_root, 'install', platform_dirs[platform])

	# where we want to copy the files
	dir_binaries_dest = pp(dir_plugin_root, 'Binaries', platform_dirs[platform])
	os.makedirs(dir_binaries_dest, exist_ok=True)

	print('Task:', color.MAGENTA + 'build')
	print('- platform:', color.CYAN + platform)
	print('- source directory:', color.CYAN + dir_install)
	print('- destination directory:', color.CYAN + dir_binaries_dest)

	def copy_tree(src, dest):
		print('copy directory: ', color.YELLOW + src + color.RESET, ' ---> ', color.CYAN + dest)

		if not os.path.isdir(src):
			raise Exception('Source directory not found at '+ src)

		if os.path.exists(dest):
			print('	delete existing dir:', dest)
			shutil.rmtree(dest, onerror=lambda *err: print('	rmtree err: ', err))

		print('	copying dir')
		shutil.copytree(src, dest)

	def copy_single(src, dest):
		print('copy : ', color.YELLOW + src + color.RESET, ' ---> ', color.CYAN + dest)
		shutil.copy(src, dest)

	def func_copy_includes():
		print('-- Includes --')

		if platform != 'android':
			includes_src = pp(dir_install, 'include')
		else:
			includes_src = pp(dir_install, 'sdk', 'native', 'jni', 'include')

		includes_dest = pp(dir_opencv_root, 'include')
		copy_tree(includes_src, includes_dest)

	def copy_libs():
		print('-- Libs --')
		modules = MODULES

		if platform == 'windows':
			#modules = MODULES + ["opencv_aur_allocator"]

			binaries_src = pp(dir_install, 'x64', 'vc15')

			shared_lib_src = pp(binaries_src, 'bin')
			for mod in modules:
				copy_single(pp(shared_lib_src, mod + '341.dll'), dir_binaries_dest)

			# static_lib_src = pp(binaries_src, 'lib')
			# static_lib_dest = pp(opencv_root, 'lib', args.platform)
			# for mod in modules:
			# 	copy_single(pp(static_lib_src, mod + '310.lib'), static_lib_dest)

		elif platform == 'linux':
			shared_lib_src = pp(dir_install, 'lib')
			for mod in modules:
				symlink_name = pp(dir_binaries_dest, 'lib' + mod + '.so')
				out_name = symlink_name + '.3.4'

				copy_single(pp(shared_lib_src, 'lib' + mod + '.so.3.4.1'), out_name)

				try:
					os.remove(symlink_name)
				except:
					pass
				os.symlink(out_name, symlink_name)

		elif platform == 'android':
			print(color.GREEN + 'Android libraries are statically linked so no need to move them')

	if copy_includes:
		func_copy_includes()

	if copy_binaries:
		copy_libs()
示例#36
0
    def execute(self, context):

        scene = context.scene
        pref = get_prefs(context)

        # prepare rendering:
        # - set FOV
        context.scene.camera.data.angle_x = math.radians(pref.fov)

        # discover textures
        texture_files = os.listdir(pref.dir_tex)
        texture_files.sort()
        texture_files = [pp(pref.dir_tex, tf) for tf in texture_files]

        if not texture_files:
            self.report({'ERROR'}, 'No textures in ' + pref.dir_tex)
            return

        tex_img = None
        for tex_idx, tex_file in enumerate(texture_files):
            tex_file_path = os.path.abspath(tex_file)
            print('Scene', tex_idx, '-', tex_file_path)

            dir_scene = pp(pref.dir_out, 'scene_{s:03d}'.format(s=tex_idx))
            # - set out dir
            os.makedirs(dir_scene, exist_ok=True)
            set_out_file_path_base(dir_scene)

            # load and apply texture
            prev_tex_img = tex_img

            tex_img = bpy.data.images.load(tex_file_path, check_existing=True)
            bpy.data.materials['image_material'].texture_slots[
                0].texture.image = tex_img

            # remove previous image to free mem
            if prev_tex_img:
                prev_tex_img.user_clear()
                if not prev_tex_img.users:
                    bpy.data.images.remove(prev_tex_img)

            # progress bar
            for fr_id in range(pref.frames_per_scene):

                # move camera
                if fr_id == 0:
                    pitch = 0.
                    yaw = 0.
                    roll = 0.

                else:
                    pitch = math.radians(random.uniform(0, pref.pitch_max))
                    yaw = random.uniform(0, 2 * math.pi)
                    roll = random.uniform(0, 2 * math.pi)

                move_camera_to_spherical(5., pitch, yaw, roll)

                # write camera pose to file
                write_pose(scene.camera,
                           pp(dir_scene, '{n:04d}_pose.csv'.format(n=fr_id)))

                # set out file names
                set_out_file_index(fr_id)

                # render!
                bpy.ops.render.render()

        return ST_FINISHED