Beispiel #1
0
def make_report(traj_3d, cam_top, cam_left, template):
    """Generates a report of the post-processed values as well as the parameters used to extract the trajectory.
    Also saves the trajectory.

    :param traj_3d: Experiment object
    :param cam_top,cam_left: camera objects used for the trajectory determination
    :param template: name of the template to use for the report
    """
    if traj_3d.save_dir == '':
        popupmsg('Empty file name')
        return 0
    vi_norm = np.sqrt(traj_3d.vinit[0]**2 + traj_3d.vinit[1]**2 +
                      traj_3d.vinit[2]**2)
    vo_norm = np.sqrt(traj_3d.vend[0]**2 + traj_3d.vend[1]**2 +
                      traj_3d.vend[2]**2)
    dimp = traj_3d.yerr[traj_3d.impact_i]
    make_template_file(template, traj_3d.save_dir, [
        traj_3d.save_dir, cam_top.firstPic, cam_top.framerate, cam_top.res,
        traj_3d.sample, traj_3d.shot, traj_3d.pressure, traj_3d.alpha,
        traj_3d.vinit[0], traj_3d.vinit[1], traj_3d.vinit[2], vi_norm,
        traj_3d.vend[0], traj_3d.vend[1], traj_3d.vend[2], vo_norm,
        traj_3d.impact_pos[0], traj_3d.impact_pos[1], traj_3d.impact_pos[2],
        dimp
    ], [
        'testName', 'picName', 'fps', 'res', 'sample', 'shot', 'pressure',
        'angle', 'VX', 'VY', 'VZ', 'ViNorm', 'VXAfter', 'VYAfter', 'VZAfter',
        'VoNorm', 'X', 'Y', 'Z', 'dimp'
    ])
    data_save(traj_3d, cam_top, cam_left)
Beispiel #2
0
def save_res(cam_top, cam_left, T, traj_3d, fileSave):
    """Saves the results and make a report

    :param cam_top,cam_left: top and left camera objects
    :param T: Text canvas to log the results
    :param traj_3d: Experiment object
    :param fileSave: report save directory
    """
    list_pic = os.listdir('data_treat')
    try:
        traj_3d.save_dir = fileSave[0][1].get()
        if 'Angle.png' in list_pic:
            move_file('data_treat/Angle.png', parse_dir(traj_3d.save_dir))
        if 'Impact_position.png' in list_pic:
            move_file('data_treat/Impact_position.png',
                      parse_dir(traj_3d.save_dir))
        if 'Velocity.png' in list_pic:
            move_file('data_treat/Velocity.png', parse_dir(traj_3d.save_dir))
        if 'Reproj_error.png' in list_pic:
            move_file('data_treat/Reproj_error.png',
                      parse_dir(traj_3d.save_dir))

        make_report(traj_3d, cam_top, cam_left,
                    "data_treat/report_template.txt")
        log = '\nTrajectory exported as ' + traj_3d.save_dir
        T.insert(tk.END, log)

    except:
        popupmsg("Wrong save directory")
    else:
        popupmsg("File saved successfully !")
