Index: /other-projects/is-sheet-music-encore/trunk/Makefile
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/Makefile	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/Makefile	(revision 33170)
@@ -14,6 +14,4 @@
 	cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MU-hathiFullIDList.txt MU
 	cd java-gen-corpus; java javaGenValidIDList gen-500-MU-hathiFullIDList.txt 500 gen-500-MU-hathiValidIDList.txt
-	#cd java-gen-corpus; rm compact_metadata_temp.xml
-	#cd java-gen-corpus; rm metadata_temp.xml
 	./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MU-hathiValidIDList.txt
 
@@ -24,6 +22,4 @@
 	cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-BK-hathiFullIDList.txt BK
 	cd java-gen-corpus; java javaGenValidIDList gen-500-BK-hathiFullIDList.txt 500 gen-500-BK-hathiValidIDList.txt
-	#cd java-gen-corpus; rm compact_metadata_temp.xml
-	#cd java-gen-corpus; rm metadata_temp.xml
 	./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-BK-hathiValidIDList.txt
 
@@ -34,6 +30,4 @@
 	cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-SE-hathiFullIDList.txt SE
 	cd java-gen-corpus; java javaGenValidIDList gen-500-SE-hathiFullIDList.txt 500 gen-500-SE-hathiValidIDList.txt
-	#cd java-gen-corpus; rm compact_metadata_temp.xml
-	#cd java-gen-corpus; rm metadata_temp.xml
 	./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-SE-hathiValidIDList.txt
 
@@ -44,6 +38,4 @@
 	cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MP-hathiFullIDList.txt MP
 	cd java-gen-corpus; java javaGenValidIDList gen-500-MP-hathiFullIDList.txt 500 gen-500-MP-hathiValidIDList.txt
-	#cd java-gen-corpus; rm compact_metadata_temp.xml
-	#cd java-gen-corpus; rm metadata_temp.xml
 	./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MP-hathiValidIDList.txt
 
@@ -54,8 +46,101 @@
 	cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MX-hathiFullIDList.txt MX
 	cd java-gen-corpus; java javaGenValidIDList gen-500-MX-hathiFullIDList.txt 500 gen-500-MX-hathiValidIDList.txt
-	#cd java-gen-corpus; rm compact_metadata_temp.xml
-	#cd java-gen-corpus; rm metadata_temp.xml
+
 	./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MX-hathiValidIDList.txt
 
+#***********
+#CLASSIFIERS
+#***********
 
+#HoughLinesP
+run-classifier-houghlinesP-test:
+        #Compile
+	cd image-identification-terminal; javac javaAccuracyCalculator.java
+	cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java;
+        #Run javaImageClassifier on all images in TestImages
+	@echo starting classfier
+	@date
+	cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP log-houghlinesP-test.txt -test
+	@echo finished classifier
+	@date
+        #Calculate the Accuracy of the classifier
+	cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-test.txt houghlinesP results.txt
+        #Display output of javaImageClassifier
+	cd image-identification-terminal; less log-houghlinesP-test.txt
+        #Display output of javaAccuracyCalculator
+	cd image-identification-terminal; less results.txt
 
