Package boofcv.io

Class UtilIO

java.lang.Object
boofcv.io.UtilIO

public class UtilIO extends Object
Functions for reading and writing different data structures to a file or data stream.
  • Field Details

  • Constructor Details

    • UtilIO

      public UtilIO()
  • Method Details

    • saveListStringYaml

      public static void saveListStringYaml(List<String> list, File file)
      Saves a list of strings as a YAML file
    • loadListStringYaml

      public static List<String> loadListStringYaml(File file)
      Saves a list of strings from a YAML file
    • savePoseListCsv

      public static void savePoseListCsv(List<Se3_F64> list, RotationType type, File file)
      Saves a list of 6-dof pose in a CSV format. Rotation matrix is converted into the specified encoding.
      Parameters:
      list - (Input) List of poses
      type - (Input) Format to use for rotation matrix
      file - (Output) Where it's written to.
    • savePoseListCsv

      public static void savePoseListCsv(List<Se3_F64> list, RotationType type, OutputStream output)
      Saves a list of 6-dof pose in a CSV format. Rotation matrix is converted into the specified encoding.
      Parameters:
      list - (Input) List of poses
      type - (Input) Format to use for rotation matrix
      output - (Output) Where it's written to.
    • saveConfig

      public static void saveConfig(Configuration config, File file)
      Saves a BoofCV Configuration in a YAML format to disk
    • saveConfig

      public static <C extends Configuration> void saveConfig(C config, @Nullable C canonical, File file)
      Saves a BoofCV Configuration in a YAML format to disk. Only values which are different from the 'canonical' reference are saved. This can result in more concise and readable configurations but can cause problems in repeatability if the reference is changed in the future.
      Parameters:
      config - (Input) The configuration which is to be saved
      canonical - (Input) A configuration that is compared against. Only what's not identical will be saved. IF null then a new configuration will be created using default constructor.
      file - (Input) Reference to the file that the configuration will be saved at.
    • loadConfig

      public static <T extends Configuration> T loadConfig(File file)
      Loads a BoofCV Configuration in a YAML format from the disk
    • pathExampleURL

      public static URL pathExampleURL(String path)
      Returns an absolute path to the file that is relative to the example directory
      Parameters:
      path - File path relative to root directory
      Returns:
      Absolute path to file
    • loadExampleIntrinsic

      public static CameraPinholeBrown loadExampleIntrinsic(MediaManager media, File exampleFile)
      Loads camera model for an example input file. First checks to see if there's calibration specific to that file if not it looks to see if there is a directory wide one. If all fails it returns null.
    • openBufferedReader

      public static BufferedReader openBufferedReader(String fileName) throws FileNotFoundException
      Throws:
      FileNotFoundException
    • ensureURL

      @Nullable public static @Nullable URL ensureURL(String path)
      Given a path which may or may not be a URL return a URL
    • ensureUrlNotNull

      public static URL ensureUrlNotNull(@Nullable @Nullable String path)
    • ensureFilePath

      @Nullable public static @Nullable String ensureFilePath(String path)
    • simplifyJarPath

      public static URL simplifyJarPath(URL url)
      Jar paths don't work if they include up directory. this wills trip those out.
    • systemToUnix

      public static String systemToUnix(String path)
    • simplifyJarPath

      public static String simplifyJarPath(String path)
    • openStream

      @Nullable public static @Nullable InputStream openStream(String path)
    • readLine

      public static String readLine(InputStream input, StringBuilder buffer) throws IOException
      Reads a line from an input stream.
      Throws:
      IOException
    • readInt

      public static int readInt(InputStream input) throws IOException
      Throws:
      IOException
    • write

      public static void write(OutputStream output, String message) throws IOException
      Throws:
      IOException
    • pathExample

      public static String pathExample(String path)
    • fileExample

      public static File fileExample(String path)
    • path

      public static String path(String path)
      Searches for the root BoofCV directory and returns an absolute path from it.
      Parameters:
      path - File path relative to root directory
      Returns:
      Absolute path to file
    • getFileToBase

      public static File getFileToBase()
    • getPathToBase

      @Nullable public static @Nullable String getPathToBase()
      Steps back until it finds the base BoofCV directory.
      Returns:
      Path to the base directory.
    • selectFile

      public static String selectFile(boolean exitOnCancel)
      Opens up a dialog box asking the user to select a file. If the user cancels it either returns null or quits the program.
      Parameters:
      exitOnCancel - If it should quit on cancel or not.
      Returns:
      Name of the selected file or null if nothing was selected.
    • loadLibrarySmart

      public static void loadLibrarySmart(String libraryName)
    • loadLibrary

      public static boolean loadLibrary(String libraryName)
    • save

      public static void save(Object o, String fileName)
    • load

      public static <T> T load(String fileName)
    • deleteRecursive

      public static void deleteRecursive(File f)
      Deletes all the file/directory and all of its children
    • copyRecursive

      public static void copyRecursive(File src, File dst)
      Copies all the files and directories in 'src' into 'dst'.
    • readAsString

      @Nullable public static @Nullable String readAsString(String path)
      Reads an entire file and converts it into a text string
    • readAsString

      @Nullable public static @Nullable String readAsString(InputStream stream)
      Reads an entire file and converts it into a text string
    • getSourcePath

      public static String getSourcePath(String pkg, String app)
      Constructs the path for a source code file residing in the examples or demonstrations directory In the case of the file not being in either directory, an empty string is returned The expected parameters are class.getPackage().getName(), class.getSimpleName()
      Parameters:
      pkg - package containing the class
      app - simple class name
    • getGithubURL

      public static String getGithubURL(String pkg, String app)
    • indexOfSourceStart

      public static int indexOfSourceStart(String code)
      Finds the first javadoc OR the start of the class, which ever comes first. This does require some thought. The word class can easily be inside a comment. Comments may or may not be there. Always the potential for stray //
    • listByPrefix

      public static List<String> listByPrefix(String directory, @Nullable @Nullable String prefix, @Nullable @Nullable String suffix)
      Loads a list of files with the specified prefix.
      Parameters:
      directory - Directory it looks inside of
      prefix - Prefix that the file must have. Null if no prefix.
      suffix - Suffix that the file must have. Null if no suffix
      Returns:
      List of files that are in the directory and match the prefix.
    • listSmart

      public static List<String> listSmart(String pathPattern, boolean sort, BoofLambdas.Filter<Path> filter)

      An intelligent image file search. If the passed in string starts with "glob:" or "regex:" then it will use a glob or regex pattern to find the files. Otherwise it will see if it's a file or directory. If a file then just that file is returned in the list. If a directory then all the files in that directory are returned.

      Because Windows uses backslash instead of forward slash things are more complex. You either need to modify the path to escape the backslash '\' -> '\\' or replace all backslashes with a forward slash. This isn't done automatically because REGEX uses backslashes too. In summary: Windows path like foo\bar needs to be changed to foo/bar or foo\\bar. If you know of a clean fix for this mess please create a PR on Github

      Parameters:
      pathPattern - Either a path to the file/directory or a glob/regex pattern.
      sort - If the output should be sorted first
      filter - A filter that provides better flexibility in deciding what's included
      Returns:
      List of found files that matched all the patterns
    • listSmartImages

      public static List<String> listSmartImages(String pathPattern, boolean sort)
      Same as listSmart(String, boolean, BoofLambdas.Filter) but adds a filter that looks for images based on their extension.
      Parameters:
      pathPattern - Either a path to the file/directory or a glob/regex pattern.
      sort - If the output should be sorted first
      Returns:
      List of matching file paths
    • listImages

      public static List<String> listImages(String directory, boolean sort)
      Lists all images in the directory using a regex and optionally sorts the list
    • listByRegex

      public static List<String> listByRegex(String directory, String regex)
    • listFilesSorted

      public static List<File> listFilesSorted(File directory)
      Returns a list of all the children as a file and sorts them
    • listAll

      public static List<String> listAll(String directory)
    • listAllMime

      public static List<String> listAllMime(String directory, String type)
      Lists all files in the directory with an MIME type that contains the string "type"
    • findMatches

      public static File[] findMatches(File directory, String regex)

      Looks for file names which match the regex in the directory.

      Example:
      BoofMiscOps.findMatches(new File("/path/to/directory"), ".+jpg");

      Parameters:
      directory - directory
      regex - file name regex
      Returns:
      array of matching files
    • validURL

      public static boolean validURL(URL url)
    • copyToFile

      public static void copyToFile(InputStream in, File file)
    • delete

      public static void delete(File f, UtilIO.FileTest test) throws IOException
      Recursively deletes all files in path which pass the test.
      Parameters:
      f - base directory or file
      test - The test
      Throws:
      IOException - Exception if fails to delete a file
    • checkIfJarAndCopyToTemp

      public static String checkIfJarAndCopyToTemp(String filename)
    • mkdirs

      public static void mkdirs(File directory)
      Convenience function which creates a directory and everything along its path if it does not exist. Also checks to make sure the path leads to a directory if it does exist
      Parameters:
      directory - Path to the directory
    • mkdirs

      public static void mkdirs(File directory, boolean delete)
      Checks to directory exists. If it does and delete is true it will recursively delete it and all its children. Then creates the directory again. If delete is false then it calls mkdirs(File).
      Parameters:
      directory - Path to the directory
      delete - if true it will delete the original directory