Changeset 33170 for other-projects
- Timestamp:
- 2019-06-20T20:42:56+12:00 (5 years ago)
- Location:
- other-projects/is-sheet-music-encore/trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/is-sheet-music-encore/trunk/Makefile
r33066 r33170 14 14 cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MU-hathiFullIDList.txt MU 15 15 cd java-gen-corpus; java javaGenValidIDList gen-500-MU-hathiFullIDList.txt 500 gen-500-MU-hathiValidIDList.txt 16 #cd java-gen-corpus; rm compact_metadata_temp.xml17 #cd java-gen-corpus; rm metadata_temp.xml18 16 ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MU-hathiValidIDList.txt 19 17 … … 24 22 cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-BK-hathiFullIDList.txt BK 25 23 cd java-gen-corpus; java javaGenValidIDList gen-500-BK-hathiFullIDList.txt 500 gen-500-BK-hathiValidIDList.txt 26 #cd java-gen-corpus; rm compact_metadata_temp.xml27 #cd java-gen-corpus; rm metadata_temp.xml28 24 ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-BK-hathiValidIDList.txt 29 25 … … 34 30 cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-SE-hathiFullIDList.txt SE 35 31 cd java-gen-corpus; java javaGenValidIDList gen-500-SE-hathiFullIDList.txt 500 gen-500-SE-hathiValidIDList.txt 36 #cd java-gen-corpus; rm compact_metadata_temp.xml37 #cd java-gen-corpus; rm metadata_temp.xml38 32 ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-SE-hathiValidIDList.txt 39 33 … … 44 38 cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MP-hathiFullIDList.txt MP 45 39 cd java-gen-corpus; java javaGenValidIDList gen-500-MP-hathiFullIDList.txt 500 gen-500-MP-hathiValidIDList.txt 46 #cd java-gen-corpus; rm compact_metadata_temp.xml47 #cd java-gen-corpus; rm metadata_temp.xml48 40 ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MP-hathiValidIDList.txt 49 41 … … 54 46 cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MX-hathiFullIDList.txt MX 55 47 cd java-gen-corpus; java javaGenValidIDList gen-500-MX-hathiFullIDList.txt 500 gen-500-MX-hathiValidIDList.txt 56 #cd java-gen-corpus; rm compact_metadata_temp.xml 57 #cd java-gen-corpus; rm metadata_temp.xml 48 58 49 ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MX-hathiValidIDList.txt 59 50 51 #*********** 52 #CLASSIFIERS 53 #*********** 60 54 55 #HoughLinesP 56 run-classifier-houghlinesP-test: 57 #Compile 58 cd image-identification-terminal; javac javaAccuracyCalculator.java 59 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java; 60 #Run javaImageClassifier on all images in TestImages 61 @echo starting classfier 62 @date 63 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP log-houghlinesP-test.txt -test 64 @echo finished classifier 65 @date 66 #Calculate the Accuracy of the classifier 67 cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-test.txt houghlinesP results.txt 68 #Display output of javaImageClassifier 69 cd image-identification-terminal; less log-houghlinesP-test.txt 70 #Display output of javaAccuracyCalculator 71 cd image-identification-terminal; less results.txt 61 72 73 run-classifier-houghlinesP-all: 74 #Compile 75 cd image-identification-terminal; javac javaAccuracyCalculator.java 76 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java; 77 #Run javaImageClassifier on all images in MU 78 @echo starting classfier 79 @date 80 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP log-houghlinesP-MU.txt -all 81 @echo finished classifier 82 @date 83 #Calculate the Accuracy of the classifier 84 cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-MU.txt houghlinesP results.txt 85 #Display output of javaImageClassifier 86 cd image-identification-terminal; less log-houghlinesP-MU.txt 87 #Display output of javaAccuracyCalculator 88 cd image-identification-terminal; less results.txt 89 90 #HoughLinesP_refined 91 run-classifier-houghlinesP-refined-test: 92 #Compile 93 cd image-identification-terminal; javac javaAccuracyCalculator.java 94 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java; 95 #Run javaImageClassifier on all images in TestImages 96 @echo starting classfier 97 @date 98 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP-refined log-houghlinesP-refined-test.txt -test 99 @echo finished classifier 100 @date 101 #Calculate the Accuracy of the classifier 102 cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-refined-test.txt houghlinesP-refined results.txt 103 #Display output of javaImageClassifier 104 cd image-identification-terminal; less log-houghlinesP-refined-test.txt 105 #Display output of javaAccuracyCalculator output 106 cd image-identification-terminal; less results.txt 107 108 run-classifier-houghlinesP-refined-all: 109 #Compile 110 cd image-identification-terminal; javac javaAccuracyCalculator.java 111 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java; 112 #Run javaImageClassifier on all images in MU 113 @echo starting classfier 114 @date 115 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP log-houghlinesP-refined-MU.txt -all 116 @echo finished classifier 117 @date 118 #Calculate the Accuracy of the classifier 119 cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-refined-MU.txt houghlinesP results.txt 120 #Display output of javaImageClassifier 121 cd image-identification-terminal; less log-houghlinesP-refined-MU.txt 122 #Display output of javaAccuracyCalculator 123 cd image-identification-terminal; less results.txt 124 125 run-all: 126 #Compile 127 cd image-identification-terminal; javac javaAccuracyCalculator.java 128 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java; 129 #Run javaImageClassifier on all images in MU 130 @echo starting houghlinesP classfier 131 @date 132 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP log-houghlinesP-MU.txt -all 133 @echo finished houghlinesP classifier 134 @date 135 @echo starting houghlinesP-refined classfier 136 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP-refined log-houghlinesP-refined-MU.txt -all 137 @echo finished houghlinesP-refined classifier 138 @date 139 #Calculate the Accuracy of the classifier 140 cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-MU.txt houghlinesP results.txt 141 cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-refined-MU.txt houghlinesP-refined results.txt 142 #Display the results 143 cd image-identification-terminal; less results.txt 144 cd image-identification-terminal; less log-houghlinesP-MU.txt 145 cd image-identification-terminal; less log-houghlinesP-refined-MU.txt 146 -
other-projects/is-sheet-music-encore/trunk/download-images/imageErrors.txt
r33110 r33170 10 10 SE/uiuo.ark+=13960=t4nk57820-7.png invalid or incomplete server response 11 11 SE/uiuo.ark+=13960=t63556b5c-5.png invalid or incomplete server response 12 MU/mdp.39015096590958-10.png no server avaiable to complete request 13 MU/mdp.39015096654648-5.png no server avaiable to complete request 14 MU/nc01.ark+=13960=t9w11r982-7 no server avaiable to compelte request -
other-projects/is-sheet-music-encore/trunk/image-identification-development/.idea/workspace.xml
r33110 r33170 4 4 <list default="true" readonly="true" id="9bad4f92-4a7d-46a2-b6f0-94214c9f55cc" name="Default" comment=""> 5 5 <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> 6 <change beforePath="$PROJECT_DIR$/Test_HoughLineP.png" beforeDir="false" afterPath="$PROJECT_DIR$/Test_HoughLineP.png" afterDir="false" />7 6 <change beforePath="$PROJECT_DIR$/out/production/image-identification/Main.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/image-identification/Main.class" afterDir="false" /> 8 7 <change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" /> … … 21 20 <entry file="file://$PROJECT_DIR$/src/Main.java"> 22 21 <provider selected="true" editor-type-id="text-editor"> 23 <state relative-caret-position=" 694">24 <caret line="1 74" column="36" lean-forward="true" selection-start-line="174" selection-start-column="36" selection-end-line="174" selection-end-column="36" />22 <state relative-caret-position="337"> 23 <caret line="187" column="68" lean-forward="true" selection-start-line="187" selection-start-column="68" selection-end-line="187" selection-end-column="68" /> 25 24 <folding> 26 25 <element signature="imports" expanded="true" /> … … 39 38 </option> 40 39 </component> 41 <component name="ProjectFrameBounds" extendedState=" 6">42 <option name="x" value=" 712" />43 <option name="y" value=" 69" />44 <option name="width" value=" 1350" />45 <option name="height" value=" 850" />40 <component name="ProjectFrameBounds" extendedState="4"> 41 <option name="x" value="992" /> 42 <option name="y" value="52" /> 43 <option name="width" value="928" /> 44 <option name="height" value="1028" /> 46 45 </component> 47 46 <component name="ProjectView"> … … 128 127 </component> 129 128 <component name="ToolWindowManager"> 130 <frame x="65" y="24" width="1855" height="1056" extended-state="6" /> 129 <frame x="992" y="52" width="928" height="1028" extended-state="4" /> 130 <editor active="true" /> 131 131 <layout> 132 132 <window_info anchor="right" id="Palette" order="4" /> … … 138 138 <window_info anchor="bottom" id="Event Log" order="1" side_tool="true" /> 139 139 <window_info anchor="right" id="Maven Projects" order="3" /> 140 <window_info a nchor="bottom" id="Run" order="6" weight="0.26789367" />140 <window_info active="true" anchor="bottom" id="Run" order="6" visible="true" weight="0.22526316" /> 141 141 <window_info anchor="bottom" id="Version Control" order="2" /> 142 142 <window_info anchor="bottom" id="Terminal" order="0" weight="0.42638037" /> … … 198 198 <entry file="file://$PROJECT_DIR$/src/Main.java"> 199 199 <provider selected="true" editor-type-id="text-editor"> 200 <state relative-caret-position="2430"> 201 <caret line="162" lean-forward="true" selection-start-line="162" selection-end-line="162" /> 202 <folding> 203 <element signature="imports" expanded="true" /> 204 </folding> 205 </state> 206 </provider> 207 </entry> 208 <entry file="file://$PROJECT_DIR$/src/Main.java"> 209 <provider selected="true" editor-type-id="text-editor"> 210 <state relative-caret-position="1785"> 211 <caret line="119" column="109" lean-forward="true" selection-start-line="119" selection-start-column="109" selection-end-line="119" selection-end-column="109" /> 212 <folding> 213 <element signature="imports" expanded="true" /> 214 </folding> 215 </state> 216 </provider> 217 </entry> 218 <entry file="file://$PROJECT_DIR$/src/Main.java"> 219 <provider selected="true" editor-type-id="text-editor"> 220 <state relative-caret-position="2610"> 221 <caret line="174" column="36" lean-forward="true" selection-start-line="174" selection-start-column="36" selection-end-line="174" selection-end-column="36" /> 222 <folding> 223 <element signature="imports" expanded="true" /> 224 </folding> 225 </state> 226 </provider> 227 </entry> 228 <entry file="file://$PROJECT_DIR$/src/Main.java"> 229 <provider selected="true" editor-type-id="text-editor"> 200 230 <state relative-caret-position="1620"> 201 231 <caret line="108" column="29" lean-forward="true" selection-start-line="108" selection-start-column="29" selection-end-line="108" selection-end-column="29" /> … … 345 375 <entry file="file://$PROJECT_DIR$/src/Main.java"> 346 376 <provider selected="true" editor-type-id="text-editor"> 347 <state relative-caret-position=" 694">348 <caret line="1 74" column="36" lean-forward="true" selection-start-line="174" selection-start-column="36" selection-end-line="174" selection-end-column="36" />377 <state relative-caret-position="337"> 378 <caret line="187" column="68" lean-forward="true" selection-start-line="187" selection-start-column="68" selection-end-line="187" selection-end-column="68" /> 349 379 <folding> 350 380 <element signature="imports" expanded="true" /> -
other-projects/is-sheet-music-encore/trunk/image-identification-development/src/Main.java
r33110 r33170 100 100 Mat edgesDetected = new Mat(); 101 101 Mat edgesDetectedRGB = new Mat(); 102 Mat forOTSU = new Mat();103 102 Mat edgesDetectedRGBProb; 103 Mat edgeDoesntMakeSense; 104 104 Mat justEdges; //TESTING 105 String default_file = "TestImages/houghlineTest.png"; 105 //String default_file = "TestImages/NotSheetMusic01.png"; 106 String default_file = "TestImages/NotSheetMusic02.png"; 107 //String default_file = "TestImages/SheetMusic01.png"; 108 //String default_file = "TestImages/SheetMusic02.png"; 109 //String default_file = "TestImages/vLine.png"; 106 110 String filename = ((args.length > 0) ? args[0] : default_file); 107 111 … … 110 114 // Edge detection 111 115 //01 CANNY 112 //Imgproc.Canny(original, edgesDetected, 50, 200, 3, false); 116 Imgproc.Canny(original, edgesDetected, 50, 200, 3, false); 117 //Imgproc.Canny(original, edgesDetected,80, 120); 113 118 //02 BINARYINV 114 Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV,15, 2);119 //Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV,15, 2); 115 120 //03 BINARY 116 121 //Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY,15, 2); … … 122 127 123 128 124 //Convert to RGB 129 //Convert to RGB for future use 125 130 Imgproc.cvtColor(edgesDetected, edgesDetectedRGB, Imgproc.COLOR_GRAY2BGR); 126 131 justEdges = edgesDetectedRGB.clone();//TESTING 127 128 // Standard Hough Line Transform 129 Mat lines = new Mat(); // will hold the results of the detection 132 edgesDetectedRGBProb = edgesDetectedRGB.clone(); 133 edgeDoesntMakeSense = edgesDetectedRGB.clone(); 134 135 Mat linesP = new Mat(); // will hold the results of the detection 130 136 //(edgeDetectedImage, outputOfDetection(r,Ξ), resolution of rho, resolution of theta, threshold (minimum num of intersections) 131 Imgproc.HoughLines(edgesDetected, lines, 1, Math.PI / 180.0, 350); // runs the actual detection 132 //Imgproc.HoughLines(edgesDetected, lines, 5.0, 4.0, 7); // runs the actual detection 133 134 //make some test images. black and white. row of white row of black. call hough transform. check if its displaying as expected 135 //make sure res of 0 is appropriate, try 360 136 //expect theta values of 0+- 137 //try greyscale image 138 139 140 for (int i = 0; i < lines.cols(); i++) { 141 double rho = lines.get(0, i)[0]; 142 double theta = lines.get(0, i)[1]; 143 double cosTheta = Math.cos(theta); 144 double sinTheta = Math.sin(theta); 145 double x0 = cosTheta * rho; 146 double y0 = sinTheta * rho; 147 double xpt1 = x0 + 10000 * (-sinTheta); 148 double ypt1 = y0 + 10000 * (cosTheta); 149 double xpt2 = x0 - 10000 * (-sinTheta); 150 double ypt2 = y0 - 10000 * (cosTheta); 151 double angle = Core.fastAtan2((float)ypt2 - (float)ypt1, (float)xpt2 - (float)xpt1) * (Math.PI/180.0); 152 Point pt1 = new Point(xpt1, ypt1); 153 Point pt2 = new Point(xpt2, ypt2); 154 Imgproc.line(edgesDetectedRGB, pt1, pt2, new Scalar(0, 0, 255), 3, Imgproc.LINE_AA,0); 155 System.out.println("rho: " + rho + '\n' + "theta: " + theta + '\n' + "angle: " + angle); 137 138 double minLineLength = edgesDetectedRGB.size().width/4; 139 Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 180, 50, minLineLength, 10); // runs the actual detection 140 141 142 143 //Imgproc.HoughLinesP(edgesDetected,linesP,1,Math.PI/2, 50, 80, 5); 144 // Draw the lines 145 for (int x = 0; x < linesP.rows(); x++) { 146 double[] l = linesP.get(x, 0); 147 148 //Find angle that line is at 149 //double rho = linesP.get(x, 0)[0]; 150 //double theta = linesP.get(x, 0)[1]; 151 //double cosTheta = Math.cos(theta); 152 //double sinTheta = Math.sin(theta); 153 //double x0 = cosTheta * rho; 154 //double y0 = sinTheta * rho; 155 //double xpt1 = x0 + 1000 * (-sinTheta); 156 //double ypt1 = y0 + 1000 * (cosTheta); 157 //double xpt2 = x0 - 1000 * (-sinTheta); 158 //double ypt2 = y0 - 1000 * (cosTheta); 159 //double angle = Math.atan2((float)ypt2 - (float)ypt1, (float)xpt2 - (float)xpt1)*(Math.PI); 160 //double testAngle = (ypt2 - ypt1)/(xpt2 - xpt1); 161 162 //New angles 163 Point p1 = new Point(l[0], l[1]); 164 Point p2 = new Point(l[2], l[3]); 165 double m = Math.abs(p2.y - p1.y)/(p2.x - p1.x); 166 //System.out.println(l[0]); 167 //System.out.println(l[1]); 168 //System.out.println(l[2]); 169 //System.out.println(l[3]); 170 171 172 173 174 175 176 if(m<=0.1) { 177 //System.out.println("m: " + m); 178 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); 179 } 180 156 181 } 157 158 /* 159 for (int x = 0; x < lines.rows(); x++) { 160 double rho = lines.get(x, 0)[0]; 161 double theta = lines.get(x, 0)[1]; 162 double cosTheta = Math.cos(theta); 163 double sinTheta = Math.sin(theta); //CONVERT to Cartisean coord 164 double x0 = cosTheta * rho; 165 double y0 = sinTheta * rho; 166 167 double xpt1 = Math.round(x0 + 10000 * (-sinTheta)); 168 double ypt1 = Math.round(y0 + 10000 * (cosTheta)); 169 double xpt2 = Math.round(x0 - 10000 * (-sinTheta)); 170 double ypt2 = Math.round(y0 - 10000 * (cosTheta)); 171 double angle = Core.fastAtan2((float)ypt2 - (float)ypt1, (float)xpt2 - (float)xpt1) * (Math.PI/180.0); 172 173 Point pt1 = new Point(xpt1, ypt1); 174 Point pt2 = new Point(xpt2, ypt2); 175 Imgproc.line(edgesDetectedRGB, pt1, pt2, new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0); 176 177 System.out.println("rho: " + rho + '\n' + "theta: " + theta + '\n' + "angle: " + angle); 178 } 179 */ 180 182 //Point is a co ordinate (x, y) 183 //Prove by finding number of points from one end to other: 184 //Get width of image. 185 System.out.println("every matrix widths: "+edgesDetectedRGB.size().width); 186 File filenameTest = new File("TestImages/NotSheetMusic02.png"); 187 BufferedImage i = ImageIO.read(filenameTest); 188 System.out.println("input image width: "+ i.getWidth()); 189 190 BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB); 191 System.out.println("Result: " + Classifier(toBeClassifiedImg)); 181 192 182 193 //Display Results 183 194 //HighGui.imshow("Source", original); 184 HighGui.imshow("Just Edges", justEdges); //TESTING 185 HighGui.imshow("Detected Lines (in red) - Standard Hough Line Transform", edgesDetectedRGB); 186 //HighGui.imshow("Detected Lines (in red) - Probabilistic Line Transform", edgesDetectedRGBProb); 195 //HighGui.imshow("Just Edges", justEdges); //TESTING 196 HighGui.imshow("Detected Lines (in red) - positive", edgesDetectedRGB); 197 //HighGui.imshow("Detected Lines (in red) - negative", edgesDetectedRGBProb); 198 //HighGui.imshow("Detected Lines (in red) - edgeDoesntMakeSense", edgeDoesntMakeSense); 187 199 188 200 // Wait and Exit -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/Makefile
r33141 r33170 2 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 3 3 4 run-classifier-houghlinesP:4 testrun-classifier-houghlinesP: 5 5 #Compile 6 6 javac javaAccuracyCalculator.java -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaAccuracyCalculator.java
r33141 r33170 4 4 import java.io.FileReader; 5 5 import java.io.FileWriter; 6 import java.util.*; 6 7 public class javaAccuracyCalculator{ 7 8 … … 15 16 } 16 17 else { 18 Date d = new Date(); 17 19 String inputFilename = args[0]; 18 20 String classifierType = args[1]; … … 23 25 String line = null; 24 26 String[] item; 25 float trueAccuracyRate =0;26 float falseAccuracyRate =0;27 int trueCount =0;28 int falseCount = 0;27 float trueAccuracyRate =0; 28 float falseAccuracyRate =0; 29 float overallAccuracyRate=0; 30 // 29 31 int sheetMusicCount = 0; 30 32 int notSheetMusicCount = 0; 33 // 34 int truePositive = 0; 35 int trueNegative = 0; 36 // 37 int falsePositive = 0; 38 int falseNegative = 0; 39 31 40 //Splits into each record, since readLine splits by "\n" 32 41 while ((line = buf.readLine()) != null) { 33 42 item = line.split("\t"); 34 43 //Calculate AccuracyRates 35 if(item[1].contains(" TestImages/SheetMusic/")){44 if(item[1].contains("/SheetMusic/")){ 36 45 sheetMusicCount++; 37 46 if(item[3].equals("true")){ 38 trueCount++; 47 truePositive++; 48 } 49 else if(item[3].equals("false")){ 50 falseNegative++; 51 } 52 else { 53 System.err.println("Error log file"); 39 54 } 40 55 } 41 if(item[1].contains(" TestImages/NotSheetMusic/")){56 if(item[1].contains("/NotSheetMusic/")){ 42 57 notSheetMusicCount++; 43 58 if(item[3].equals("true")){ 44 falseCount++; 59 falsePositive++; 60 } 61 else if(item[3].equals("false")){ 62 trueNegative++; 63 } 64 else{ 65 System.err.println("Error log file"); 45 66 } 46 67 } 47 68 } 48 69 49 //Amount of sheetMusic classified images / total amount of images read50 trueAccuracyRate = ((float)trueCount/(float)sheetMusicCount)*(float)100;51 //Amount of notSheetMusic classified images / total amount of images read52 falseAccuracyRate = ((float)falseCount/(float)notSheetMusicCount)*(float)100;53 70 54 fw.write("Classifier: " + classifierType + '\t' + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\t' + "NotSheetMusicAccuracyRate :" + falseAccuracyRate + "%" + "\n"); 71 //Correctly identified SheetMusic as SheetMusic 72 trueAccuracyRate = ((float)truePositive/(float)sheetMusicCount)*(float)100; 73 74 //Amount of Correctly identified NotSheetSheetMusic as NotSheetMusic 75 falseAccuracyRate = ((float)trueNegative/(float)notSheetMusicCount)*(float)100; 76 77 overallAccuracyRate = (truePositive + trueNegative)/(float)(sheetMusicCount+notSheetMusicCount)*(float)100; 78 79 fw.write("Date: " + d.toString() + '\n' 80 + "Classifier: " + classifierType + '\n' 81 + "truePositive: " + truePositive + '\n' 82 + "falseNegative: " + falseNegative + '\n' 83 + "falsePositve: " + falsePositive + '\n' 84 + "trueNegative: " + trueNegative + '\n' 85 + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\n' 86 + "NotSheetMusicAccuracyRate: " + falseAccuracyRate + "%" + '\n' 87 + "OverallAccuracyRate: " + overallAccuracyRate + "%" + '\n' + '\n'); 55 88 buf.close(); 56 89 fw.close(); -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaImageClassifier.java
r33141 r33170 33 33 public static void main(String[] args) { 34 34 try { 35 if (args.length != 2) {36 System.out.println("Usage: imageClassifier <inputFilename> <classifierType> ");35 if (args.length != 3) { 36 System.out.println("Usage: imageClassifier <inputFilename> <classifierType> <outputFilename>"); 37 37 } 38 38 else { 39 39 Boolean result = null; 40 40 String imageFilename = args[0]; 41 String classifierType = args[1]; 41 String classifierType = args[1]; 42 String outputFilename = args[2]; 42 43 //Execute classifierType defined from arguement 43 44 switch(classifierType){ 44 45 case "houghlinesP": 45 result = setup_HoughLineP(imageFilename); //true or false 46 result = setup_HoughLinesP(imageFilename); //true or false 47 break; 48 case "houghlinesP-refined": 49 result = setup_HoughLinesP_refined(imageFilename); 46 50 break; 47 51 default: 48 System.out.println("unknown ");52 System.out.println("unknown algorithm"); 49 53 break; 50 54 } 51 55 //Write output to disc 52 File log = new File( "log.txt");56 File log = new File(outputFilename); 53 57 FileWriter fileWriter = new FileWriter(log, true); 54 58 BufferedWriter bw = new BufferedWriter(fileWriter); … … 66 70 //True = 1 + Filename + Status 67 71 //False= 0 + Filename + Status 68 private static Boolean setup_HoughLineP(String filename){ 72 73 //****************** 74 //CLASSIFIER FUNCTIONS 75 //****************** 76 private static Boolean setup_HoughLinesP(String filename){ 69 77 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 70 78 Boolean isSheetMusic = null; … … 85 93 // Draw the lines 86 94 for (int x = 0; x < linesP.rows(); x++) { 87 double[] l = linesP.get(x, 0);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);95 double[] l = linesP.get(x, 0); 96 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); 89 97 } 90 98 … … 92 100 BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB); 93 101 //Calculate if its sheet music or not 94 isSheetMusic = classifier_HoughLineP(toBeClassifiedImg); 95 96 //Save Processed Image 97 String processedFile = filename; 98 if (isSheetMusic == true) { 99 processedFile = "proc_T_"+filename; 100 }else { 101 processedFile = "proc_F_"+filename; 102 } 103 imwrite(processedFile, edgesDetectedRGB); 102 isSheetMusic = classifier_HoughLinesP(toBeClassifiedImg); 104 103 } 105 104 catch(Exception e){ … … 107 106 } 108 107 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 108 } 117 109 110 private static Boolean setup_HoughLinesP_refined(String filename){ 111 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 112 Boolean isSheetMusic = null; 113 try{ 114 //Variables 115 Mat edgesDetected = new Mat(); 116 Mat edgesDetectedRGB = new Mat(); 117 Mat edgesDetectedRGBProb; 118 // Load an image 119 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 120 // Edge detection 121 Imgproc.Canny(original, edgesDetected, 50, 200, 3, false); 122 //Copy edges to the images that will display the results in BGR 123 Imgproc.cvtColor(edgesDetected, edgesDetectedRGB, Imgproc.COLOR_GRAY2BGR); 124 // Probabilistic Line Transform 125 Mat linesP = new Mat(); // will hold the results of the detection 126 double minLineLength = edgesDetectedRGB.size().width/4; 127 Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 180, 50, minLineLength, 10);// runs the actual detection 128 // Draw the lines 129 130 for (int x = 0; x < linesP.rows(); x++) { 131 double[] l = linesP.get(x, 0); 132 //New angles 133 Point p1 = new Point(l[0], l[1]); 134 Point p2 = new Point(l[2], l[3]); 135 double m = Math.abs(p2.y - p1.y)/(p2.x - p1.x); 136 //System.out.println(l[0]); 137 //System.out.println(l[1]); 138 //System.out.println(l[2]); 139 //System.out.println(l[3]); 140 if(m<0.1) { 141 //System.out.println("m: " + m); 142 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); 143 } 144 } 145 146 //Convert MAT into a BufferedImage 147 BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB); 148 //Calculate if its sheet music or not 149 isSheetMusic = classifier_HoughLinesP(toBeClassifiedImg); 150 151 } 152 catch(Exception e){ 153 System.err.println(e); 154 } 155 return isSheetMusic; 156 } 157 118 158 //****************** 119 159 //INTERNAL FUNCTIONS 120 160 //****************** 121 private static boolean classifier_HoughLine P(BufferedImage img){161 private static boolean classifier_HoughLinesP(BufferedImage img){ 122 162 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 123 163 try { … … 143 183 percentage = ((float)redCount/(float)pixelCount)*(float)100; 144 184 //If more than %10 and less than %50 then its sheet music! 145 if(percentage > 10 && percentage < 50){185 if(percentage > CLASSIFIER_HOUGHLINESP_MIN && percentage < CLASSIFIER_HOUGHLINESP_MAX){ 146 186 return true;} 147 187 } -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/results.txt
r33110 r33170 1 Classifier:Probabilistic HoughLines 30.08% 1 Date: Thu Jun 20 18:40:41 NZST 2019 2 Classifier: houghlinesP 3 truePositive: 3098 4 falseNegative: 63 5 falsePositve: 624 6 trueNegative: 1216 7 SheetMusicAccuracyRate: 98.00696% 8 NotSheetMusicAccuracyRate: 66.08695% 9 OverallAccuracyRate: 86.26274% 10 11 Date: Thu Jun 20 18:40:42 NZST 2019 12 Classifier: houghlinesP-refined 13 truePositive: 1666 14 falseNegative: 1495 15 falsePositve: 123 16 trueNegative: 1717 17 SheetMusicAccuracyRate: 52.70484% 18 NotSheetMusicAccuracyRate: 93.315216% 19 OverallAccuracyRate: 67.64648% 20 -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/runClassifer.sh
r33141 r33170 1 1 #!/bin/bash 2 2 3 if [ $# != 2] ; then4 echo "Usage: ./testClassifier.sh file_name classifier_type " 1>&23 if [ $# != 4 ] ; then 4 echo "Usage: ./testClassifier.sh file_name classifier_type output_filename num_doc(-a = all -test = 100)" 1>&2 5 5 exit 1 6 6 fi … … 8 8 folder_name=$1 9 9 classifier_type=$2 10 #Runs javaImageClassifier on ALL images 11 for file_name in $folder_name/*/*.png; do 12 echo $file_name 13 echo "" 14 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 $file_name $classifier_type 15 done 10 output_filename=$3 11 num_doc=$4 12 i=0 13 case "$4" in 14 -all) 15 #Runs javaImageClassifier on ALL images 16 for file_name in $folder_name/*/*.png; do 17 echo $file_name 18 echo $output_filename 19 echo $i 20 echo "" 21 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 $file_name $classifier_type $output_filename 22 i=$[$i+1] 23 done 24 ;; 25 -test) 26 #Runs javaImageClassifier on 100 images 27 for file_name in $folder_name/*/*.png; do 28 if [ $i -lt 200 ] ; then 29 echo $file_name 30 echo $output_filename 31 echo $i 32 echo "" 33 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 $file_name $classifier_type $output_filename 34 i=$[$i+1] 35 else 36 exit 0 37 fi 38 done 39 ;; 40 esac
Note:
See TracChangeset
for help on using the changeset viewer.