+run-classifier-houghlinesP-all:
+        #Compile
+	cd image-identification-terminal; javac javaAccuracyCalculator.java
+	cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java;
+        #Run javaImageClassifier on all images in MU
+	@echo starting classfier
+	@date
+	cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP log-houghlinesP-MU.txt -all
+	@echo finished classifier
+	@date
+        #Calculate the Accuracy of the classifier
+	cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-MU.txt houghlinesP results.txt
+        #Display output of javaImageClassifier
+	cd image-identification-terminal; less log-houghlinesP-MU.txt
+        #Display output of javaAccuracyCalculator
+	cd image-identification-terminal; less results.txt
+
+#HoughLinesP_refined
+run-classifier-houghlinesP-refined-test:
+        #Compile
+	cd image-identification-terminal; javac javaAccuracyCalculator.java
+	cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java;
+        #Run javaImageClassifier on all images in TestImages
+	@echo starting classfier
+	@date
+	cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP-refined log-houghlinesP-refined-test.txt -test
+	@echo finished classifier
+	@date
+        #Calculate the Accuracy of the classifier
+	cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-refined-test.txt houghlinesP-refined results.txt
+        #Display output of javaImageClassifier
+	cd image-identification-terminal; less log-houghlinesP-refined-test.txt
+        #Display output of javaAccuracyCalculator output
+	cd image-identification-terminal; less results.txt
+
+run-classifier-houghlinesP-refined-all:
+        #Compile
+	cd image-identification-terminal; javac javaAccuracyCalculator.java
+	cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java;
+        #Run javaImageClassifier on all images in MU
+	@echo starting classfier
+	@date
+	cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP log-houghlinesP-refined-MU.txt -all
+	@echo finished classifier
+	@date
+        #Calculate the Accuracy of the classifier
+	cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-refined-MU.txt houghlinesP results.txt
+        #Display output of javaImageClassifier
+	cd image-identification-terminal; less log-houghlinesP-refined-MU.txt
+        #Display output of javaAccuracyCalculator
+	cd image-identification-terminal; less results.txt
+
+run-all:
+        #Compile
+	cd image-identification-terminal; javac javaAccuracyCalculator.java
+	cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaImageClassifier.java; 
+        #Run javaImageClassifier on all images in MU
+	@echo starting houghlinesP classfier
+	@date
+	cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP log-houghlinesP-MU.txt -all
+	@echo finished houghlinesP classifier
+	@date
+	@echo starting houghlinesP-refined classfier
+	cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/download-images/MU houghlinesP-refined log-houghlinesP-refined-MU.txt -all
+	@echo finished houghlinesP-refined classifier
+	@date
+        #Calculate the Accuracy of the classifier
+	cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-MU.txt houghlinesP results.txt
+	cd image-identification-terminal; java javaAccuracyCalculator log-houghlinesP-refined-MU.txt houghlinesP-refined results.txt
+        #Display the results
+	cd image-identification-terminal; less results.txt
+	cd image-identification-terminal; less log-houghlinesP-MU.txt
+	cd image-identification-terminal; less log-houghlinesP-refined-MU.txt
+
Index: /other-projects/is-sheet-music-encore/trunk/download-images/imageErrors.txt
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/download-images/imageErrors.txt	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/download-images/imageErrors.txt	(revision 33170)
@@ -10,2 +10,5 @@
 SE/uiuo.ark+=13960=t4nk57820-7.png	invalid or incomplete server response
 SE/uiuo.ark+=13960=t63556b5c-5.png	invalid or incomplete server response
+MU/mdp.39015096590958-10.png	no server avaiable to complete request
+MU/mdp.39015096654648-5.png		no server avaiable to complete request
+MU/nc01.ark+=13960=t9w11r982-7	no server avaiable to compelte request
Index: /other-projects/is-sheet-music-encore/trunk/image-identification-development/.idea/workspace.xml
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/image-identification-development/.idea/workspace.xml	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/image-identification-development/.idea/workspace.xml	(revision 33170)
@@ -4,5 +4,4 @@
     <list default="true" readonly="true" id="9bad4f92-4a7d-46a2-b6f0-94214c9f55cc" name="Default" comment="">
       <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
-      <change beforePath="$PROJECT_DIR$/Test_HoughLineP.png" beforeDir="false" afterPath="$PROJECT_DIR$/Test_HoughLineP.png" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/out/production/image-identification/Main.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/image-identification/Main.class" afterDir="false" />
       <change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
@@ -21,6 +20,6 @@
         <entry file="file://$PROJECT_DIR$/src/Main.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="694">
-              <caret line="174" column="36" lean-forward="true" selection-start-line="174" selection-start-column="36" selection-end-line="174" selection-end-column="36" />
+            <state relative-caret-position="337">
+              <caret line="187" column="68" lean-forward="true" selection-start-line="187" selection-start-column="68" selection-end-line="187" selection-end-column="68" />
               <folding>
                 <element signature="imports" expanded="true" />
@@ -39,9 +38,9 @@
     </option>
   </component>
-  <component name="ProjectFrameBounds" extendedState="6">
-    <option name="x" value="712" />
-    <option name="y" value="69" />
-    <option name="width" value="1350" />
-    <option name="height" value="850" />
+  <component name="ProjectFrameBounds" extendedState="4">
+    <option name="x" value="992" />
+    <option name="y" value="52" />
+    <option name="width" value="928" />
+    <option name="height" value="1028" />
   </component>
   <component name="ProjectView">
@@ -128,5 +127,6 @@
   </component>
   <component name="ToolWindowManager">
-    <frame x="65" y="24" width="1855" height="1056" extended-state="6" />
+    <frame x="992" y="52" width="928" height="1028" extended-state="4" />
+    <editor active="true" />
     <layout>
       <window_info anchor="right" id="Palette" order="4" />
@@ -138,5 +138,5 @@
       <window_info anchor="bottom" id="Event Log" order="1" side_tool="true" />
       <window_info anchor="right" id="Maven Projects" order="3" />
-      <window_info anchor="bottom" id="Run" order="6" weight="0.26789367" />
+      <window_info active="true" anchor="bottom" id="Run" order="6" visible="true" weight="0.22526316" />
       <window_info anchor="bottom" id="Version Control" order="2" />
       <window_info anchor="bottom" id="Terminal" order="0" weight="0.42638037" />
@@ -198,4 +198,34 @@
     <entry file="file://$PROJECT_DIR$/src/Main.java">
       <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="2430">
+          <caret line="162" lean-forward="true" selection-start-line="162" selection-end-line="162" />
+          <folding>
+            <element signature="imports" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/Main.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="1785">
+          <caret line="119" column="109" lean-forward="true" selection-start-line="119" selection-start-column="109" selection-end-line="119" selection-end-column="109" />
+          <folding>
+            <element signature="imports" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/Main.java">
+      <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="2610">
+          <caret line="174" column="36" lean-forward="true" selection-start-line="174" selection-start-column="36" selection-end-line="174" selection-end-column="36" />
+          <folding>
+            <element signature="imports" expanded="true" />
+          </folding>
+        </state>
+      </provider>
+    </entry>
+    <entry file="file://$PROJECT_DIR$/src/Main.java">
+      <provider selected="true" editor-type-id="text-editor">
         <state relative-caret-position="1620">
           <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,6 +375,6 @@
     <entry file="file://$PROJECT_DIR$/src/Main.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="694">
-          <caret line="174" column="36" lean-forward="true" selection-start-line="174" selection-start-column="36" selection-end-line="174" selection-end-column="36" />
+        <state relative-caret-position="337">
+          <caret line="187" column="68" lean-forward="true" selection-start-line="187" selection-start-column="68" selection-end-line="187" selection-end-column="68" />
           <folding>
             <element signature="imports" expanded="true" />
Index: /other-projects/is-sheet-music-encore/trunk/image-identification-development/src/Main.java
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/image-identification-development/src/Main.java	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/image-identification-development/src/Main.java	(revision 33170)
@@ -100,8 +100,12 @@
             Mat edgesDetected = new Mat();
             Mat edgesDetectedRGB = new Mat();
-            Mat forOTSU = new Mat();
             Mat edgesDetectedRGBProb;
+            Mat edgeDoesntMakeSense;
             Mat justEdges; //TESTING
