Example #1
0
 def backup_ori_files(self):
     """ backup ORI/ADDPAR files to the backup_cal directory """
     calOriParams = par.CalOriParams(self.n_cams, path=self.par_path)
     calOriParams.read()
     for f in calOriParams.img_ori[:self.n_cams]:
         shutil.copyfile(f, f + '.bck')
         g = f.replace('ori', 'addpar')
         shutil.copyfile(g, g + '.bck')
Example #2
0
    def restore_ori_files(self):
        # backup ORI/ADDPAR files to the backup_cal directory
        calOriParams = par.CalOriParams(self.n_cams, path=self.par_path)
        calOriParams.read()

        for f in calOriParams.img_ori[:self.n_cams]:
            print('restored %s ' % f)
            shutil.copyfile(f + '.bck', f)
            g = f.replace('ori', 'addpar')
            shutil.copyfile(g + '.bck', g)
Example #3
0
 def configure_cal_par(self, editor, object):
     experiment = editor.get_parent(object)
     paramset = object
     print(len(experiment.paramsets))
     if paramset.c_params is None:
         # TODO: is it possible that control reaches here? If not, probably the if should be removed.
         paramset.c_params = par.CalOriParams() # this is a very questionable line
     else:
         paramset.c_params._reload()
     paramset.c_params.edit_traits(kind='modal')
Example #4
0
 def protect_ori_files(self):
     # backup ORI/ADDPAR files to the backup_cal directory
     calOriParams = par.CalOriParams(self.n_cams, path=self.par_path)
     calOriParams.read()
     for f in calOriParams.img_ori[:self.n_cams]:
         with open(f, 'r') as d:
             d.read().split()
             if not np.all(np.isfinite(np.asarray(d).astype(
                     'f'))):  # if there NaN for instance
                 print("protected ORI file %s " % f)
                 shutil.copyfile(f + '.bck', f)
Example #5
0
    def __init__(self, path):
        # load ptv_par
        ptvParams = par.PtvParams(path=path)
        ptvParams.read()
        self.n_img = ptvParams.n_img

        # load cal_ori
        calOriParams = par.CalOriParams(self.n_img, path=path)
        calOriParams.read()

        for i in range(self.n_img):
            self.oriEditors.append(oriEditor(get_path(
                calOriParams.img_ori[i])))
