Index: other-projects/is-sheet-music-encore/trunk/image-identification/.idea/workspace.xml
===================================================================
--- other-projects/is-sheet-music-encore/trunk/image-identification/.idea/workspace.xml	(revision 33069)
+++ other-projects/is-sheet-music-encore/trunk/image-identification/.idea/workspace.xml	(revision 33070)
@@ -2,5 +2,7 @@
 <project version="4">
   <component name="ChangeListManager">
-    <list default="true" readonly="true" id="9bad4f92-4a7d-46a2-b6f0-94214c9f55cc" name="Default" comment="" />
+    <list default="true" readonly="true" id="9bad4f92-4a7d-46a2-b6f0-94214c9f55cc" name="Default" comment="">
+      <change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
+    </list>
     <ignored path="$PROJECT_DIR$/out/" />
     <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@@ -16,6 +18,6 @@
         <entry file="file://$PROJECT_DIR$/src/Main.java">
           <provider selected="true" editor-type-id="text-editor">
-            <state relative-caret-position="566">
-              <caret line="94" column="73" selection-start-line="94" selection-start-column="73" selection-end-line="94" selection-end-column="73" />
+            <state relative-caret-position="107">
+              <caret line="19" lean-forward="true" selection-start-line="19" selection-end-line="19" />
               <folding>
                 <element signature="imports" expanded="true" />
@@ -84,4 +86,26 @@
     <configuration>$USER_HOME$/.subversion</configuration>
     <supportedVersion>125</supportedVersion>
+  </component>
+  <component name="SvnFileUrlMappingImpl">
+    <option name="myMappingRoots">
+      <list>
+        <SvnCopyRootSimple>
+          <option name="myVcsRoot" value="$PROJECT_DIR$" />
+          <option name="myCopyRoot" value="$PROJECT_DIR$" />
+        </SvnCopyRootSimple>
+        <SvnCopyRootSimple>
+          <option name="myVcsRoot" value="$PROJECT_DIR$/.idea" />
+          <option name="myCopyRoot" value="$PROJECT_DIR$/.idea" />
+        </SvnCopyRootSimple>
+      </list>
+    </option>
+    <option name="myMoreRealMappingRoots">
+      <list>
+        <SvnCopyRootSimple>
+          <option name="myVcsRoot" value="$PROJECT_DIR$" />
+          <option name="myCopyRoot" value="$PROJECT_DIR$" />
+        </SvnCopyRootSimple>
+      </list>
+    </option>
   </component>
   <component name="TaskManager">
@@ -116,5 +140,5 @@
       <window_info id="UI Designer" order="1" />
       <window_info anchor="right" id="Theme Preview" order="2" />
-      <window_info anchor="bottom" id="Debug" order="7" weight="0.4" />
+      <window_info anchor="bottom" id="Debug" order="7" weight="0.3997955" />
       <window_info id="Favorites" order="3" side_tool="true" />
       <window_info anchor="right" content_ui="combo" id="Hierarchy" order="7" weight="0.25" />
@@ -132,5 +156,4 @@
       <window_info anchor="bottom" id="Run" order="6" visible="true" weight="0.34662578" />
       <window_info anchor="right" id="Theme Preview" order="2" />
-      <window_info anchor="bottom" id="Cvs" order="8" weight="0.25" />
       <window_info content_ui="combo" id="Project" order="5" visible="true" weight="0.18382749" />
       <window_info id="Structure" order="6" side_tool="true" weight="0.25" />
@@ -138,4 +161,5 @@
       <window_info anchor="right" id="Ant Build" order="6" weight="0.25" />
       <window_info anchor="bottom" id="TODO" order="10" />
+      <window_info anchor="bottom" id="Version Control" order="2" />
       <window_info id="Image Layers" order="4" />
       <window_info id="Designer" order="0" />
@@ -147,5 +171,5 @@
       <window_info anchor="bottom" id="Event Log" order="1" side_tool="true" />
       <window_info anchor="bottom" id="Inspection" order="9" weight="0.4" />