-            String default_file = "TestImages/houghlineTest.png";
+            //String default_file = "TestImages/NotSheetMusic01.png";
+            String default_file = "TestImages/NotSheetMusic02.png";
+            //String default_file = "TestImages/SheetMusic01.png";
+            //String default_file = "TestImages/SheetMusic02.png";
+            //String default_file = "TestImages/vLine.png";
             String filename = ((args.length > 0) ? args[0] : default_file);
 
@@ -110,7 +114,8 @@
             // Edge detection
             //01 CANNY
-            //Imgproc.Canny(original, edgesDetected, 50, 200, 3, false);
+            Imgproc.Canny(original, edgesDetected, 50, 200, 3, false);
+            //Imgproc.Canny(original, edgesDetected,80, 120);
             //02 BINARYINV
-            Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV,15, 2);
+            //Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV,15, 2);
             //03 BINARY
             //Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY,15, 2);
@@ -122,67 +127,74 @@
 
 
-            //Convert to RGB
+            //Convert to RGB for future use
             Imgproc.cvtColor(edgesDetected, edgesDetectedRGB, Imgproc.COLOR_GRAY2BGR);
             justEdges = edgesDetectedRGB.clone();//TESTING
-
-            // Standard Hough Line Transform
-            Mat lines = new Mat(); // will hold the results of the detection
+            edgesDetectedRGBProb = edgesDetectedRGB.clone();
+            edgeDoesntMakeSense = edgesDetectedRGB.clone();
+
+            Mat linesP = new Mat(); // will hold the results of the detection
             //(edgeDetectedImage, outputOfDetection(r,Îž), resolution of rho, resolution of theta, threshold (minimum num of intersections)
-            Imgproc.HoughLines(edgesDetected, lines, 1, Math.PI / 180.0, 350); // runs the actual detection
-            //Imgproc.HoughLines(edgesDetected, lines, 5.0, 4.0, 7); // runs the actual detection
-
-            //make some test images. black and white. row of white row of black. call hough transform. check if its displaying as expected
-            //make sure res of 0 is appropriate, try 360
-            //expect theta values of 0+-
-            //try greyscale image
-
-
-            for (int i = 0; i < lines.cols(); i++) {
-                double rho = lines.get(0, i)[0];
-                double theta = lines.get(0, i)[1];
-                double cosTheta = Math.cos(theta);
-                double sinTheta = Math.sin(theta);
-                double x0 = cosTheta * rho;
-                double y0 = sinTheta * rho;
-                double xpt1 = x0 + 10000 * (-sinTheta);
-                double ypt1 = y0 + 10000 * (cosTheta);
-                double xpt2 = x0 - 10000 * (-sinTheta);
-                double ypt2 = y0 - 10000 * (cosTheta);
-                double angle = Core.fastAtan2((float)ypt2 - (float)ypt1, (float)xpt2 - (float)xpt1) * (Math.PI/180.0);
-                Point pt1 = new Point(xpt1, ypt1);
-                Point pt2 = new Point(xpt2, ypt2);
-                Imgproc.line(edgesDetectedRGB, pt1, pt2, new Scalar(0, 0, 255), 3, Imgproc.LINE_AA,0);
-                System.out.println("rho: " + rho + '\n' + "theta: " + theta + '\n' + "angle: " + angle);
+
+            double minLineLength = edgesDetectedRGB.size().width/4;
+            Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 180, 50, minLineLength, 10); // runs the actual detection
+
+
+
+            //Imgproc.HoughLinesP(edgesDetected,linesP,1,Math.PI/2, 50, 80, 5);
+            // Draw the lines
+            for (int x = 0; x < linesP.rows(); x++) {
+                double[] l = linesP.get(x, 0);
+
+                //Find angle that line is at
+                //double rho = linesP.get(x, 0)[0];
+                //double theta = linesP.get(x, 0)[1];
+                //double cosTheta = Math.cos(theta);
+                //double sinTheta = Math.sin(theta);
+                //double x0 = cosTheta * rho;
+                //double y0 = sinTheta * rho;
+                //double xpt1 = x0 + 1000 * (-sinTheta);
+                //double ypt1 = y0 + 1000 * (cosTheta);
+                //double xpt2 = x0 - 1000 * (-sinTheta);
+                //double ypt2 = y0 - 1000 * (cosTheta);
+                //double angle =  Math.atan2((float)ypt2 - (float)ypt1, (float)xpt2 - (float)xpt1)*(Math.PI);
+                //double testAngle = (ypt2 - ypt1)/(xpt2 - xpt1);
+
+                //New angles
+                Point p1 = new Point(l[0], l[1]);
+                Point p2 = new Point(l[2], l[3]);
+                double m = Math.abs(p2.y - p1.y)/(p2.x - p1.x);
+                //System.out.println(l[0]);
+                //System.out.println(l[1]);
+                //System.out.println(l[2]);
+                //System.out.println(l[3]);
+
+
+
+
+
+
+                if(m<=0.1) {
+                    //System.out.println("m: " + m);
+                    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);
+                }
+
             }