Example #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."
Example #7
0
    def _reload(self):
        # print("reloading")
        # self.__init__(self)
        # load ptv_par
        ptvParams = par.PtvParams(path=self.par_path)
        ptvParams.read()

        # read picture size parameters
        self.h_image_size = ptvParams.imx
        self.v_image_size = ptvParams.imy
        self.h_pixel_size = ptvParams.pix_x
        self.v_pixel_size = ptvParams.pix_y
        self.img_cal = ptvParams.img_cal
        if ptvParams.allCam_flag:
            self.pair_enable_flag = False
        else:
            self.pair_enable_flag = True

        # unesed parameters

        self.n_img = ptvParams.n_img
        self.img_name = ptvParams.img_name
        self.hp_flag = np.bool(ptvParams.hp_flag)
        self.allCam_flag = np.bool(ptvParams.allCam_flag)
        self.mmp_n1 = ptvParams.mmp_n1
        self.mmp_n2 = ptvParams.mmp_n2
        self.mmp_n3 = ptvParams.mmp_n3
        self.mmp_d = ptvParams.mmp_d

        # read_calibration parameters
        calOriParams = par.CalOriParams(self.n_img, path=self.par_path)
        calOriParams.read()
        (fixp_name, img_cal_name, img_ori, tiff_flag, pair_flag, chfield) = \
            (calOriParams.fixp_name, calOriParams.img_cal_name, calOriParams.img_ori,
             calOriParams.tiff_flag, calOriParams.pair_flag, calOriParams.chfield)

        for i in range(self.n_img):
            exec("self.cam_{0} = calOriParams.img_cal_name[{1}]".format(
                i + 1, i))
            exec("self.ori_cam_{0} = calOriParams.img_ori[{1}]".format(
                i + 1, i))

        self.tiff_head = np.bool(tiff_flag)
        self.pair_head = np.bool(pair_flag)
        self.fixp_name = fixp_name
        if chfield == 0:
            self.chfield = "Frame"
        elif chfield == 1:
            self.chfield = "Field odd"
        else:
            self.chfield = "Field even"

        # read detect plate parameters
        detectPlateParams = par.DetectPlateParams(path=self.par_path)
        detectPlateParams.read()

        (gv_th1, gv_th2, gv_th3, gv_th4, tolerable_discontinuity, min_npix, max_npix, min_npix_x,
            max_npix_x, min_npix_y, max_npix_y, sum_of_grey, size_of_crosses) = \
            (detectPlateParams.gvth_1, detectPlateParams.gvth_2, detectPlateParams.gvth_3, detectPlateParams.gvth_4,
             detectPlateParams.tol_dis, detectPlateParams.min_npix, detectPlateParams.max_npix, detectPlateParams.min_npix_x,
             detectPlateParams.max_npix_x, detectPlateParams.min_npix_y, detectPlateParams.max_npix_y, detectPlateParams.sum_grey,
             detectPlateParams.size_cross)

        for i in range(self.n_img):
            exec('self.grey_value_treshold_{0} = gv_th{0}'.format(i + 1))

        self.tolerable_discontinuity = tolerable_discontinuity
        self.min_npix = min_npix
        self.min_npix_x = min_npix_x
        self.min_npix_y = min_npix_y
        self.max_npix = max_npix
        self.max_npix_x = max_npix_x
        self.max_npix_y = max_npix_y
        self.sum_of_grey = sum_of_grey
        self.size_of_crosses = size_of_crosses

        # read manual orientaion parameters
        manOriParams = par.ManOriParams(self.n_img, [], path=self.par_path)
        manOriParams.read()

        for i in range(self.n_img):
            for j in range(4):  # 4 points per image
                exec(f"self.img_{i+1}_p{j+1} = manOriParams.nr[{i*4+j}]")

        # examine arameters
        examineParams = par.ExamineParams(path=self.par_path)
        examineParams.read()
        (self.Examine_Flag, self.Combine_Flag) = (examineParams.Examine_Flag,
                                                  examineParams.Combine_Flag)

        # orientation parameters
        orientParams = par.OrientParams(path=self.par_path)
        orientParams.read()
        (po_num_of_ori, cc, xh, yh, k1, k2, k3, p1, p2, scale, shear, interf) = \
            (orientParams.pnfo, orientParams.cc, orientParams.xh, orientParams.yh, orientParams.k1, orientParams.k2, orientParams.k3,
             orientParams.p1, orientParams.p2, orientParams.scale, orientParams.shear, orientParams.interf)

        self.point_number_of_orientation = po_num_of_ori
        self.cc = np.bool(cc)
        self.xh = np.bool(xh)
        self.yh = np.bool(yh)
        self.k1 = np.bool(k1)
        self.k2 = np.bool(k2)
        self.k3 = np.bool(k3)
        self.p1 = np.bool(p1)
        self.p2 = np.bool(p2)
        self.scale = np.bool(scale)
        self.shear = np.bool(shear)
        self.interf = np.bool(interf)

        dumbbellParams = par.DumbbellParams(path=self.par_path)
        dumbbellParams.read()
        (self.dumbbell_eps, self.dumbbell_scale, self.dumbbell_gradient_descent,
            self.dumbbell_penalty_weight, self.dumbbell_step, self.dumbbell_niter) = \
            (dumbbellParams.dumbbell_eps, dumbbellParams.dumbbell_scale,
             dumbbellParams.dumbbell_gradient_descent, dumbbellParams.dumbbell_penalty_weight,
             dumbbellParams.dumbbell_step, dumbbellParams.dumbbell_niter)

        shakingParams = par.ShakingParams(path=self.par_path)
        shakingParams.read()
        (self.shaking_first_frame, self.shaking_last_frame,
         self.shaking_max_num_points,
         self.shaking_max_num_frames) = (shakingParams.shaking_first_frame,
                                         shakingParams.shaking_last_frame,
                                         shakingParams.shaking_max_num_points,
                                         shakingParams.shaking_max_num_frames)
