Beispiel #1
0
def test_meters_per_pixel():
    C = CameraParams(lens=4.0,
                     sensorwidth=5.0,
                     xresolution=1024,
                     yresolution=800)
    frame_time = 1478954763.0
    pos = mav_position.MavPosition(-50, 145, 120, 0, 0, 90, frame_time)
    ret = meters_per_pixel(pos, C)
    assert abs(0.1463 - ret) < 0.001

    pos = mav_position.MavPosition(-50, 145, 85, 3, 1, 45, frame_time)
    ret = meters_per_pixel(pos, C)
    assert abs(0.1041 - ret) < 0.001
Beispiel #2
0
def test_JoeLog_JoeIterator():
    joelog = cuav_joe.JoeLog(os.path.join('.', 'joe.log'), False)
    regions = []
    frame_time = 1478954763.0
    C = CameraParams(lens=4.0,
                     sensorwidth=5.0,
                     xresolution=1024,
                     yresolution=768)
    regions.append(cuav_region.Region(10, 10, 25, 23, None, scan_score=450))
    regions.append(cuav_region.Region(200, 205, 252, 236, None,
                                      scan_score=420))
    pos = mav_position.MavPosition(-30, 145, 34.56, 20, -56.67, 345,
                                   frame_time)
    joelog.add_regions(frame_time, regions, pos, 'img2017111312451230Z.png')

    joeread = cuav_joe.JoeIterator(os.path.join('.', 'joe.log'))

    joeret = joeread.getjoes()

    assert len(joeret) == 2
    assert joeret[
        0] == "JoePosition(lat=-30.000235 lon=144.999639 MavPosition(pos -30.000000 145.000000 alt=34.6 roll=20.0 pitch=-56.7 yaw=345.0) img2017111312451230Z.png None (10, 10, 25, 23) latlon=(-30.000235126851315, 144.9996388367703) score=None Sat Nov 12 23:46:03 2016 2016111212460300Z)" or "JoePosition(lat=-30.000235 lon=144.999639 MavPosition(pos -30.000000 145.000000 alt=34.6 roll=20.0 pitch=-56.7 yaw=345.0) img2017111312451230Z.png None (10, 10, 25, 23) latlon=(-30.000235126851315, 144.9996388367703) score=None Sat Nov 12 12:46:03 2016 2016111212460300Z)"
    assert joeret[
        1] == "JoePosition(lat=-30.000367 lon=144.999711 MavPosition(pos -30.000000 145.000000 alt=34.6 roll=20.0 pitch=-56.7 yaw=345.0) img2017111312451230Z.png None (200, 205, 252, 236) latlon=(-30.000366794010567, 144.9997107272955) score=None Sat Nov 12 23:46:03 2016 2016111212460300Z)" or "JoePosition(lat=-30.000367 lon=144.999711 MavPosition(pos -30.000000 145.000000 alt=34.6 roll=20.0 pitch=-56.7 yaw=345.0) img2017111312451230Z.png None (200, 205, 252, 236) latlon=(-30.000366794010567, 144.9997107272955) score=None Sat Nov 12 12:46:03 2016 2016111212460300Z)"

    os.remove(os.path.join('.', 'joe.log'))
def test_addLandingZoneMany():
    lz = cuav_landingregion.LandingZone()
    for i in range(0, 100):
        r = cuav_region.Region(1020, 658, 1050, 678, (30, 30))
        r.latlon = (random.uniform(-90, 90), random.uniform(-180, 180))
        r.score = random.randint(0, 1000)
        pos = mav_position.MavPosition(r.latlon[0], r.latlon[1], 80, 0, 0, 0, 1)
        lz.checkaddregion(r, pos)

    assert len(lz.regionClumps) == 100
def test_addLandingZone():
    lz = cuav_landingregion.LandingZone()
    for i in range(0, 10):
        r = cuav_region.Region(1020, 658, 1050, 678, (30, 30))
        r.latlon = (23, 34)
        pos = mav_position.MavPosition(23, 24, 80, 0, 0, 0, 1)
        r.score = 20
        lz.checkaddregion(r, pos)

    assert len(lz.regionClumps) == 1
Beispiel #5
0
def test_MavPosition():
    mav = mav_position.MavPosition(-30,
                                   145,
                                   34.56,
                                   20,
                                   -56.67,
                                   345,
                                   frame_time=None)
    assert str(
        mav
    ) == "MavPosition(pos -30.000000 145.000000 alt=34.6 roll=20.0 pitch=-56.7 yaw=345.0)"
