Esempio n. 1
0
 def _button_edit_cal_parameters_fired(self):
     cp = pargui.Calib_Params(par_path=self.par_path)
     cp.edit_traits(kind='modal')
     # at the end of a modification, copy the parameters
     par.copy_params_dir(self.par_path, self.active_path)
     self.cpar, self.spar, self.vpar, self.track_par, self.tpar, \
     self.cals, self.epar = ptv.py_start_proc_c(self.n_cams)
Esempio n. 2
0
    def __init__(self, active_path):
        """ Initialize CalibrationGUI

            Inputs:
                active_path is the path to the folder of prameters
                active_path is a subfolder of a working folder with a
                structure of /parameters, /res, /cal, /img and so on
        """

        super(CalibrationGUI, self).__init__()
        self.need_reset = 0

        self.active_path = active_path
        self.working_folder = os.path.split(self.active_path)[0]
        self.par_path = os.path.join(self.working_folder, 'parameters')

        par.copy_params_dir(self.active_path, self.par_path)

        os.chdir(os.path.abspath(self.working_folder))
        print("Inside a folder: ", os.getcwd())
        # read parameters
        with open(os.path.join(self.par_path, 'ptv.par'), 'r') as f:
            self.n_cams = int(f.readline())

        self.camera = [PlotWindow() for i in range(self.n_cams)]
        for i in range(self.n_cams):
            self.camera[i].name = "Camera" + str(i + 1)
            self.camera[i].cameraN = i
            self.camera[i].py_rclick_delete = ptv.py_rclick_delete
            self.camera[i].py_get_pix_N = ptv.py_get_pix_N
Esempio n. 3
0
    def populate_runs(self, exp_path):
        # Read all parameters directories from an experiment directory
        self.paramsets = []
        dir_contents = [
            f for f in os.listdir(exp_path)
            if os.path.isdir(os.path.join(exp_path, f))
        ]
        dir_contents = [
            f for f in dir_contents if f.startswith(par.par_dir_prefix)
        ]

        if len(dir_contents) == 1 and dir_contents[0] == par.par_dir_prefix:
            # single parameters directory, backward compatibility
            exp_name = 'Run1'
            par.copy_params_dir(dir_contents[0], dir_contents[0] + exp_name)
            dir_contents.append(dir_contents[0] + exp_name)

        for dir_item in dir_contents:
            par_path = os.path.join(exp_path, dir_item)
            if dir_item != par.par_dir_prefix:
                # This should be a params dir, add a tree entry for it.
                exp_name = dir_item[len(par.par_dir_prefix):]
                self.addParamset(exp_name, par_path)

        if not self.changed_active_params:
            if self.nParamsets() > 0:
                self.setActive(0)
Esempio n. 4
0
 def rename_set_params(editor, object):
     """ rename_set_params renames the node name on the tree and also the folder of parameters
     """
     experiment = editor.get_parent(object)
     paramset = object
     # rename
     # import pdb; pdb.set_trace()
     editor._menu_rename_node()
     new_name = object.name
     new_dir_path = par.par_dir_prefix + new_name
     os.mkdir(new_dir_path)
     par.copy_params_dir(paramset.par_path, new_dir_path)
     [os.remove(os.path.join(paramset.par_path, f)) for f in os.listdir(paramset.par_path)]
     os.rmdir(paramset.par_path)
     experiment.removeParamset(paramset)
     experiment.addParamset(new_name, new_dir_path)
Esempio n. 5
0
    def copy_set_params(self, editor, object):
        experiment = editor.get_parent(object)
        paramset = object
        i = 1
        new_name = None
        new_dir_path = None
        flag = False
        while not flag:
            new_name = "%s (%d)" % (paramset.name, i)
            new_dir_path = "%s%s" % (par.par_dir_prefix, new_name)
            if not os.path.isdir(new_dir_path):
                flag = True
            else:
                i = i + 1

        os.mkdir(new_dir_path)
        par.copy_params_dir(paramset.par_path, new_dir_path)
        experiment.addParamset(new_name, new_dir_path)
Esempio n. 6
0
    def _button_showimg_fired(self):

        print("Loading images/parameters \n")

        # Initialize what is needed, copy necessary things

        print("\n Copying man_ori.dat \n")
        if os.path.isfile(os.path.join(self.par_path, 'man_ori.dat')):
            shutil.copyfile(os.path.join(self.par_path, 'man_ori.dat'),
                            os.path.join(self.working_folder, 'man_ori.dat'))
            print("\n Copied man_ori.dat \n")

        # copy parameters from active to default folder parameters/
        par.copy_params_dir(self.active_path, self.par_path)

        # read from parameters
        self.cpar, self.spar, self.vpar, self.track_par, self.tpar, \
        self.cals, self.epar = ptv.py_start_proc_c(self.n_cams)

        self.tpar.read(b'parameters/detect_plate.par')

        print(self.tpar.get_grey_thresholds())

        self.calParams = par.CalOriParams(self.n_cams, self.par_path)
        self.calParams.read()

        if self.epar.Combine_Flag is True:
            print("Combine Flag")
            self.MultiParams = par.MultiPlaneParams()
            self.MultiParams.read()
            for i in range(self.MultiParams.n_planes):
                print(self.MultiParams.plane_name[i])

            self.pass_raw_orient = True
            self.status_text = "Multiplane calibration."

        # read calibration images
        self.cal_images = []
        for i in range(len(self.camera)):
            imname = self.calParams.img_cal_name[i]
            # for imname in self.calParams.img_cal_name:
            # self.cal_images.append(imread(imname))
            im = imread(imname)
            if im.ndim > 2:
                im = rgb2gray(im)

            self.cal_images.append(img_as_ubyte(im))

        self.reset_show_images()

        # Loading manual parameters here
        man_ori_path = os.path.join(self.par_path, 'man_ori.par')

        f = open(man_ori_path, 'r')
        if f is None:
            print('\n Error loading man_ori.par')
        else:
            for i in range(len(self.camera)):
                for j in range(4):
                    self.camera[i].man_ori[j] = int(f.readline().strip())
        f.close()

        self.pass_init = True
        self.status_text = "Initialization finished."
Esempio n. 7
0
 def syncActiveDir(self):
     par.copy_params_dir(self.active_params.par_path, par.par_dir_prefix)