Changeset 33170


Ignore:
Timestamp:
2019-06-20T20:42:56+12:00 (5 years ago)
Author:
cpb16
Message:

refined houghlineP alogirthm

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  
    1414    cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MU-hathiFullIDList.txt MU
    1515    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.xml
    17     #cd java-gen-corpus; rm metadata_temp.xml
    1816    ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MU-hathiValidIDList.txt
    1917
     
    2422    cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-BK-hathiFullIDList.txt BK
    2523    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.xml
    27     #cd java-gen-corpus; rm metadata_temp.xml
    2824    ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-BK-hathiValidIDList.txt
    2925
     
    3430    cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-SE-hathiFullIDList.txt SE
    3531    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.xml
    37     #cd java-gen-corpus; rm metadata_temp.xml
    3832    ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-SE-hathiValidIDList.txt
    3933
     
    4438    cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MP-hathiFullIDList.txt MP
    4539    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.xml
    47     #cd java-gen-corpus; rm metadata_temp.xml
    4840    ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MP-hathiValidIDList.txt
    4941
     
    5446    cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-500-MX-hathiFullIDList.txt MX
    5547    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
    5849    ./COMPX520-DOWNLOADER-PNG-10PAGES.sh java-gen-corpus/gen-500-MX-hathiValidIDList.txt
    5950
     51#***********
     52#CLASSIFIERS
     53#***********
    6054
     55#HoughLinesP
     56run-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
    6172
     73run-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
     91run-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
     108run-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
     125run-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  
    1010SE/uiuo.ark+=13960=t4nk57820-7.png  invalid or incomplete server response
    1111SE/uiuo.ark+=13960=t63556b5c-5.png  invalid or incomplete server response
     12MU/mdp.39015096590958-10.png    no server avaiable to complete request
     13MU/mdp.39015096654648-5.png     no server avaiable to complete request
     14MU/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  
    44    <list default="true" readonly="true" id="9bad4f92-4a7d-46a2-b6f0-94214c9f55cc" name="Default" comment="">
    55      <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" />
    76      <change beforePath="$PROJECT_DIR$/out/production/image-identification/Main.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/image-identification/Main.class" afterDir="false" />
    87      <change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
     
    2120        <entry file="file://$PROJECT_DIR$/src/Main.java">
    2221          <provider selected="true" editor-type-id="text-editor">
    23             <state relative-caret-position="694">
    24               <caret line="174" 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" />
    2524              <folding>
    2625                <element signature="imports" expanded="true" />
     
    3938    </option>
    4039  </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" />
    4645  </component>
    4746  <component name="ProjectView">
     
    128127  </component>
    129128  <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" />
    131131    <layout>
    132132      <window_info anchor="right" id="Palette" order="4" />
     
    138138      <window_info anchor="bottom" id="Event Log" order="1" side_tool="true" />
    139139      <window_info anchor="right" id="Maven Projects" order="3" />
    140       <window_info anchor="bottom" id="Run" order="6" weight="0.26789367" />
     140      <window_info active="true" anchor="bottom" id="Run" order="6" visible="true" weight="0.22526316" />
    141141      <window_info anchor="bottom" id="Version Control" order="2" />
    142142      <window_info anchor="bottom" id="Terminal" order="0" weight="0.42638037" />
     
    198198    <entry file="file://$PROJECT_DIR$/src/Main.java">
    199199      <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">
    200230        <state relative-caret-position="1620">
    201231          <caret line="108" column="29" lean-forward="true" selection-start-line="108" selection-start-column="29" selection-end-line="108" selection-end-column="29" />
     
    345375    <entry file="file://$PROJECT_DIR$/src/Main.java">
    346376      <provider selected="true" editor-type-id="text-editor">
    347         <state relative-caret-position="694">
    348           <caret line="174" 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" />
    349379          <folding>
    350380            <element signature="imports" expanded="true" />
  • other-projects/is-sheet-music-encore/trunk/image-identification-development/src/Main.java

    r33110 r33170  
    100100            Mat edgesDetected = new Mat();
    101101            Mat edgesDetectedRGB = new Mat();
    102             Mat forOTSU = new Mat();
    103102            Mat edgesDetectedRGBProb;
     103            Mat edgeDoesntMakeSense;
    104104            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";
    106110            String filename = ((args.length > 0) ? args[0] : default_file);
    107111
     
    110114            // Edge detection
    111115            //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);
    113118            //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);
    115120            //03 BINARY
    116121            //Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY,15, 2);
     
    122127
    123128
    124             //Convert to RGB
     129            //Convert to RGB for future use
    125130            Imgproc.cvtColor(edgesDetected, edgesDetectedRGB, Imgproc.COLOR_GRAY2BGR);
    126131            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
    130136            //(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
    156181            }
    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));
    181192
    182193            //Display Results
    183194            //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);
    187199
    188200            // Wait and Exit
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/Makefile

    r33141 r33170  
    22#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
    33
    4 run-classifier-houghlinesP:
     4testrun-classifier-houghlinesP:
    55        #Compile
    66    javac javaAccuracyCalculator.java
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaAccuracyCalculator.java

    r33141 r33170  
    44import java.io.FileReader;
    55import java.io.FileWriter;
     6import java.util.*;
    67public class javaAccuracyCalculator{
    78                   
     
    1516            }
    1617            else {
     18                Date d = new Date();
    1719                String inputFilename = args[0];
    1820                String classifierType = args[1];
     
    2325                String line = null;
    2426                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                //
    2931                int sheetMusicCount = 0;
    3032                int notSheetMusicCount  = 0;
     33                //
     34                int truePositive    = 0;
     35                int trueNegative    = 0;
     36                //
     37                int falsePositive   = 0;
     38                int falseNegative   = 0;               
     39
    3140                //Splits into each record, since readLine splits by "\n"
    3241                while ((line = buf.readLine()) != null) {
    3342                    item = line.split("\t");       
    3443                    //Calculate AccuracyRates
    35                     if(item[1].contains("TestImages/SheetMusic/")){
     44                    if(item[1].contains("/SheetMusic/")){
    3645                        sheetMusicCount++;
    3746                        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");
    3954                        }
    4055                    }
    41                     if(item[1].contains("TestImages/NotSheetMusic/")){
     56                    if(item[1].contains("/NotSheetMusic/")){
    4257                        notSheetMusicCount++;
    4358                        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");
    4566                        }
    4667                    }                       
    4768                }
    4869               
    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;
    5370               
    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');     
    5588                buf.close();
    5689                fw.close();                             
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaImageClassifier.java

    r33141 r33170  
    3333    public static void main(String[] args) {   
    3434        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>");
    3737            }
    3838            else {
    3939                Boolean result = null;
    4040                String imageFilename = args[0];
    41                 String classifierType = args[1];           
     41                String classifierType = args[1];
     42                String outputFilename = args[2];           
    4243                //Execute classifierType defined from arguement
    4344                switch(classifierType){
    4445                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);
    4650                    break;
    4751                default:
    48                     System.out.println("unknown");
     52                    System.out.println("unknown algorithm");
    4953                    break;
    5054                }           
    5155                //Write output to disc
    52                 File log = new File("log.txt");
     56                File log = new File(outputFilename);
    5357                FileWriter fileWriter = new FileWriter(log, true);
    5458                BufferedWriter bw = new BufferedWriter(fileWriter);
     
    6670    //True = 1 + Filename + Status
    6771    //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){
    6977    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    7078    Boolean isSheetMusic = null;
     
    8593        // Draw the lines
    8694        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);
    8997        }
    9098       
     
    92100        BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB);
    93101        //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);               
    104103    }
    105104    catch(Exception e){
     
    107106        }
    108107        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     } */
    116108 }
    117109 
     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 
    118158 //******************
    119159 //INTERNAL FUNCTIONS
    120160 //******************
    121     private static boolean classifier_HoughLineP(BufferedImage img){
     161    private static boolean classifier_HoughLinesP(BufferedImage img){
    122162    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    123163    try {
     
    143183        percentage = ((float)redCount/(float)pixelCount)*(float)100;
    144184        //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){
    146186            return true;}
    147187        }
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/results.txt

    r33110 r33170  
    1 Classifier:Probabilistic HoughLines 30.08%
     1Date: Thu Jun 20 18:40:41 NZST 2019
     2Classifier: houghlinesP
     3truePositive: 3098
     4falseNegative: 63
     5falsePositve: 624
     6trueNegative: 1216
     7SheetMusicAccuracyRate: 98.00696%
     8NotSheetMusicAccuracyRate: 66.08695%
     9OverallAccuracyRate: 86.26274%
     10
     11Date: Thu Jun 20 18:40:42 NZST 2019
     12Classifier: houghlinesP-refined
     13truePositive: 1666
     14falseNegative: 1495
     15falsePositve: 123
     16trueNegative: 1717
     17SheetMusicAccuracyRate: 52.70484%
     18NotSheetMusicAccuracyRate: 93.315216%
     19OverallAccuracyRate: 67.64648%
     20
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/runClassifer.sh

    r33141 r33170  
    11#!/bin/bash
    22
    3 if [ $# != 2 ] ; then
    4   echo "Usage: ./testClassifier.sh file_name classifier_type" 1>&2
     3if [ $# != 4 ] ; then
     4  echo "Usage: ./testClassifier.sh file_name classifier_type output_filename num_doc(-a = all -test = 100)" 1>&2
    55  exit 1
    66fi
     
    88folder_name=$1
    99classifier_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
     10output_filename=$3
     11num_doc=$4
     12i=0
     13case "$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        ;;
     40esac       
Note: See TracChangeset for help on using the changeset viewer.