-
-            /*
-            for (int x = 0; x < lines.rows(); x++) {
-                double rho = lines.get(x, 0)[0];
-                double theta = lines.get(x, 0)[1];
-                double cosTheta = Math.cos(theta);
-                double sinTheta = Math.sin(theta);                //CONVERT to Cartisean coord
-                double x0 = cosTheta * rho;
-                double y0 = sinTheta * rho;
-
-                double xpt1 = Math.round(x0 + 10000 * (-sinTheta));
-                double ypt1 = Math.round(y0 + 10000 * (cosTheta));
-                double xpt2 = Math.round(x0 - 10000 * (-sinTheta));
-                double ypt2 = Math.round(y0 - 10000 * (cosTheta));
-                double angle = Core.fastAtan2((float)ypt2 - (float)ypt1, (float)xpt2 - (float)xpt1) * (Math.PI/180.0);
-
-                Point pt1 = new Point(xpt1, ypt1);
-                Point pt2 = new Point(xpt2, ypt2);
-                Imgproc.line(edgesDetectedRGB, pt1, pt2, new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
-
-                System.out.println("rho: " + rho + '\n' + "theta: " + theta + '\n' + "angle: " + angle);
-            }
-            */
-
+            //Point is a co ordinate (x, y)
+            //Prove by finding number of points from one end to other:
+            //Get width of image.
+            System.out.println("every matrix widths: "+edgesDetectedRGB.size().width);
+            File filenameTest = new File("TestImages/NotSheetMusic02.png");
+            BufferedImage i = ImageIO.read(filenameTest);
+            System.out.println("input image width: "+ i.getWidth());
+
+            BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB);
+            System.out.println("Result: " + Classifier(toBeClassifiedImg));
 
             //Display Results
             //HighGui.imshow("Source", original);
-            HighGui.imshow("Just Edges", justEdges); //TESTING
-            HighGui.imshow("Detected Lines (in red) - Standard Hough Line Transform", edgesDetectedRGB);
-            //HighGui.imshow("Detected Lines (in red) - Probabilistic Line Transform", edgesDetectedRGBProb);
+            //HighGui.imshow("Just Edges", justEdges); //TESTING
+            HighGui.imshow("Detected Lines (in red) - positive", edgesDetectedRGB);
+            //HighGui.imshow("Detected Lines (in red) - negative", edgesDetectedRGBProb);
+            //HighGui.imshow("Detected Lines (in red) - edgeDoesntMakeSense", edgeDoesntMakeSense);
 
             // Wait and Exit
Index: /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/Makefile
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/Makefile	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/Makefile	(revision 33170)
@@ -2,5 +2,5 @@
 #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
 
-run-classifier-houghlinesP:
+testrun-classifier-houghlinesP:
         #Compile
 	javac javaAccuracyCalculator.java
Index: /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaAccuracyCalculator.java
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaAccuracyCalculator.java	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaAccuracyCalculator.java	(revision 33170)
@@ -4,4 +4,5 @@
 import java.io.FileReader;
 import java.io.FileWriter;
+import java.util.*;
 public class javaAccuracyCalculator{
 					
@@ -15,4 +16,5 @@
 			}
 			else {
+				Date d = new Date();
 				String inputFilename = args[0];
 				String classifierType = args[1];
@@ -23,34 +25,65 @@
 				String line = null;
 				String[] item;
-				float trueAccuracyRate  =0;
-				float falseAccuracyRate =0;
-				int trueCount	= 0;
-				int falseCount  = 0;				
+				float trueAccuracyRate   =0;
+				float falseAccuracyRate  =0;
+				float overallAccuracyRate=0;
+				//
 				int sheetMusicCount	= 0;
 				int notSheetMusicCount	= 0;
+				//
+				int truePositive	= 0;
+				int trueNegative	= 0;
+				//
+				int falsePositive  	= 0;
+				int falseNegative 	= 0;				
+
 				//Splits into each record, since readLine splits by "\n"
 				while ((line = buf.readLine()) != null) {
 					item = line.split("\t");		
 					//Calculate AccuracyRates
-					if(item[1].contains("TestImages/SheetMusic/")){
+					if(item[1].contains("/SheetMusic/")){
 						sheetMusicCount++;
 						if(item[3].equals("true")){
-							trueCount++;
+							truePositive++;
+						}
+						else if(item[3].equals("false")){
+							falseNegative++;
+						}
+						else {
+							System.err.println("Error log file");
 						}
 					}
-					if(item[1].contains("TestImages/NotSheetMusic/")){
+					if(item[1].contains("/NotSheetMusic/")){
 						notSheetMusicCount++;
 						if(item[3].equals("true")){
-							falseCount++;
+							falsePositive++;
+						}
+						else if(item[3].equals("false")){
+							trueNegative++;
+						}
+						else{
+							System.err.println("Error log file");
 						}
 					}						
 				}
 				
-				//Amount of sheetMusic classified images / total amount of images read 
-				trueAccuracyRate = ((float)trueCount/(float)sheetMusicCount)*(float)100;
-				//Amount of notSheetMusic classified images / total amount of images read 
-				falseAccuracyRate = ((float)falseCount/(float)notSheetMusicCount)*(float)100;
 				
-				fw.write("Classifier: " + classifierType + '\t' + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\t' + "NotSheetMusicAccuracyRate :" + falseAccuracyRate + "%" + "\n");		
+				//Correctly identified SheetMusic as SheetMusic
+				trueAccuracyRate = ((float)truePositive/(float)sheetMusicCount)*(float)100;
+
+				//Amount of Correctly identified NotSheetSheetMusic as NotSheetMusic
+				falseAccuracyRate = ((float)trueNegative/(float)notSheetMusicCount)*(float)100;
+				
+				overallAccuracyRate = (truePositive + trueNegative)/(float)(sheetMusicCount+notSheetMusicCount)*(float)100;
+				
+				fw.write("Date: " + d.toString() + '\n'
+					+ "Classifier: " + classifierType + '\n' 
+					+ "truePositive: " 	+ truePositive + '\n' 
+					+ "falseNegative: " + falseNegative + '\n'
+					+ "falsePositve: " 	+ falsePositive + '\n'  
+					+ "trueNegative: " 	+ trueNegative + '\n'
+					+ "SheetMusicAccuracyRate: " 	+ trueAccuracyRate + "%" + '\n'
+					+ "NotSheetMusicAccuracyRate: " + falseAccuracyRate + "%" + '\n'
+					+ "OverallAccuracyRate: " 		+ overallAccuracyRate + "%" + '\n' + '\n');		
 				buf.close();
 				fw.close();								
Index: /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaImageClassifier.java
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaImageClassifier.java	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaImageClassifier.java	(revision 33170)
@@ -33,22 +33,26 @@
     public static void main(String[] args) {  	
         try {
-			if (args.length != 2) {
-			System.out.println("Usage: imageClassifier <inputFilename> <classifierType>");
+			if (args.length != 3) {
+			System.out.println("Usage: imageClassifier <inputFilename> <classifierType> <outputFilename>");
 			}
 			else {
 				Boolean result = null;
 				String imageFilename = args[0];
-				String classifierType = args[1];			
+				String classifierType = args[1];
+				String outputFilename = args[2];			
 				//Execute classifierType defined from arguement
 				switch(classifierType){
 				case "houghlinesP":
-					result = setup_HoughLineP(imageFilename); //true or false
+					result = setup_HoughLinesP(imageFilename); //true or false
+					break;
+				case "houghlinesP-refined":
+					result = setup_HoughLinesP_refined(imageFilename);
 					break;
 				default:
-					System.out.println("unknown");
+					System.out.println("unknown algorithm");
 					break;
 				}			
 				//Write output to disc
-				File log = new File("log.txt");
+				File log = new File(outputFilename);
 				FileWriter fileWriter = new FileWriter(log, true);
 				BufferedWriter bw = new BufferedWriter(fileWriter);
@@ -66,5 +70,9 @@
     //True = 1 + Filename + Status
     //False= 0 + Filename + Status
-    private static Boolean setup_HoughLineP(String filename){
+    
+ //******************
+ //CLASSIFIER FUNCTIONS
+ //******************
+    private static Boolean setup_HoughLinesP(String filename){
 	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
 	Boolean isSheetMusic = null;
@@ -85,6 +93,6 @@
 	    // Draw the lines
 	    for (int x = 0; x < linesP.rows(); x++) {
-		double[] l = linesP.get(x, 0);
-		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);
+			double[] l = linesP.get(x, 0);
+			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);
 	    }
 	    
@@ -92,14 +100,5 @@
 	    BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB);
 	    //Calculate if its sheet music or not
-	    isSheetMusic = classifier_HoughLineP(toBeClassifiedImg);  
-	            
-        //Save Processed Image
-	    String processedFile = filename;
-	    if (isSheetMusic == true) {
-		processedFile = "proc_T_"+filename;
-	    }else {
-		processedFile = "proc_F_"+filename;
-	    }
-	    imwrite(processedFile, edgesDetectedRGB);	    		    
+	    isSheetMusic = classifier_HoughLinesP(toBeClassifiedImg);      		    
 	}
 	catch(Exception e){
@@ -107,17 +106,58 @@
         }
         return isSheetMusic;
-    /*    
-    if (isSheetMusic == true){    
-    	return (1 + "\t" + "Filename: " + filename + "  Status: " + isSheetMusic  +"\t" );
-    }	
-    else{
-    	return (0 + "\t" + "Filename: " + filename + "  Status: " + isSheetMusic  +"\t" );
-    } */
  }
  
+     private static Boolean setup_HoughLinesP_refined(String filename){
+	System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
+	Boolean isSheetMusic = null;
+	try{
+	    //Variables
+	    Mat edgesDetected = new Mat();
+	    Mat edgesDetectedRGB = new Mat();
+	    Mat edgesDetectedRGBProb;
+	    // Load an image
+	    Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
+	    // Edge detection
+	    Imgproc.Canny(original, edgesDetected, 50, 200, 3, false);
+	    //Copy edges to the images that will display the results in BGR
+	    Imgproc.cvtColor(edgesDetected, edgesDetectedRGB, Imgproc.COLOR_GRAY2BGR);
+	    // Probabilistic Line Transform
+	    Mat linesP = new Mat(); // will hold the results of the detection
+	    double minLineLength = edgesDetectedRGB.size().width/4;
+	    Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 180, 50, minLineLength, 10);// runs the actual detection
+	    // Draw the lines
+	    
+	    for (int x = 0; x < linesP.rows(); x++) {
+			double[] l = linesP.get(x, 0);
+			//New angles
+            Point p1 = new Point(l[0], l[1]);
+            Point p2 = new Point(l[2], l[3]);
+            double m = Math.abs(p2.y - p1.y)/(p2.x - p1.x);
+            //System.out.println(l[0]);
+            //System.out.println(l[1]);
+            //System.out.println(l[2]);
+            //System.out.println(l[3]);
+            if(m<0.1) {
+            	//System.out.println("m: " + m);
+            	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);
+            }
+	    }
+	    
+	    //Convert MAT into a BufferedImage
+	    BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB);
+	    //Calculate if its sheet music or not
+	    isSheetMusic = classifier_HoughLinesP(toBeClassifiedImg);  
+   		    
+	}
+	catch(Exception e){
+            System.err.println(e);
+        }
+        return isSheetMusic;
+ }
+ 
  //******************
  //INTERNAL FUNCTIONS
  //******************
-    private static boolean classifier_HoughLineP(BufferedImage img){
+    private static boolean classifier_HoughLinesP(BufferedImage img){
     System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
     try {
@@ -143,5 +183,5 @@
        	percentage = ((float)redCount/(float)pixelCount)*(float)100;
         //If more than %10 and less than %50 then its sheet music!
-        if(percentage > 10 && percentage < 50){
+        if(percentage > CLASSIFIER_HOUGHLINESP_MIN && percentage < CLASSIFIER_HOUGHLINESP_MAX){
         	return true;}
         }
Index: /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/results.txt
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/results.txt	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/results.txt	(revision 33170)
@@ -1,1 +1,20 @@
-Classifier:Probabilistic HoughLines	30.08%
+Date: Thu Jun 20 18:40:41 NZST 2019
+Classifier: houghlinesP
+truePositive: 3098
+falseNegative: 63
+falsePositve: 624
+trueNegative: 1216
+SheetMusicAccuracyRate: 98.00696%
+NotSheetMusicAccuracyRate: 66.08695%
+OverallAccuracyRate: 86.26274%
+
+Date: Thu Jun 20 18:40:42 NZST 2019
+Classifier: houghlinesP-refined
+truePositive: 1666
+falseNegative: 1495
+falsePositve: 123
+trueNegative: 1717
+SheetMusicAccuracyRate: 52.70484%
+NotSheetMusicAccuracyRate: 93.315216%
+OverallAccuracyRate: 67.64648%
+
Index: /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/runClassifer.sh
===================================================================
--- /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/runClassifer.sh	(revision 33169)
+++ /other-projects/is-sheet-music-encore/trunk/image-identification-terminal/runClassifer.sh	(revision 33170)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-if [ $# != 2 ] ; then 
-  echo "Usage: ./testClassifier.sh file_name classifier_type" 1>&2
+if [ $# != 4 ] ; then 
+  echo "Usage: ./testClassifier.sh file_name classifier_type output_filename num_doc(-a = all -test = 100)" 1>&2
   exit 1
 fi
@@ -8,8 +8,33 @@
 folder_name=$1
 classifier_type=$2
-#Runs javaImageClassifier on ALL images
-for file_name in $folder_name/*/*.png; do
-	echo $file_name
-	echo ""
-	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
-done
+output_filename=$3
+num_doc=$4
+i=0
+case "$4" in
+	-all)
+		#Runs javaImageClassifier on ALL images
+		for file_name in $folder_name/*/*.png; do
+			echo $file_name
+			echo $output_filename
+			echo $i
+			echo ""
+			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
+			i=$[$i+1]
+		done
+		;;
+	-test)
+		#Runs javaImageClassifier on 100 images
+		for file_name in $folder_name/*/*.png; do
+		if [ $i -lt 200 ] ; then
+			echo $file_name
+			echo $output_filename
+			echo $i
+			echo ""
+			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
+			i=$[$i+1]
+		else
+			exit 0
+		fi		
+		done
+		;;
+esac		
