Changeset 33141
- Timestamp:
- 2019-06-10T13:48:01+12:00 (5 years ago)
- Location:
- other-projects/is-sheet-music-encore/trunk/image-identification-terminal
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/Makefile
r33110 r33141 1 1 #https://www.tensorflow.org/install/lang_java 2 #testClassifier runs the cmd below3 2 #java -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar:. -Djava.library.path=/Scratch/cpb16/opencv-3.4.2/build/lib/ javaImageClassifier TestImages/Test.png 1 4 3 5 test-run-classifier01: 4 run-classifier-houghlinesP: 5 #Compile 6 6 javac javaAccuracyCalculator.java 7 7 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java; 8 ./testClassifer.sh TestImages 1 8 #Run javaImageClassifier on all images in TestImages 9 ./runClassifer.sh TestImages houghlinesP 9 10 echo "Displaying javaImageClassifier output" 11 #Display output of javaImageClassifier 10 12 less log.txt 11 java javaAccuracyCalculator log.txt 1 results.txt 13 #Calculate the Accuracy of the classifier 14 java javaAccuracyCalculator log.txt houghlinesP results.txt 15 #Display output 12 16 less results.txt 13 17 rm log.txt 18 rm results.txt 14 19 15 20 16 image-run-classifier01:17 javac javaAccuracyCalculator.java18 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java;19 ./testClassifer.sh ../download-images/BK 120 echo "Displaying javaImageClassifier output"21 less log.txt22 java javaAccuracyCalculator log.txt 1 results.txt23 less results.txt24 rm log.txt -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaAccuracyCalculator.java
r33097 r33141 1 2 1 import java.io.File; 3 2 import java.io.BufferedReader; … … 5 4 import java.io.FileReader; 6 5 import java.io.FileWriter; 7 8 9 6 public class javaAccuracyCalculator{ 10 11 public static void main(String[] args) { 12 7 8 //Read in log.txt, grab first item in array of each line 9 //Counter for everytime have readline 10 //Calculate accuracy rate 11 public static void main(String[] args) { 13 12 try { 14 13 if (args.length != 3) { … … 21 20 FileReader fileReader = new FileReader(inputFilename); 22 21 BufferedReader buf = new BufferedReader(fileReader); 23 FileWriter fw = new FileWriter(outputFilename );22 FileWriter fw = new FileWriter(outputFilename,true); 24 23 String line = null; 25 24 String[] item; 26 float accuracyRate = 0; 27 int trueCount = 0; 28 int lineCount = 0; 29 30 //RENAME CLASSIFIER NUMBER TO ACTUALL CLASSIFIER 31 if(classifierType.equals("1")){classifierType = "Probabilistic HoughLines";} 32 25 float trueAccuracyRate =0; 26 float falseAccuracyRate =0; 27 int trueCount = 0; 28 int falseCount = 0; 29 int sheetMusicCount = 0; 30 int notSheetMusicCount = 0; 33 31 //Splits into each record, since readLine splits by "\n" 34 32 while ((line = buf.readLine()) != null) { 35 lineCount++; 36 //Splits by tab, leaves "" for every blank entry 37 item = line.split("\t"); 38 //Check first element (true or false) 39 if(item[0].equals("1")){ 40 trueCount++; 33 item = line.split("\t"); 34 //Calculate AccuracyRates 35 if(item[1].contains("TestImages/SheetMusic/")){ 36 sheetMusicCount++; 37 if(item[3].equals("true")){ 38 trueCount++; 39 } 40 } 41 if(item[1].contains("TestImages/NotSheetMusic/")){ 42 notSheetMusicCount++; 43 if(item[3].equals("true")){ 44 falseCount++; 45 } 41 46 } 42 47 } 43 accuracyRate = ((float)trueCount/(float)lineCount)*(float)100; 44 fw.write("Classifier:" + classifierType + "\t" + accuracyRate + "%" + "\n"); 48 49 //Amount of sheetMusic classified images / total amount of images read 50 trueAccuracyRate = ((float)trueCount/(float)sheetMusicCount)*(float)100; 51 //Amount of notSheetMusic classified images / total amount of images read 52 falseAccuracyRate = ((float)falseCount/(float)notSheetMusicCount)*(float)100; 53 54 fw.write("Classifier: " + classifierType + '\t' + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\t' + "NotSheetMusicAccuracyRate :" + falseAccuracyRate + "%" + "\n"); 45 55 buf.close(); 46 fw.close(); 47 48 //Read in log.txt, grab first item in array of each line 49 //counter for everytime have readline 50 51 //Calculate accuracy rate 52 56 fw.close(); 53 57 } 54 58 } -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaImageClassifier.java
r33097 r33141 22 22 23 23 24 //GOAL for 21st 24 //OUTPUT OF THIS JAVA PROGRAM FOUND IN log.txt 25 //Each image processed will have an output of 26 //True =classifierType + 1 + Filename + Status 27 //False =classifierType + 0 + Filename + Status 28 public class javaImageClassifier{ 29 //Constants 30 static int CLASSIFIER_HOUGHLINESP_MIN = 10; 31 static int CLASSIFIER_HOUGHLINESP_MAX = 50; 25 32 26 27 //Classifier 01 28 //Have args so can call "java image-identification-classifier01 XX XX" 29 //args can be parameters in algorthim such as threshold or theta? 30 //Run on 5000 images. 31 //Record success rates 32 //All done with makefile 33 34 35 //But first understand houghline transform 36 //Know what the algorithm being used is doing. 37 //MAke constants for this classifier 38 //Make java be able to run on CMD line 39 40 public class javaImageClassifier{ 41 42 public static void main(String[] args) { 43 33 public static void main(String[] args) { 44 34 try { 45 35 if (args.length != 2) { … … 47 37 } 48 38 else { 39 Boolean result = null; 49 40 String imageFilename = args[0]; 50 int classifierType = Integer.parseInt(args[1]); 51 52 String result = null; 41 String classifierType = args[1]; 53 42 //Execute classifierType defined from arguement 54 43 switch(classifierType){ 55 case 1:56 result = classifier01(imageFilename);44 case "houghlinesP": 45 result = setup_HoughLineP(imageFilename); //true or false 57 46 break; 58 case 2:47 default: 59 48 System.out.println("unknown"); 60 49 break; 61 } 62 50 } 63 51 //Write output to disc 64 52 File log = new File("log.txt"); 65 53 FileWriter fileWriter = new FileWriter(log, true); 66 54 BufferedWriter bw = new BufferedWriter(fileWriter); 67 bw.write(result + classifierType + '\n');68 bw.close();69 70 55 //Split output by tab for processing in next java program 56 //imageFilename = 1, result = 3, classifierType = 4 57 bw.write("Filename:" + '\t' + imageFilename + '\t' + "Classified as:" + '\t' + result + '\t' + classifierType + '\n'); 58 bw.close(); 71 59 } 72 60 } … … 75 63 } 76 64 } 77 private static String classifier01(String filename){ 65 //Returns 66 //True = 1 + Filename + Status 67 //False= 0 + Filename + Status 68 private static Boolean setup_HoughLineP(String filename){ 78 69 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 79 70 Boolean isSheetMusic = null; … … 97 88 Imgproc.line(edgesDetectedRGB, new Point(l[0], l[1]), new Point(l[2], l[3]), new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0); 98 89 } 90 99 91 //Convert MAT into a BufferedImage 100 92 BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB); 101 93 //Calculate if its sheet music or not 102 isSheetMusic = Classifier(toBeClassifiedImg);94 isSheetMusic = classifier_HoughLineP(toBeClassifiedImg); 103 95 104 96 //Save Processed Image … … 109 101 processedFile = "proc_F_"+filename; 110 102 } 111 imwrite(processedFile, edgesDetectedRGB); 112 113 //Display Results 114 //HighGui.imshow("Source", original); 115 //HighGui.imshow("Just Edges", justEdges); //TESTING 116 //HighGui.imshow("Detected Lines (in red) - Standard Hough Line Transform", edgesDetectedRGB); 117 //HighGui.imshow("Detected Lines (in red) - Probabilistic Line Transform", edgesDetectedRGBProb); 118 119 // Wait and Exit 120 //HighGui.waitKey(); 121 //System.exit(0); 122 103 imwrite(processedFile, edgesDetectedRGB); 123 104 } 124 105 catch(Exception e){ 125 106 System.err.println(e); 126 107 } 127 if (isSheetMusic == true){ 128 return (1 + "\t" + "Filename: " + filename + " Status: " + isSheetMusic +"\t" );} 129 130 else{ 131 return (0 + "\t" + "Filename: " + filename + " Status: " + isSheetMusic +"\t" );} 132 } 133 134 private static boolean Classifier(BufferedImage img){ 108 return isSheetMusic; 109 /* 110 if (isSheetMusic == true){ 111 return (1 + "\t" + "Filename: " + filename + " Status: " + isSheetMusic +"\t" ); 112 } 113 else{ 114 return (0 + "\t" + "Filename: " + filename + " Status: " + isSheetMusic +"\t" ); 115 } */ 116 } 117 118 //****************** 119 //INTERNAL FUNCTIONS 120 //****************** 121 private static boolean classifier_HoughLineP(BufferedImage img){ 135 122 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 136 123 try { 137 124 //Read file 138 //BufferedImage img = ImageIO.read(new File(processedFile));139 125 int x = img.getWidth(); 140 126 int y = img.getHeight(); … … 142 128 int redCount = 0; 143 129 float percentage = 0; 144 145 130 //Go Thru every pixel 146 131 for(int i=0; i < y; i++){ … … 157 142 //Calculate percentage of Red in image 158 143 percentage = ((float)redCount/(float)pixelCount)*(float)100; 159 160 161 144 //If more than %10 and less than %50 then its sheet music! 162 if(percentage > 10 && percentage < 50){ //MAKE THESE CONSTANTS!!145 if(percentage > 10 && percentage < 50){ 163 146 return true;} 164 147 } … … 168 151 return false; 169 152 } 170 171 153 private static BufferedImage toBufferedImage(Mat mat){ 172 154 //MOSTLY COPY PASTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! … … 189 171 } 190 172 return null; 191 } 192 193 173 } 194 174 }
Note:
See TracChangeset
for help on using the changeset viewer.