Beispiel #3
0
def set_mask(cam, form):
    """Generate the subwindow to set a camera mask

    :param cam: camera object
    :param form: camera form values to get the first picture path
    """
    mask_w = tk.IntVar()
    mask_h = tk.IntVar()

    cam_pics = glob.glob(form[1][1].get() + "/*.tif")
    if len(cam_pics) == 0:
        cam_pics = glob.glob(form[1][1].get() + "/*.jpg")
    try:
        im_act = Image.open(cam_pics[0])
    except:
        popupmsg("Wrong camera picture folder name")
    else:
        root = tk.Tk()
        root.title("Set mask")
        root.geometry("600x600")
        root.wm_iconbitmap('gui/logo-lm2-f_0.ico')
        fig = Figure(figsize=(5, 4), dpi=100)
        im_act = np.array(im_act)
        fig_plot = fig.add_subplot(111).imshow(im_act)
        canvas = FigureCanvasTkAgg(fig, master=root)
        canvas.draw()
        canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
        toolbar = NavigationToolbar2Tk(canvas, root)
        toolbar.update()
        canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)

        wd_lab = tk.Label(root, text="width")
        mask_val_w = tk.Scale(
            root,
            from_=0,
            to=im_act.shape[1],
            orient=tk.HORIZONTAL,
            variable=mask_w,
            command=(
                lambda ma=mask_w, p=im_act, c=canvas: update_fig(ma, p, c, 0)))
        wd_lab.pack(side=tk.LEFT)
        mask_val_w.pack(side=tk.LEFT)

        hi_lab = tk.Label(root, text="height")
        mask_val_h = tk.Scale(
            root,
            from_=0,
            to=im_act.shape[0],
            orient=tk.HORIZONTAL,
            variable=mask_h,
            command=(
                lambda ma=mask_h, p=im_act, c=canvas: update_fig(ma, p, c, 1)))
        hi_lab.pack(side=tk.LEFT)
        mask_val_h.pack(side=tk.LEFT)

        b1 = tk.Button(root,
                       text='Set mask',
                       command=(lambda r=root, c=cam, mw=mask_val_w, mh=
                                mask_val_h: set_cam_mask(r, c, mw, mh)))
        b1.pack()
Beispiel #4
0
def delete_pic(pic_path):
    if platform.system() == 'Windows':
        pic_path = pic_path.replace('/', '\\')
        os.system('del ' + pic_path)
    elif platform.system() == 'Linux':
        os.system('rm -rf ' + pic_path)
    else:
        popupmsg(
            "Unknown OS, I cannot save the pictures. You may find them in the data_treat folder directly..."
        )
Beispiel #5
0
def move_file(init, end):
    """Moves a file using either batch or shell command according to the current os (Windows or Linux only)

    :param init: path of the file to move
    :param end: target directory path
    """
    if platform.system() == 'Windows':
        init = init.replace('/', '\\')
        end = end.replace('/', '\\')
        os.system('copy ' + init + ' ' + end)
    elif platform.system() == 'Linux':
        os.system('scp -r ' + init + ' ' + end)
    else:
        popupmsg(
            "Unknown OS, I cannot save the pictures. You may find them in the data_treat folder directly..."
        )
Beispiel #6
0
def start_load(notebook, f, tra, ct, cl):
    """loads an analysis by initializing the cameras and experiment objects

    :param notebook: notebook object the tab belongs to (enables the pp mode)
    :param f: form entries
    :param tra: Experiment object
    :param ct,cl: camera_top and left objects
    """

    try:
        load_data(f.get(), tra, ct, cl)
    except:
        notebook.tab(3, state='disabled')
        popupmsg('File not found...')
    else:
        notebook.tab(3, state='normal')
        popupmsg('Data successfully loaded !')
Beispiel #7
0
def launch_calib(entries, numcase, lencase):
    """Launch calibration procedure

    :param entries: calibration form entries
    :param numcase: number of checkboard case form object
    :param lencase: length of a checkboard case form object
    """
    try:
        calibrate_stereo(entries[0][1].get(),
                         entries[1][1].get(),
                         entries[2][1].get(),
                         entries[3][1].get(),
                         entries[4][1].get(),
                         chess_dim=int(numcase.get()),
                         chess_case_len=float(lencase.get()))
    except CalibrationError as err:
        popupmsg(err)
