Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Vector;
- import java.io.*;
- public class PictureProcessor{
- public static final boolean DEBUG = true; //this is for debugging the program efficiently and is used throughout
- private static String _path = "../originalframes/"; //this is the default directory that PictureProcessor will check for the frame extractions if none is specified as a command-line argument
- private static Vector<Picture> _pictures = new Vector<Picture>(); //vector of pictures that we can store our picture objects in for processing
- private static File _rootpath;
- private static File _resultDirectory;
- private boolean initialize(){
- try{ //try runs whatever is in this scope
- File testFile = new File(_path); //File is a java object. The directory passed in from the user in the command-line is put into that object.
- if(!testFile.exists()) //testFile is a particular File object with the path _path (either the default or from a command line argument, as per Test.java), .exists is a function within the File class that tests if that particular File object exists
- throw new Exception("Directory '" + _path + "' does not exist."); //if the File object doesn't exist, give an error message
- }catch(Exception ex){ //catches exception above
- System.err.print(ex.getMessage()); //System makes kernel calls, System.err writes to the error log instead of standard output System.out
- return false; //if there's an exception, initialization fails
- }
- _rootpath = new File(_path);//create a new File object called rootpath that contains the directory that the frame extractions are stored in
- _resultDirectory = new File(_rootpath.getAbsolutePath() + "\\results"); //set up a results directory inside the frame extraction directory
- try{
- if(_rootpath.exists()){ //check to see if the rootpath above exists
- if(!_resultDirectory.exists()) //if a folder called results does not exist within the frame extractions directory, create it
- _resultDirectory.mkdir();
- }else
- throw new Exception("Directory '" + _rootpath.getAbsolutePath() + "' does not exist."); //if the frame extractions directory doesn't exist, throw an exception
- }catch(Exception ex){
- System.err.print(ex.getMessage());
- return false; //if there's an exception, initialization fails
- }
- //add picture objects to a vector
- for(File f : _rootpath.listFiles()){ //for each File f within the frame extractions directory, out of the list of files generated from listFiles() function
- if(f.getName().endsWith(".bmp") || f.getName().endsWith(".jpg") || f.getName().endsWith(".png")){ //if file f's name ends with .bmp, .jpg, or .png
- Picture tmpPic = new Picture(f.getAbsolutePath()); //create a new temporary picture object called tmpPic with path given by f.getAbsolutePath()
- _pictures.add(tmpPic); //add tmpPic Picture object to the vector _pictures created above
- if(DEBUG)
- System.out.println("Added Picture object (" + f.getName() + ") to vector." ); //print that we added the picture to the vector
- }
- }
- //process pictures(frames) in the vector, function given below
- for(Picture pic : _pictures){
- this.processPicture(pic);
- }
- return true;
- }
- //throw an exception if PictureProcessor doesn't initialize
- public PictureProcessor() throws Exception{
- if(!this.initialize()){
- throw new Exception("PictureProcessor was not initialized properly.");
- }
- }
- public PictureProcessor( String _inputdirectory ) throws Exception{
- PictureProcessor._path = _inputdirectory;
- if(!this.initialize()){
- throw new Exception("PictureProcessor was not initialized properly.");
- }
- }
- public void processPicture(Picture pic){
- //to be written, see ForestFire.java
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement