<s> import os , sys , pickle <EOL> from SimpleCV import * <EOL> from nose . tools import with_setup , nottest <EOL> VISUAL_TEST = True <EOL> SHOW_WARNING_TESTS = False <EOL> black = Color . BLACK <EOL> white = Color . WHITE <EOL> red = Color . RED <EOL> green = Color . GREEN <EOL> blue = Color . BLUE <EOL> pair1 = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> pair2 = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> pair3 = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> pair4 = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> pair5 = ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> correct_pairs = [ pair1 , pair2 , pair3 , pair4 , pair5 ] <EOL> standard_path = "<STR_LIT>" <EOL> def imgDiffs ( test_imgs , name_stem , tolerance , path ) : <EOL> count = len ( test_imgs ) <EOL> for idx in range ( <NUM_LIT:0> , count ) : <EOL> lhs = test_imgs [ idx ] . applyLayers ( ) <EOL> fname = standard_path + name_stem + str ( idx ) + "<STR_LIT>" <EOL> rhs = Image ( fname ) <EOL> if ( lhs . width == rhs . width and lhs . height == rhs . height ) : <EOL> diff = ( lhs - rhs ) <EOL> val = np . average ( diff . getNumpy ( ) ) <EOL> if ( val > tolerance ) : <EOL> print val <EOL> return True <EOL> return False <EOL> def imgSaves ( test_imgs , name_stem , path = standard_path ) : <EOL> count = len ( test_imgs ) <EOL> for idx in range ( <NUM_LIT:0> , count ) : <EOL> fname = standard_path + name_stem + str ( idx ) + "<STR_LIT>" <EOL> test_imgs [ idx ] . save ( fname ) <EOL> def perform_diff ( result , name_stem , tolerance = <NUM_LIT> , path = standard_path ) : <EOL> if ( VISUAL_TEST ) : <EOL> imgSaves ( result , name_stem , path ) <EOL> else : <EOL> if ( imgDiffs ( result , name_stem , tolerance , path ) ) : <EOL> assert False <EOL> else : <EOL> pass <EOL> def setup_context ( ) : <EOL> img = Image ( pair1 [ <NUM_LIT:0> ] ) <EOL> def destroy_context ( ) : <EOL> img = "<STR_LIT>" <EOL> @ with_setup ( setup_context , destroy_context ) <EOL> def test_findFundamentalMat ( ) : <EOL> for pairs in correct_pairs : <EOL> img1 = Image ( pairs [ <NUM_LIT:0> ] ) <EOL> img2 = Image ( pairs [ <NUM_LIT:1> ] ) <EOL> StereoImg = StereoImage ( img1 , img2 ) <EOL> if ( not StereoImg . findFundamentalMat ( ) ) : <EOL> assert False <EOL> def test_findHomography ( ) : <EOL> for pairs in correct_pairs : <EOL> img1 = Image ( pairs [ <NUM_LIT:0> ] ) <EOL> img2 = Image ( pairs [ <NUM_LIT:1> ] ) <EOL> StereoImg = StereoImage ( img1 , img2 ) <EOL> if ( not StereoImg . findHomography ( ) ) : <EOL> assert False <EOL> def test_findDisparityMap ( ) : <EOL> dips = [ ] <EOL> for pairs in correct_pairs : <EOL> img1 = Image ( pairs [ <NUM_LIT:0> ] ) <EOL> img2 = Image ( pairs [ <NUM_LIT:1> ] ) <EOL> StereoImg = StereoImage ( img1 , img2 ) <EOL> dips . append ( StereoImg . findDisparityMap ( method = "<STR_LIT>" ) ) <EOL> name_stem = "<STR_LIT>" <EOL> perform_diff ( dips , name_stem ) <EOL> dips = [ ] <EOL> for pairs in correct_pairs : <EOL> img1 = Image ( pairs [ <NUM_LIT:0> ] ) <EOL> img2 = Image ( pairs [ <NUM_LIT:1> ] ) <EOL> StereoImg = StereoImage ( img1 , img2 ) <EOL> dips . append ( StereoImg . findDisparityMap ( method = "<STR_LIT>" ) ) <EOL> name_stem = "<STR_LIT>" <EOL> perform_diff ( dips , name_stem ) <EOL> def test_eline ( ) : <EOL> for pairs in correct_pairs : <EOL> img1 = Image ( pairs [ <NUM_LIT:0> ] ) <EOL> img2 = Image ( pairs [ <NUM_LIT:1> ] ) <EOL> StereoImg = StereoImage ( img1 , img2 ) <EOL> F , ptsLeft , ptsRight = StereoImg . findFundamentalMat ( ) <EOL> for pts in ptsLeft : <EOL> line = StereoImg . Eline ( pts , F , <NUM_LIT:2> ) <EOL> if ( line == None ) : <EOL> assert False <EOL> def test_projectPoint ( ) : <EOL> for pairs in correct_pairs : <EOL> img1 = Image ( pairs [ <NUM_LIT:0> ] ) <EOL> img2 = Image ( pairs [ <NUM_LIT:1> ] ) <EOL> StereoImg = StereoImage ( img1 , img2 ) <EOL> H , ptsLeft , ptsRight = StereoImg . findHomography ( ) <EOL> for pts in ptsLeft : <EOL> line = StereoImg . projectPoint ( pts , H , <NUM_LIT:2> ) <EOL> if ( line == None ) : <EOL> assert False <EOL> def test_StereoCalibration ( ) : <EOL> cam = StereoCamera ( ) <EOL> try : <EOL> cam1 = Camera ( <NUM_LIT:0> ) <EOL> cam2 = Camera ( <NUM_LIT:1> ) <EOL> cam1 . getImage ( ) <EOL> cam2 . getImage ( ) <EOL> try : <EOL> cam = StereoCamera ( ) <EOL> calib = cam . StereoCalibration ( <NUM_LIT:0> , <NUM_LIT:1> , nboards = <NUM_LIT:1> ) <EOL> if ( calib ) : <EOL> assert True <EOL> else : <EOL> assert False <EOL> except : <EOL> assert False <EOL> except : <EOL> assert True <EOL> def test_loadCalibration ( ) : <EOL> cam = StereoCamera ( ) <EOL> calbib = cam . loadCalibration ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if ( calbib ) : <EOL> assert True <EOL> else : <EOL> assert False <EOL> def test_StereoRectify ( ) : <EOL> cam = StereoCamera ( ) <EOL> calib = cam . loadCalibration ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> rectify = cam . stereoRectify ( calib ) <EOL> if rectify : <EOL> assert True <EOL> else : <EOL> assert False <EOL> def test_getImagesUndistort ( ) : <EOL> img1 = Image ( correct_pairs [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] ) . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> img2 = Image ( correct_pairs [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) . resize ( <NUM_LIT> , <NUM_LIT> ) <EOL> cam = StereoCamera ( ) <EOL> calib = cam . loadCalibration ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> rectify = cam . stereoRectify ( calib ) <EOL> rectLeft , rectRight = cam . getImagesUndistort ( img1 , img2 , calib , rectify ) <EOL> if rectLeft and rectRight : <EOL> assert True <EOL> else : <EOL> assert False </s>
