Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. import java.util.Vector;
  2. import java.io.*;
  3.  
  4. public class PictureProcessor{
  5. public static final boolean DEBUG = true; //this is for debugging the program efficiently and is used throughout
  6. 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
  7. private static Vector<Picture> _pictures = new Vector<Picture>(); //vector of pictures that we can store our picture objects in for processing
  8. private static File _rootpath;
  9. private static File _resultDirectory;
  10.  
  11. private boolean initialize(){
  12. try{ //try runs whatever is in this scope
  13. 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.
  14. 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
  15. throw new Exception("Directory '" + _path + "' does not exist."); //if the File object doesn't exist, give an error message
  16. }catch(Exception ex){ //catches exception above
  17. System.err.print(ex.getMessage()); //System makes kernel calls, System.err writes to the error log instead of standard output System.out
  18. return false; //if there's an exception, initialization fails
  19. }
  20.  
  21. _rootpath = new File(_path);//create a new File object called rootpath that contains the directory that the frame extractions are stored in
  22. _resultDirectory = new File(_rootpath.getAbsolutePath() + "\\results"); //set up a results directory inside the frame extraction directory
  23. try{
  24. if(_rootpath.exists()){ //check to see if the rootpath above exists
  25. if(!_resultDirectory.exists()) //if a folder called results does not exist within the frame extractions directory, create it
  26. _resultDirectory.mkdir();
  27. }else
  28. throw new Exception("Directory '" + _rootpath.getAbsolutePath() + "' does not exist."); //if the frame extractions directory doesn't exist, throw an exception
  29. }catch(Exception ex){
  30. System.err.print(ex.getMessage());
  31. return false; //if there's an exception, initialization fails
  32. }
  33.  
  34. //add picture objects to a vector
  35. for(File f : _rootpath.listFiles()){ //for each File f within the frame extractions directory, out of the list of files generated from listFiles() function
  36. if(f.getName().endsWith(".bmp") || f.getName().endsWith(".jpg") || f.getName().endsWith(".png")){ //if file f's name ends with .bmp, .jpg, or .png
  37. Picture tmpPic = new Picture(f.getAbsolutePath()); //create a new temporary picture object called tmpPic with path given by f.getAbsolutePath()
  38. _pictures.add(tmpPic); //add tmpPic Picture object to the vector _pictures created above
  39.  
  40. if(DEBUG)
  41. System.out.println("Added Picture object (" + f.getName() + ") to vector." ); //print that we added the picture to the vector
  42. }
  43. }
  44.  
  45. //process pictures(frames) in the vector, function given below
  46. for(Picture pic : _pictures){
  47. this.processPicture(pic);
  48. }
  49.  
  50. return true;
  51. }
  52. //throw an exception if PictureProcessor doesn't initialize
  53. public PictureProcessor() throws Exception{
  54. if(!this.initialize()){
  55. throw new Exception("PictureProcessor was not initialized properly.");
  56. }
  57.  
  58. }
  59.  
  60. public PictureProcessor( String _inputdirectory ) throws Exception{
  61. PictureProcessor._path = _inputdirectory;
  62. if(!this.initialize()){
  63. throw new Exception("PictureProcessor was not initialized properly.");
  64. }
  65. }
  66.  
  67.  
  68. public void processPicture(Picture pic){
  69.  
  70. //to be written, see ForestFire.java
  71.  
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement