Ignore:
Timestamp:
2019-05-26T17:15:31+12:00 (5 years ago)
Author:
cpb16
Message:

Ground truth complete for SE and BK. Added file to keep track of all error images downdloaded. added file for notes for next meeting

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/is-sheet-music-encore/trunk/image-identification-development/src/Main.java

    r33097 r33110  
    100100            Mat edgesDetected = new Mat();
    101101            Mat edgesDetectedRGB = new Mat();
     102            Mat forOTSU = new Mat();
    102103            Mat edgesDetectedRGBProb;
    103104            Mat justEdges; //TESTING
    104             String default_file = "Test02.png";
     105            String default_file = "TestImages/houghlineTest.png";
    105106            String filename = ((args.length > 0) ? args[0] : default_file);
    106107
     
    108109            Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
    109110            // Edge detection
    110             Imgproc.Canny(original, edgesDetected, 50, 200, 3, false);
    111             //Copy edges to the images that will display the results in BGR
     111            //01 CANNY
     112            //Imgproc.Canny(original, edgesDetected, 50, 200, 3, false);
     113            //02 BINARYINV
     114            Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV,15, 2);
     115            //03 BINARY
     116            //Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY,15, 2);
     117            //04 NO PROC
     118            //edgesDetected = original.clone();
     119            //05 OTSU THRESHOLD
     120            //Imgproc.threshold(original, edgesDetected,0,255,Imgproc.THRESH_BINARY_INV+Imgproc.THRESH_OTSU);
     121
     122
     123
     124            //Convert to RGB
    112125            Imgproc.cvtColor(edgesDetected, edgesDetectedRGB, Imgproc.COLOR_GRAY2BGR);
    113             edgesDetectedRGBProb = edgesDetectedRGB.clone();
    114 
    115             justEdges = edgesDetectedRGBProb.clone();//TESTING
     126            justEdges = edgesDetectedRGB.clone();//TESTING
    116127
    117128            // Standard Hough Line Transform
    118129            Mat lines = new Mat(); // will hold the results of the detection
    119             //(edgeDetectedImage, outputOfDetection(r,Ξ), resolution of r, resolution of Ξ, threshold (minimum num of intersections)
    120             Imgproc.HoughLines(edgesDetected, lines, 1.4, Math.PI / 180, 500); // runs the actual detection
     130            //(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
    121133
    122             // Draw the lines
    123             //LOOK OVER THIS AGAIN THE 1000 might be image height?
    124             //THRESHOLD should be changed, based on img dimensions?
     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
    125138
    126             for (int x = 0; x < lines.rows(); x++) {
    127                 double rho = lines.get(x, 0)[0],
    128                         theta = lines.get(x, 0)[1];
    129                 //CONVERT to Cartisean coord
    130                 double a = Math.cos(theta), b = Math.sin(theta);
    131                 double x0 = a * rho, y0 = b * rho;
    132139
    133                 Point pt1 = new Point(Math.round(x0 + 1000 * (-b)), Math.round(y0 + 1000 * (a)));
    134                 Point pt2 = new Point(Math.round(x0 - 1000 * (-b)), Math.round(y0 - 1000 * (a)));
    135                 Imgproc.line(edgesDetectedRGB, pt1, pt2, new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
     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);
    136156            }
    137157
    138             // Probabilistic Line Transform
    139             Mat linesP = new Mat(); // will hold the results of the detection
    140             Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 180, 50, 50, 10); // runs the actual detection
    141             // Draw the lines
    142             for (int x = 0; x < linesP.rows(); x++) {
    143                 double[] l = linesP.get(x, 0);
    144                 Imgproc.line(edgesDetectedRGBProb, new Point(l[0], l[1]), new Point(l[2], l[3]), new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
     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);
    145178            }
     179            */
    146180
    147             //Convert MAT into a BufferedImage
    148             BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGBProb);
    149 
    150             //Calculate if its sheet music or not
    151             Boolean isSheetMusic = Classifier(toBeClassifiedImg);
    152             System.out.println("Filename: " + filename + "  Status: " + isSheetMusic);
    153 
    154             //Save Processed Image
    155             String processedFile = null;
    156             if (isSheetMusic == true) {
    157                 //NEED FIGURE OUT HOW RUN IN SCRIPT. THEN USE ARGS as filename + "HoughLineP + "png"
    158                 processedFile = "SheetMusic/Test_HoughLineP.png";
    159             }else {
    160                 processedFile = "Test_HoughLineP.png";
    161             }
    162             imwrite(processedFile, edgesDetectedRGBProb);
    163181
    164182            //Display Results
Note: See TracChangeset for help on using the changeset viewer.