def test_calcLandingZone():
    lz = cuav_landingregion.LandingZone()
    for i in range(0, 100):
        r = cuav_region.Region(1020, 658, 1050, 678, (30, 30))
        r.latlon = (random.uniform(-0.001, 0.001)+34, random.uniform(-0.001, 0.001)-140)
        r.score = random.randint(0, 1000)
        pos = mav_position.MavPosition(r.latlon[0], r.latlon[1], 80, 0, 0, 0, 1)
        lz.checkaddregion(r, pos)

    ret = lz.calclandingzone()
    assert ret == True
Beispiel #7
0
def test_MosaicRegion():
    regOne = cuav_region.Region(1020, 658, 1050, 678, (30, 30))
    regOne.latlon=(-26.6398870, 151.8220000)
    regOne.score = 20
    pos = mav_position.MavPosition(-30, 145, 34.56, 20, -56.67, 345, frame_time=None)
    pos.time = int(time.time())
    im_orig = cv2.imread(os.path.join(os.getcwd(), 'tests', 'testdata', 'test-8bit.png'))
    full_thumbnail = im_orig[1:80, 1:80]
    small_thumbnail = im_orig[2:12, 10:20]
    mos = cuav_mosaic.MosaicRegion(2, regOne, "nofile.png", pos, full_thumbnail, small_thumbnail)
    mos.tag_image_available()
    assert mos.small_thumbnail[2,9,0] == 0
    assert mos.small_thumbnail[2,9,1] == 255
    assert mos.small_thumbnail[2,9,2] == 255
    assert "MavPosition(pos -30.000000 145.000000 alt=34.6 roll=20.0 pitch=-56.7 yaw=345.0)" in str(mos)
Beispiel #8
0
def test_gps_position_from_image_region():
    frame_time = 1478954763.0
    pos = mav_position.MavPosition(-50, 145, 120, 0, 0, 90, frame_time)
    region = cuav_region.Region(10, 10, 25, 23, None, scan_score=450)
    C = CameraParams(lens=4.0,
                     sensorwidth=5.0,
                     xresolution=1024,
                     yresolution=800)
    (lat, lon) = gps_position_from_image_region(region,
                                                pos,
                                                width=1024,
                                                height=800,
                                                C=C,
                                                altitude=None)
    assert abs(-49.99934 - lat) < 0.00001
    assert abs(145.00078 - lon) < 0.00001
Beispiel #9
0
def test_filter_boundary():
    OBC_boundary = cuav_util.polygon_load(os.path.join(os.getcwd(), 'tests', 'testdata', 'OBC_boundary.txt'))
    regions = []
    regOne = cuav_region.Region(1020, 658, 1050, 678, (30, 30))
    regOne.latlon=(-26.6398870, 151.8220000)
    regOne.score = 20
    regions.append(regOne)
    regTwo = cuav_region.Region(1020, 658, 1050, 678, (30, 30))
    regTwo.score = 32
    regTwo.latlon=(-26.6418700, 151.8709260)
    regions.append(regTwo)
    pos = mav_position.MavPosition(-30, 145, 34.56, 20, -56.67, 345, frame_time=None)
    ret = cuav_region.filter_boundary(regions, OBC_boundary, pos)
    assert len(ret) == 2
    assert ret[0].score == 0
    assert ret[1].score == 32
Beispiel #10
0
def test_gps_position_from_xy():
    C = CameraParams(lens=4.0,
                     sensorwidth=5.0,
                     xresolution=1024,
                     yresolution=800)
    frame_time = 1478954763.0
    pos = mav_position.MavPosition(-50, 145, 120, 0, 0, 90, frame_time)
    (lat, lon) = gps_position_from_xy(512,
                                      400,
                                      pos,
                                      C=C,
                                      altitude=120,
                                      shape=None)
    assert abs(-50 - lat) < 0.00001
    assert abs(145 - lon) < 0.00001

    (lat, lon) = gps_position_from_xy(200,
                                      100,
                                      pos,
                                      C=C,
                                      altitude=120,
                                      shape=None)
    assert abs(-49.999589 - lat) < 0.00001
    assert abs(145.000614 - lon) < 0.00001