-      <window_info anchor="bottom" id="Version Control" order="2" />
+      <window_info anchor="bottom" id="Cvs" order="8" weight="0.25" />
       <window_info id="Capture Tool" order="2" />
       <window_info anchor="bottom" id="Message" order="4" />
@@ -166,4 +190,14 @@
     <entry file="file://$PROJECT_DIR$/src/Main.java">
       <provider selected="true" editor-type-id="text-editor">
+        <state relative-caret-position="1410">
+          <caret line="94" column="73" selection-start-line="94" selection-start-column="73" selection-end-line="94" selection-end-column="73" />
+          <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="495">
           <caret line="33" column="19" selection-start-line="33" selection-start-column="19" selection-end-line="33" selection-end-column="31" />
@@ -203,6 +237,6 @@
     <entry file="file://$PROJECT_DIR$/src/Main.java">
       <provider selected="true" editor-type-id="text-editor">
-        <state relative-caret-position="566">
-          <caret line="94" column="73" selection-start-line="94" selection-start-column="73" selection-end-line="94" selection-end-column="73" />
+        <state relative-caret-position="107">
+          <caret line="19" lean-forward="true" selection-start-line="19" selection-end-line="19" />
           <folding>
             <element signature="imports" expanded="true" />
Index: other-projects/is-sheet-music-encore/trunk/image-identification/src/Main.java
===================================================================
--- other-projects/is-sheet-music-encore/trunk/image-identification/src/Main.java	(revision 33069)
+++ other-projects/is-sheet-music-encore/trunk/image-identification/src/Main.java	(revision 33070)
@@ -5,36 +5,81 @@
 import org.opencv.imgproc.Imgproc;
 import static org.opencv.imgcodecs.Imgcodecs.imwrite;
-
+import java.awt.image.BufferedImage;
+import java.awt.image.DataBufferByte;
+import java.io.File;
+import javax.imageio.ImageIO;
 
 //REFERENCES:
