def simple_plot():
    ## Just some points on a plane
    s = ascontiguousarray(array(c_[mgrid[-10:11:2,-10:11:2,0:1].reshape(3,-1).T], dtype=float64))

    ## Tilt the camera a bit, and make it point to the origin.
    ion()
    figure(1)
    theta = pi / 16
    t = array([0.0, tan(theta), -1.0]) * 25.0
    psi = array([cos(theta/2), sin(theta/2), 0, 0])

    cx, cy = 320.0, 240.0
    mods = [
        mod(1, cx, cy, 500.0, 0.0),
        mod(2, cx, cy, 500.0, 3e-4),
        mod(2, cx, cy, 500.0, -3e-4),
        ]
    plist = [array([lowlevel.p_wrapper(sk, t, psi, cmod) for sk in s]) for cmod in mods]

    plot_pp(plist)
    title('Camera model test - Harris distortion')
    axis([0,640,480,0])

    #####
    theta = pi / 16
    figure(2)
    t = array([0.0, tan(theta), -1.0]) * 5.0
    psi = array([cos(theta/2), sin(theta/2), 0, 0])
    cx, cy = 320.0, 240.0
    mods = [
        mod(3, cx, cy, 180.0, 0.0),
        ]
    plist = [array([lowlevel.p_wrapper(sk, t, psi, cmod) for sk in s]) for cmod in mods]
    plot_pp(plist)
    title('Camera model test - equidistant distortion')
    axis([0,640,480,0])

    #####
    figure(3, figsize=(8,4))
    title('Camera model test - equirectangular distortion')
    theta = pi / 16
    t = array([0.0, tan(theta), -1.0]) * 3.0
    psi = array([cos(theta/2), sin(theta/2), 0, 0])
    cx, cy = 0.0, 0.0
    mods = [
        mod(4, cx, cy, 1.0, 0.0),
        ]
    plist = [array([lowlevel.p_wrapper(sk, t, psi, cmod) for sk in s]) for cmod in mods]
    plot_pp(plist, cx, cy)
    axis([-pi,pi,pi/2,-pi/2])

    code.interact(local=locals())
def test_camera_models(save):
    '''
    Test if the camera models are working. Compare projections to
    previously calculated values, recorded one a bright sunny day when
    we though everything was working fine. The reason we have this
    test is to check out if the program is still working after any
    changes, it is not an actual validation of the models.

    '''

    ## TODO: Move more of that to external files, make the test just
    ## read and then check against stored results.
    s = ascontiguousarray(array(c_[mgrid[-10:11:2,-10:11:2,0:1].reshape(3,-1).T], dtype=float64))
    theta = pi / 16
    t = array([0.0, tan(theta), -1.0]) * 25.0
    psi = array([cos(theta/2), sin(theta/2), 0, 0])
    cx, cy = 320.0, 240.0
    mods = [
        mod(1, cx, cy, 500.0, 0.0),
        mod(2, cx, cy, 500.0, 3e-4),
        mod(2, cx, cy, 500.0, -3e-4),
        mod(3, cx, cy, 180.0, 0.0),
        mod(4, cx, cy, 1.0, 0.0),
        ]
    plist = array([array([lowlevel.p_wrapper(sk, t, psi, cmod) for sk in s]) for cmod in mods])
    if save:
        print plist
        np.save(CAMERA_MODEL_TEST_REFERENCE_FILE, plist)
        print "Reference saved."
    else:
        ref = np.load(CAMERA_MODEL_TEST_REFERENCE_FILE)
        numpy.testing.assert_almost_equal(plist, ref)
        print "Re-calculated projections are correct."
def project(s, t, psi, cmod):
    return array([lowlevel.p_wrapper(sk, t, psi, cmod) for sk in s], dtype=numpy.float64)
Exemple #4
0
def target(ss, t, psi, cam, p):

    p_hat = numpy.array([lowlevel.p_wrapper(s, t, psi, cam) for s in ss])