Esempio n. 1
0
    def circle_plane(self):
        x0 = np.array([1.0, 2.0])
        lam0 = 1.0
        rho0 = 0.1
        funcs = (val_c, grad_c, hess_c, val_ff, grad_ff, hess_ff)
        args_f = ()
        x_opt, val_opt, iterations, lam_opt, rho_opt = filterSQP(x0, lam0, rho0, funcs, args_f)

        print 'x_opt', x_opt, 'val_opt', val_opt

        Assert(abs(x_opt[0] / - 0.2 ** 0.5 - 1)) < 1.2e-15
        Assert(abs(x_opt[1] / - 0.8 ** 0.5 - 1)) < 1.2e-15
Esempio n. 2
0
def estimate_orientation(process_args, image_file_str):
    seterr(divide='ignore')  ## Avoid zero divide warnings

    tt_total = utime()

    ## Edgel extraction parameters
    gmethod = process_args['grid']['method']
    gspc = process_args['grid']['size']
    glim = process_args['grid']['lim']
    ## Optimization parameters
    ransac_iterations = process_args['ransac_itr']
    optimization_tolerance = process_args['op_tol']
    ## Parameters from the error function. Default is Tukey bisquare with s=0.15
    error_function_parameters = array(process_args['err_func'])
    intrinsic_parameters = process_args['int_parm']

    #################################################################
    ## Load image and initialize pic object
    tt_init = utime()

    ## Creates picture object
    pic = Picture(intrinsic_parameters, image_file_str)

    if process_args['smooth'] is not None:
        pic.smooth(process_args['smooth'])

    ## Extract the edgels from the image using the grid mask
    tt_edgel_extraction = utime()
    pic.extract_edgels(gspc, glim, method=gmethod)
    tt_edgel_extraction = utime() - tt_edgel_extraction


    ## Caculate the edgel normals (interpretation plane), and Jacobians.
    pic.calculate_edgel_normals()
    pic.calculate_edgel_jacobians()

    ## Calculate initial estimate
    tt_initial_estimate = utime()
    qini = pic.random_search(ransac_iterations, error_function_parameters)
    qini = qini.canonical()
    tt_initial_estimate = utime() - tt_initial_estimate

    ## Perform second-stage continuous optimization procedure, based on FilterSQP.
    tt_filtersqp = utime()

    sqp_funcs = (val_c, grad_c, hess_c, val_f, grad_f, hess_f)
    args_f = (pic.edgels, pic.i_param, error_function_parameters)


    filterSQPout = filtersqp.filterSQP(
        qini.q, .0, 1e-3, sqp_funcs, args_f, delta_tol=optimization_tolerance
        )

    # try:
    #     filterSQPout = filtersqp.filterSQP(
    #         qini.q, .0, 1e-3, sqp_funcs, args_f, delta_tol=optimization_tolerance
    #         )
    # except:
    #     print '*** Numerical error for input:'
    #     print {'img_md5': get_hash(image_file_str),
    #            'proc_args': process_args}
    #     raise SystemExit

    xo, err, sqp_iters,Llam,Lrho = filterSQPout
    qopt = Quat(xo)

    tt_filtersqp = utime() - tt_filtersqp

    tt_total = utime() - tt_total

    first_orientation_estimate = qini.canonical().q.tolist()
    final_orientation_estimate = qopt.canonical().q.tolist()

    output_data = {
        'input': {'img_md5': get_hash(image_file_str),
                  'proc_args': process_args},
        'time': {
            'total': tt_total,
            'edgel': tt_edgel_extraction,
            'ransac': tt_initial_estimate,
            'sqp': tt_filtersqp
            },
        'Nedgels': pic.edgels.shape[0],
        'sqp_itr': sqp_iters,
        'ransac_ori_est': first_orientation_estimate,
        'ori_est': final_orientation_estimate,
        }

    return output_data, pic