-//https://docs.opencv.org/3.4.3/d9/db0/tutorial_hough_lines.html
+//https://docs.opencv.org/3.4.3/d9/db0/tutorial_hough_lines.
+//https://stackoverflow.com/questions/43443309/count-red-pixel-in-a-given-image
+//https://www.wikihow.com/Calculate-Percentage-in-Java
+//https://riptutorial.com/opencv/example/21963/converting-an-mat-object-to-an-bufferedimage-object
 
 
 public class Main {
 
-    private Scalar meanOfProcessed;
+    private static  BufferedImage toBufferedImage(Mat mat){
+        //MOSTLY COPY PASTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        //MOSTLY COPY PASTE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+        //https://riptutorial.com/opencv/example/21963/converting-an-mat-object-to-an-bufferedimage-object
+        try{
+            int type = BufferedImage.TYPE_3BYTE_BGR;
+            int bufferSize = mat.channels() * mat.cols() * mat.rows();
+            byte[] b = new byte[bufferSize];
+            //get all the pixels
+            mat.get(0, 0, b);
+            BufferedImage image = new BufferedImage(mat.cols(), mat.rows(), type);
+            final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
+            System.arraycopy(b, 0, targetPixels, 0, b.length);
+            return image;
+        }
+        catch(Exception e){
+            System.err.println(e);
+        }
+        return null;
+    }
+
+    private static boolean Classifier(BufferedImage img){
+        try {
+            //Read file
+            //BufferedImage img = ImageIO.read(new File(processedFile));
+            int x = img.getWidth();
+            int y = img.getHeight();
+            int pixelCount  = 0;
+            int redCount    = 0;
+            float percentage = 0;
+
+            //Go Thru every pixel
+            for(int i=0; i < y; i++){
+                for(int j=0;j < x; j++){
+                    //Get value for current pixels RGB value
+                    int currPixelRGB = img.getRGB(j, i);
+                    //Check if pixel is red (hex value of red)
+                    if(currPixelRGB == 0xFFFF0000){
+                        redCount++;
+                    }
+                    pixelCount++;
+                }
+            }
+            //Calculate percentage of Red in image
+            percentage = ((float)redCount/(float)pixelCount)*(float)100;
+            //If more than %10 and less than %50 then its sheet music!
+            if(percentage > 10 && percentage < 50){
+                return true;}
+        }
+        catch (Exception e) {
+            System.err.println(e);
+        }
+        return false;
+    }
 
     public static void main(String[] args) {
         System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
-/*
-	    // write your code here
-        System.out.println("Welcome to OpenCV " + Core.VERSION);
-        Mat m = new Mat(5, 10, CvType.CV_8UC1, new Scalar(0));
-        System.out.println("OpenCV Mat: " + m);
-        Mat mr1 = m.row(1);
-        mr1.setTo(new Scalar(1));
-        Mat mc5 = m.col(0);
-        mc5.setTo(new Scalar(8));
-        System.out.println("OpenCV Mat data:\n" + m.dump());
- */
-    try {
+        try {
             //Variables
             Mat edgesDetected = new Mat();
             Mat edgesDetectedRGB = new Mat();
             Mat edgesDetectedRGBProb;
-            Mat justEdges;
-
-
-
+            Mat justEdges; //TESTING
             String default_file = "Test.png";
             String filename = ((args.length > 0) ? args[0] : default_file);
@@ -48,7 +93,5 @@
             edgesDetectedRGBProb = edgesDetectedRGB.clone();
 
-            justEdges = edgesDetectedRGBProb.clone();
-
-
+            justEdges = edgesDetectedRGBProb.clone();//TESTING
 
             // Standard Hough Line Transform
@@ -66,6 +109,4 @@
             }
 
-
-
             // Probabilistic Line Transform
             Mat linesP = new Mat(); // will hold the results of the detection
@@ -77,29 +118,27 @@
             }
 
-            //save output
-            imwrite(filename+"_HoughLineP", edgesDetectedRGBProb);
-            String processedFile = filename+"_HoughLineP";
-            //Load an image
-            Mat processed = Imgcodecs.imread(processedFile, Imgcodecs.IMREAD_COLOR);
-            System.out.println(Core.mean(processed));
-            String meanOfProcessed = (Core.mean(processed).toString());
-            //OUTPUTS [ BLUE , GREEN , RED, ALPHA?
-            //Core.mean GETS scalar of image (array of BGR) and calculates the average for each
-            //https://docs.opencv.org/java/2.4.2/org/opencv/core/Core.html#mean(org.opencv.core.Mat)
+            //Convert MAT into a BufferedImage
+            BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGBProb);
 
-            //With this logic, then if can say if the RED in the array is between 'x' and 'y' then its sheet music
-            System.out.println(meanOfProcessed); //PRINTS AS EXPECTED
+            //Calculate if its sheet music or not
+            Boolean isSheetMusic = Classifier(toBeClassifiedImg);
+            System.out.println("Filename: " + filename + "  Status: " + isSheetMusic);
 
-            //CONVERT STRING TO ARRAY OR FIND ANOTHER WAY OF GETTING TO RED VALUE
-            //SAVE AS VARIABLE : RedValue.
-            //IF redValue > 'x' and redValue < 'y' THEN it is sheet music
+            //Save Processed Image
+            String processedFile = null;
+            if (isSheetMusic == true) {
+                //NEED FIGURE OUT HOW RUN IN SCRIPT. THEN USE ARGS as filename + "HoughLineP + "png"
+                processedFile = "SheetMusic/Test_HoughLineP.png";
+            }else {
+                processedFile = "Test_HoughLineP.png";
+            }
+            imwrite(processedFile, edgesDetectedRGBProb);
 
+            //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);
 
-
-            // Show results
-            //HighGui.imshow("Source", original);
-            //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);
             // Wait and Exit
             HighGui.waitKey();
@@ -107,5 +146,5 @@
         }
         catch(Exception e){
-         System.err.println(e);
+            System.err.println(e);
         }
     }
