def paramsFactory(filename, n_img, n_pts=4): if filename == "ptv.par": return parameters.PtvParams() if filename == "cal_ori.par": return parameters.CalOriParams(n_img) if filename == "sequence.par": return parameters.SequenceParams(n_img) if filename == "criteria.par": return parameters.CriteriaParams() if filename == "targ_rec.par": return parameters.TargRecParams(n_img) if filename == "man_ori.par": return parameters.ManOriParams(n_img, n_pts) if filename == "detect_plate.par": return parameters.DetectPlateParams() if filename == "orient.par": return parameters.OrientParams() if filename == "track.par": return parameters.TrackingParams() if filename == "pft_version.par": return parameters.PftVersionParams() if filename == "examine.par": return parameters.ExamineParams() if filename == "dumbbell.par": return parameters.DumbbellParams() if filename == "shaking.par": return parameters.ShakingParams() return None
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()
def py_detection_proc_c(list_of_images, cpar, tpar, cals): """ Detection of targets """ pftVersionParams = par.PftVersionParams(path='./parameters') pftVersionParams.read() Existing_Target = np.bool(pftVersionParams.Existing_Target) detections, corrected = [],[] for i_cam, img in enumerate(list_of_images): if Existing_Target: targs = read_targets(cpar.get_img_base_name(i_cam),0) else: targs = target_recognition(img, tpar, i_cam, cpar) targs.sort_y() detections.append(targs) mc = MatchedCoords(targs, cpar, cals[i_cam]) corrected.append(mc) return detections, corrected
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
def _reload(self): # load ptv_par ptvParams = par.PtvParams(path=self.par_path) ptvParams.read() (n_img, img_name, img_cal, hp_flag, allCam_flag, tiff_flag, imx, imy, pix_x, pix_y, chfield, mmp_n1, mmp_n2, mmp_n3, mmp_d) = \ (ptvParams.n_img, ptvParams.img_name, ptvParams.img_cal, ptvParams.hp_flag, ptvParams.allCam_flag, ptvParams.tiff_flag, ptvParams.imx, ptvParams.imy, ptvParams.pix_x, ptvParams.pix_y, ptvParams.chfield, ptvParams.mmp_n1, ptvParams.mmp_n2, ptvParams.mmp_n3, ptvParams.mmp_d) self.Name_1_Image = img_name[0] self.Name_2_Image = img_name[1] self.Name_3_Image = img_name[2] self.Name_4_Image = img_name[3] self.Cali_1_Image = img_cal[0] self.Cali_2_Image = img_cal[1] self.Cali_3_Image = img_cal[2] self.Cali_4_Image = img_cal[3] self.Refr_Air = mmp_n1 self.Refr_Glass = mmp_n2 self.Refr_Water = mmp_n3 self.Thick_Glass = mmp_d self.Accept_OnlyAllCameras = n.bool(allCam_flag) self.Num_Cam = n_img self.HighPass = n.bool(hp_flag) # load unused self.tiff_flag = n.bool(tiff_flag) self.imx = imx self.imy = imy self.pix_x = pix_x self.pix_y = pix_y self.chfield = chfield # read_calibration parameters calOriParams = par.CalOriParams(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) self.pair_Flag = n.bool(pair_flag) self.img_cal_name = img_cal_name self.img_ori = img_ori self.fixp_name = fixp_name # load read_targ_rec targRecParams = par.TargRecParams(n_img, path=self.par_path) targRecParams.read() (gvthres, disco, nnmin, nnmax, nxmin, nxmax, nymin, nymax, sumg_min, cr_sz) = \ (targRecParams.gvthres, targRecParams.disco, targRecParams.nnmin, targRecParams.nnmax, targRecParams.nxmin, targRecParams.nxmax, targRecParams.nymin, targRecParams.nymax, targRecParams.sumg_min, targRecParams.cr_sz) self.Gray_Tresh_1 = gvthres[0] self.Gray_Tresh_2 = gvthres[1] self.Gray_Tresh_3 = gvthres[2] self.Gray_Tresh_4 = gvthres[3] self.Min_Npix = nnmin self.Max_Npix = nnmax self.Min_Npix_x = nxmin self.Max_Npix_x = nxmax self.Min_Npix_y = nymin self.Max_Npix_y = nymax self.Sum_Grey = sumg_min self.Tol_Disc = disco self.Size_Cross = cr_sz # load pft_version pftVersionParams = par.PftVersionParams(path=self.par_path) pftVersionParams.read() self.Existing_Target = n.bool(pftVersionParams.Existing_Target) # load sequence_par sequenceParams = par.SequenceParams(n_img, path=self.par_path) sequenceParams.read() (base_name, first, last) = \ (sequenceParams.base_name, sequenceParams.first, sequenceParams.last) self.Basename_1_Seq = base_name[0] self.Basename_2_Seq = base_name[1] self.Basename_3_Seq = base_name[2] self.Basename_4_Seq = base_name[3] self.Seq_First = first self.Seq_Last = last # load criteria_par criteriaParams = par.CriteriaParams(path=self.par_path) criteriaParams.read() (X_lay, Zmin_lay, Zmax_lay, cnx, cny, cn, csumg, corrmin, eps0) = \ (criteriaParams.X_lay, criteriaParams.Zmin_lay, criteriaParams.Zmax_lay, criteriaParams.cnx, criteriaParams.cny, criteriaParams.cn, criteriaParams.csumg, criteriaParams.corrmin, criteriaParams.eps0) self.Xmin = X_lay[0] self.Xmax = X_lay[1] self.Zmin1 = Zmin_lay[0] self.Zmin2 = Zmin_lay[1] self.Zmax1 = Zmax_lay[0] self.Zmax2 = Zmax_lay[1] self.Min_Corr_nx = cnx self.Min_Corr_ny = cny self.Min_Corr_npix = cn self.Sum_gv = csumg self.Min_Weight_corr = corrmin self.Tol_Band = eps0
def py_sequence_loop(exp): """ Runs a sequence of detection, stereo-correspondence, determination and stores the data in the cam#.XXX_targets (rewritten) and rt_is.XXX files. Basically it is to run the batch as in pyptv_batch.py without tracking """ n_cams, cpar, spar, vpar, tpar, cals = \ exp.n_cams, exp.cpar, exp.spar, exp.vpar, exp.tpar, exp.cals pftVersionParams = par.PftVersionParams(path='./parameters') pftVersionParams.read() Existing_Target = np.bool(pftVersionParams.Existing_Target) # sequence loop for all frames for frame in range(spar.get_first(), spar.get_last()+1): print("processing frame %d" % frame) detections = [] corrected = [] for i_cam in range(n_cams): if Existing_Target: targs = read_targets(spar.get_img_base_name(i_cam),frame) else: imname = spar.get_img_base_name(i_cam) + str(frame).encode() print(imname) if not os.path.exists(imname): print(os.path.abspath(os.path.curdir)) print('{0} does not exist'.format(imname)) img = imread(imname.decode()) # time.sleep(.1) # I'm not sure we need it here hp = simple_highpass(img, cpar) targs = target_recognition(hp, tpar, i_cam, cpar) targs.sort_y() detections.append(targs) mc = MatchedCoords(targs, cpar, cals[i_cam]) pos, pnr = mc.as_arrays() corrected.append(mc) # if any([len(det) == 0 for det in detections]): # return False # Corresp. + positions. sorted_pos, sorted_corresp, num_targs = correspondences( detections, corrected, cals, vpar, cpar) # Save targets only after they've been modified: for i_cam in range(n_cams): detections[i_cam].write(spar.get_img_base_name(i_cam),frame) print("Frame " + str(frame) + " had " \ + repr([s.shape[1] for s in sorted_pos]) + " correspondences.") # Distinction between quad/trip irrelevant here. sorted_pos = np.concatenate(sorted_pos, axis=1) sorted_corresp = np.concatenate(sorted_corresp, axis=1) flat = np.array([corrected[i].get_by_pnrs(sorted_corresp[i]) \ for i in range(len(cals))]) pos, rcm = point_positions( flat.transpose(1,0,2), cpar, cals, vpar) # if len(cals) == 1: # single camera case # sorted_corresp = np.tile(sorted_corresp,(4,1)) # sorted_corresp[1:,:] = -1 if len(cals) < 4: print_corresp = -1*np.ones((4,sorted_corresp.shape[1])) print_corresp[:len(cals),:] = sorted_corresp else: print_corresp = sorted_corresp # Save rt_is print(default_naming['corres']) rt_is = open(default_naming['corres']+b'.'+ str(frame).encode(), 'w') rt_is.write(str(pos.shape[0]) + '\n') for pix, pt in enumerate(pos): pt_args = (pix + 1,) + tuple(pt) + tuple(print_corresp[:,pix]) rt_is.write("%4d %9.3f %9.3f %9.3f %4d %4d %4d %4d\n" % pt_args) rt_is.close()