Beispiel #11
0
def test_Mosaic():
    #slipmap = mp_slipmap.MPSlipMap(service='GoogleSat', elevation=True, title='Map')
    #mocked_slipmap.return_value = 1
    #monkeypatch.setattr('slipmap', lambda x: 1)
    mocked_slipmap = mock.MagicMock(return_value=1)
    C_params = CameraParams(lens=4.0, sensorwidth=5.0, xresolution=1280, yresolution=960)
    mosaic = cuav_mosaic.Mosaic(mocked_slipmap, C=C_params)
    mosaic.set_mosaic_size((200, 200))
    assert mosaic.mosaic.shape == (175, 175, 3)
    
    f = os.path.join(os.getcwd(), 'tests', 'testdata', 'raw2016111223465120Z.png')
    img = cv2.imread(f)
    pos = mav_position.MavPosition(-30, 145, 34.56, 20, -56.67, 345, frame_time=1478994408.76)
    regions = []
    regions.append(cuav_region.Region(1020, 658, 1050, 678, (30, 30), scan_score=20))
    regions.append(cuav_region.Region(30, 54, 50, 74, (20, 20), scan_score=15))
    regions.append(cuav_region.Region(30, 54, 55, 79, (25, 25), scan_score=10))
    for i in range(40):
        regions.append(cuav_region.Region(200, 600, 220, 620, (20, 20), scan_score=45))
    composite = cuav_region.CompositeThumbnail(img, regions)
    thumbs = cuav_mosaic.ExtractThumbs(composite, len(regions))
    mosaic.add_regions(regions, thumbs, f, pos)
    mosaic.add_image(1478994408.76, f, pos)
    
    mosaic.show_region(0)

    mosaic.view_imagefile(f)
    
    
    assert mosaic.find_image_idx(f) == 0
    mosaic.view_imagefile_by_idx(0)
    
    mocked_key = mock.MagicMock(return_value=1)
    mocked_key.objkey = "region 1"
    assert mosaic.show_selected(mocked_key) == True
    
    mosaic.show_closest((-30, 145), mocked_key)
    
    mosaic.view_image.terminate()
    
    #mosaic.map_menu_callback
    
    #mosaic.map_callback
    
    OBC_boundary = cuav_util.polygon_load(os.path.join(os.getcwd(), 'tests', 'testdata', 'OBC_boundary.txt'))
    mosaic.set_boundary(OBC_boundary)
    
    mosaic.change_page(1)
    mosaic.hide_page()
    assert len(mosaic.regions_sorted) == 25
    mosaic.unhide_all()
    assert len(mosaic.regions_sorted) == 43
    
    for i in ['Score', 'ScoreReverse', 'Distinctiveness', 'Whiteness', 'Time']:
        mosaic.sort_type = i
        mosaic.re_sort()
    
    #mosaic.menu_event
    
    assert mosaic.started() == True
    
    mosaic.popup_show_image(mosaic.regions[2])
    
    mosaic.popup_fetch_image(mosaic.regions[2], 'fetchImageFull')
    
    assert len(mosaic.get_image_requests()) == 1
    
    mosaic.view_image.terminate()
    
    #mosaic.menu_event_view
    
    mocked_pos = mock.MagicMock(return_value=1)
    mocked_pos.x = 10
    mocked_pos.y = 10
    assert mosaic.pos_to_region(mocked_pos) == mosaic.regions[0]
    
    assert mosaic.objkey_to_region(mocked_key) == mosaic.regions[1]
    
    #mosaic.mouse_event
    
    #mosaic.mouse_event_view
    
    mosaic.key_event(1)
    
    assert mosaic.region_on_page(2, 0) == True
    assert mosaic.region_on_page(2000, 20) == False
    
    mosaic.mouse_region = mosaic.regions[0]
    mosaic.display_mosaic_region(0)
    
    mosaic.redisplay_mosaic()
    
    assert mosaic.make_thumb(img, regions[0], 8).shape == (8, 8, 3)
    assert mosaic.make_thumb(img, regions[0], 30).shape == (30, 30, 3)
    
    mosaic.tag_image(1478994408.76)
    
    #mosaic.check_events
    
    mosaic.image_mosaic.terminate()
Beispiel #12
0
def test_MosaicImage():
    pos = mav_position.MavPosition(-30, 145, 34.56, 20, -56.67, 345, frame_time=None)
    pos.time = int(time.time())
    im = cuav_mosaic.MosaicImage(int(time.time()), "nofile.png", pos)
    assert "nofile.png" in str(im)