Example #8
0
    def _reload(self):
        # load ptv_par
        ptvParams = par.PtvParams(path=self.par_path)
        ptvParams.read()

        for i in range(ptvParams.n_img):
            exec('self.Name_%d_Image = ptvParams.img_name[%d]' % (i + 1, i))
            exec('self.Cali_%d_Image = ptvParams.img_cal[%d]' % (i + 1, i))

        self.Refr_Air = ptvParams.mmp_n1
        self.Refr_Glass = ptvParams.mmp_n2
        self.Refr_Water = ptvParams.mmp_n3
        self.Thick_Glass = ptvParams.mmp_d
        self.Accept_OnlyAllCameras = np.bool(ptvParams.allCam_flag)
        self.Num_Cam = ptvParams.n_img
        self.HighPass = np.bool(ptvParams.hp_flag)
        # load unused
        self.tiff_flag = np.bool(ptvParams.tiff_flag)
        self.imx = ptvParams.imx
        self.imy = ptvParams.imy
        self.pix_x = ptvParams.pix_x
        self.pix_y = ptvParams.pix_y
        self.chfield = ptvParams.chfield

        # read_calibration parameters
        calOriParams = par.CalOriParams(ptvParams.n_img, path=self.par_path)
        calOriParams.read()

        self.pair_Flag = np.bool(calOriParams.pair_flag)
        self.img_cal_name = calOriParams.img_cal_name
        self.img_ori = calOriParams.img_ori
        self.fixp_name = calOriParams.fixp_name

        # load read_targ_rec
        targRecParams = par.TargRecParams(ptvParams.n_img, path=self.par_path)
        targRecParams.read()

        for i in range(ptvParams.n_img):
            exec("self.Gray_Tresh_{0} = targRecParams.gvthres[{1}]".format(
                i + 1, i))

        self.Min_Npix = targRecParams.nnmin
        self.Max_Npix = targRecParams.nnmax
        self.Min_Npix_x = targRecParams.nxmin
        self.Max_Npix_x = targRecParams.nxmax
        self.Min_Npix_y = targRecParams.nymin
        self.Max_Npix_y = targRecParams.nymax
        self.Sum_Grey = targRecParams.sumg_min
        self.Tol_Disc = targRecParams.disco
        self.Size_Cross = targRecParams.cr_sz

        # load pft_version
        pftVersionParams = par.PftVersionParams(path=self.par_path)
        pftVersionParams.read()
        self.Existing_Target = np.bool(pftVersionParams.Existing_Target)

        # load sequence_par
        sequenceParams = par.SequenceParams(ptvParams.n_img,
                                            path=self.par_path)
        sequenceParams.read()

        for i in range(ptvParams.n_img):
            exec(
                "self.Basename_{0}_Seq = sequenceParams.base_name[{1}]".format(
                    i + 1, i))

        self.Seq_First = sequenceParams.first
        self.Seq_Last = sequenceParams.last

        # load criteria_par
        criteriaParams = par.CriteriaParams(path=self.par_path)
        criteriaParams.read()
        self.Xmin = criteriaParams.X_lay[0]
        self.Xmax = criteriaParams.X_lay[1]
        self.Zmin1 = criteriaParams.Zmin_lay[0]
        self.Zmin2 = criteriaParams.Zmin_lay[1]
        self.Zmax1 = criteriaParams.Zmax_lay[0]
        self.Zmax2 = criteriaParams.Zmax_lay[1]
        self.Min_Corr_nx = criteriaParams.cnx
        self.Min_Corr_ny = criteriaParams.cny
        self.Min_Corr_npix = criteriaParams.cn
        self.Sum_gv = criteriaParams.csumg
        self.Min_Weight_corr = criteriaParams.corrmin
        self.Tol_Band = criteriaParams.eps0
Example #9
0
    def closed(self, info, is_ok):
        mainParams = info.object
        par_path = mainParams.par_path
        Handler.closed(self, info, is_ok)
        if is_ok:
            img_name = [
                mainParams.Name_1_Image, mainParams.Name_2_Image,
                mainParams.Name_3_Image, mainParams.Name_4_Image
            ]
            img_cal_name = [
                mainParams.Cali_1_Image, mainParams.Cali_2_Image,
                mainParams.Cali_3_Image, mainParams.Cali_4_Image
            ]

            gvthres = [
                mainParams.Gray_Tresh_1, mainParams.Gray_Tresh_2,
                mainParams.Gray_Tresh_3, mainParams.Gray_Tresh_4
            ]
            base_name = [
                mainParams.Basename_1_Seq, mainParams.Basename_2_Seq,
                mainParams.Basename_3_Seq, mainParams.Basename_4_Seq
            ]
            X_lay = [mainParams.Xmin, mainParams.Xmax]
            Zmin_lay = [mainParams.Zmin1, mainParams.Zmin2]
            Zmax_lay = [mainParams.Zmax1, mainParams.Zmax2]

            # write ptv_par
            par.PtvParams(mainParams.Num_Cam,
                          img_name,
                          img_cal_name,
                          mainParams.HighPass,
                          mainParams.Accept_OnlyAllCameras,
                          mainParams.tiff_flag,
                          mainParams.imx,
                          mainParams.imy,
                          mainParams.pix_x,
                          mainParams.pix_y,
                          mainParams.chfield,
                          mainParams.Refr_Air,
                          mainParams.Refr_Glass,
                          mainParams.Refr_Water,
                          mainParams.Thick_Glass,
                          path=par_path).write()
            # write calibration parameters
            par.CalOriParams(mainParams.Num_Cam,
                             mainParams.fixp_name,
                             mainParams.img_cal_name,
                             mainParams.img_ori,
                             mainParams.tiff_flag,
                             mainParams.pair_Flag,
                             mainParams.chfield,
                             path=par_path).write()

            # write targ_rec_par
            par.TargRecParams(mainParams.Num_Cam,
                              gvthres,
                              mainParams.Tol_Disc,
                              mainParams.Min_Npix,
                              mainParams.Max_Npix,
                              mainParams.Min_Npix_x,
                              mainParams.Max_Npix_x,
                              mainParams.Min_Npix_y,
                              mainParams.Max_Npix_y,
                              mainParams.Sum_Grey,
                              mainParams.Size_Cross,
                              path=par_path).write()
            # write pft_version_par
            par.PftVersionParams(mainParams.Existing_Target,
                                 path=par_path).write()
            # write sequence_par
            par.SequenceParams(mainParams.Num_Cam,
                               base_name,
                               mainParams.Seq_First,
                               mainParams.Seq_Last,
                               path=par_path).write()
            # write criteria_par
            par.CriteriaParams(X_lay,
                               Zmin_lay,
                               Zmax_lay,
                               mainParams.Min_Corr_nx,
                               mainParams.Min_Corr_ny,
                               mainParams.Min_Corr_npix,
                               mainParams.Sum_gv,
                               mainParams.Min_Weight_corr,
                               mainParams.Tol_Band,
                               path=par_path).write()