Beispiel #8
0
def launch_analysis(top_entry, left_entry, notebook, method, cam_top, cam_left,
                    traj_3d, show_traj, ratTop, ratLeft, isbatch, batch_folder,
                    exp_param):
    """Launch a 3D trajectory analysis

    :param top_entry,left_entry: form entries for the top and left cameras
    :param notebook: GUI notebook object (to enable the pp tab at the end
    :param method: analysis method combobox object
    :param cam_top,cam_left: camera top and left objects
    :param traj_3d: Experiment object
    :param show_traj: Trajectory display checkbox object
    :param ratTop,ratLeft: pixel to cm ratio form objects for the top and left cameras
    :param isbatch: checkbox object enabling (or not) batch mode
    :param batch_folder: batch folder path form object
    :param exp_param: experimental parameter form object
    :return:
    """

    traj_3d.set_exp_params(exp_param[0][1].get(), exp_param[1][1].get(),
                           exp_param[2][1].get(), "Trajectory.txt")

    if method.get() == "No perspective":
        meth = 'no-persp'
    elif method.get() == "Perspective simple":
        meth = 'persp'
    else:
        meth = 'persp-opti'

    if isbatch.get():
        foldList = os.listdir(batch_folder.get())
        ana_fold = batch_folder.get() + '/'
        if 'RESULTS' in foldList:
            foldList.remove('RESULTS')
        os.system('cd ' + ana_fold + ' && mkdir RESULTS')
        savedir = ana_fold + 'RESULTS/'
    else:
        foldList = ['']
        ana_fold = ''
        savedir = 'data_treat/Reproj_error.png'

    for elem in foldList:
        print("************ " + elem)
        try:
            if meth == 'no-persp':
                ptc_top = float(ratTop.get())
                ptc_left = float(ratLeft.get())
            else:
                ptc_top = None
                ptc_left = None
            create_camera(top_entry, 'top', cam_top, ptc_top)
            create_camera(left_entry, 'left', cam_left, ptc_left)
            if not elem == '':
                cam_top.dir = ana_fold + elem + '/' + cam_top.dir
                cam_left.dir = ana_fold + elem + '/' + cam_left.dir
            cam_top.set_crop_size()
            cam_left.set_crop_size()

        except NameError:
            popupmsg(
                "One of the camera folder name you entered was either incorrect or empty."
            )

        else:
            if isbatch.get():
                savedir += elem + '_reproj.png'
            #try:
            X, Y, Z, timespan, err = reconstruct_3d(cam_top,
                                                    cam_left,
                                                    splitSymb="_",
                                                    numsplit=-1,
                                                    method=meth,
                                                    plotTraj=show_traj.get(),
                                                    plot=not (isbatch.get()),
                                                    isgui=True,
                                                    savedir=savedir)
            #except:
            notebook.tab(3, state='disable')
            #popupmsg("Something went wrong in the analysis. Check out the console messages for more detail.")
            #else:
            traj_3d.set_trajectory(timespan, X, Y, Z, yerr=err)
            notebook.tab(3, state='normal')
            if isbatch.get():
                try:
                    alpha = get_init_angle(X,
                                           Y,
                                           Z,
                                           timespan,
                                           cam_top,
                                           cam_left,
                                           plot=False,
                                           saveDir=ana_fold + 'RESULTS\\' +
                                           elem + '-',
                                           init=traj_3d.ang_min_ind,
                                           end=traj_3d.ang_end_ind)
                    xi, yi, zi, imp_i = get_impact_position(
                        X,
                        Y,
                        Z,
                        cam_left,
                        cam_top,
                        plot=False,
                        saveDir=ana_fold + 'RESULTS\\' + elem + '-',
                        threshold=traj_3d.imp_thres)
                    Vinit, Vend = get_velocity(timespan,
                                               X,
                                               Y,
                                               Z,
                                               thres=traj_3d.vel_det_fac,
                                               plot=False,
                                               saveDir=ana_fold + 'RESULTS\\' +
                                               elem + '-',
                                               init=traj_3d.vel_init_ind,
                                               pt_num=traj_3d.vel_min_pt)
                except:
                    popupmsg(
                        "Wrong batch post-processing parameters. Please adjust."
                    )
                else:
                    traj_3d.set_pp(alpha, Vinit, Vend, [xi, yi, zi], imp_i)
                    traj_3d.save_dir = ana_fold + 'RESULTS/' + elem + '.txt'
                    make_report(traj_3d, cam_top, cam_left,
                                "data_treat/report_template.txt")