public static URL pathExampleURL ( String path ) { try { File fpath = new File ( path ) ; if ( fpath . isAbsolute ( ) ) return fpath . toURI ( ) . toURL ( ) ; // Assume we are running inside of the project come String pathToBase = getPathToBase ( ) ; if ( pathToBase != null ) { File pathExample = new File ( pathToBase , "data/example/" ) ; if ( pathExample . exists ( ) ) { return new File ( pathExample . getPath ( ) , path ) . getAbsoluteFile ( ) . toURL ( ) ; } } // System.out.println("-----------------------"); // maybe we are running inside an app and all data is stored inside as a resource // System.out.println("Attempting to load resource "+path); URL url = UtilIO . class . getClassLoader ( ) . getResource ( path ) ; if ( url == null ) { System . err . println ( ) ; System . err . println ( "Can't find data/example directory! There are three likely causes for this problem." ) ; System . err . println ( ) ; System . err . println ( "1) You checked out the source code from git and did not pull the data submodule too." ) ; System . err . println ( "2) You are trying to run an example from outside the BoofCV directory tree." ) ; System . err . println ( "3) You are trying to pass in your own image." ) ; System . err . println ( ) ; System . err . println ( "Solutions:" ) ; System . err . println ( "1) Follow instructions in the boofcv/readme.md file to grab the data directory." ) ; System . err . println ( "2) Launch the example from inside BoofCV's directory tree!" ) ; System . err . println ( "3) Don't use this function and just pass in the path directly" ) ; System . exit ( 1 ) ; } return url ; } catch ( MalformedURLException e ) { throw new RuntimeException ( e ) ; } }
Returns an absolute path to the file that is relative to the example directory