Example #10
0
    def closed(self, info, is_ok):
        calibParams = info.object
        par_path = calibParams.par_path
        print("inside CalHandler ", par_path)
        Handler.closed(self, info, is_ok)
        if is_ok:
            img_cal_name = [
                calibParams.cam_1, calibParams.cam_2, calibParams.cam_3,
                calibParams.cam_4
            ]
            img_ori = [
                calibParams.ori_cam_1, calibParams.ori_cam_2,
                calibParams.ori_cam_3, calibParams.ori_cam_4
            ]
            nr1 = [
                calibParams.img_1_p1, calibParams.img_1_p2,
                calibParams.img_1_p3, calibParams.img_1_p4
            ]
            nr2 = [
                calibParams.img_2_p1, calibParams.img_2_p2,
                calibParams.img_2_p3, calibParams.img_2_p4
            ]
            nr3 = [
                calibParams.img_3_p1, calibParams.img_3_p2,
                calibParams.img_3_p3, calibParams.img_3_p4
            ]
            nr4 = [
                calibParams.img_4_p1, calibParams.img_4_p2,
                calibParams.img_4_p3, calibParams.img_4_p4
            ]

            nr = [nr1, nr2, nr3, nr4]

            if (calibParams.chfield == "Frame"):
                chfield = 0
            elif (calibParams.chfield == "Field odd"):
                chfield = 1
            else:
                chfield = 2
            par.PtvParams(calibParams.n_img,
                          calibParams.img_name,
                          calibParams.img_cal,
                          calibParams.hp_flag,
                          calibParams.allCam_flag,
                          calibParams.tiff_head,
                          calibParams.h_image_size,
                          calibParams.v_image_size,
                          calibParams.h_pixel_size,
                          calibParams.v_pixel_size,
                          chfield,
                          calibParams.mmp_n1,
                          calibParams.mmp_n2,
                          calibParams.mmp_n3,
                          calibParams.mmp_d,
                          path=par_path).write()

            par.CalOriParams(calibParams.n_img,
                             calibParams.fixp_name,
                             img_cal_name,
                             img_ori,
                             calibParams.tiff_head,
                             calibParams.pair_head,
                             chfield,
                             path=par_path).write()

            par.DetectPlateParams(calibParams.grey_value_treshold_1,
                                  calibParams.grey_value_treshold_2,
                                  calibParams.grey_value_treshold_3,
                                  calibParams.grey_value_treshold_4,
                                  calibParams.tolerable_discontinuity,
                                  calibParams.min_npix,
                                  calibParams.max_npix,
                                  calibParams.min_npix_x,
                                  calibParams.max_npix_x,
                                  calibParams.min_npix_y,
                                  calibParams.max_npix_y,
                                  calibParams.sum_of_grey,
                                  calibParams.size_of_crosses,
                                  path=par_path).write()

            par.ManOriParams(calibParams.n_img, nr, path=par_path).write()
            par.ExamineParams(calibParams.Examine_Flag,
                              calibParams.Combine_Flag,
                              path=par_path).write()
            par.OrientParams(calibParams.point_number_of_orientation,
                             calibParams.cc,
                             calibParams.xh,
                             calibParams.yh,
                             calibParams.k1,
                             calibParams.k2,
                             calibParams.k3,
                             calibParams.p1,
                             calibParams.p2,
                             calibParams.scale,
                             calibParams.shear,
                             calibParams.interf,
                             path=par_path).write()
            par.ShakingParams(calibParams.shaking_first_frame,
                              calibParams.shaking_last_frame,
                              calibParams.shaking_max_num_points,
                              calibParams.shaking_max_num_frames,
                              path=par_path).write()

            par.DumbbellParams(calibParams.dumbbell_eps,
                               calibParams.dumbbell_scale,
                               calibParams.dumbbell_gradient_descent,
                               calibParams.dumbbell_penalty_weight,
                               calibParams.dumbbell_step,
                               calibParams.dumbbell_niter,
                               path=par_path).write()