Ignore:
Timestamp:
2019-09-02T17:08:03+12:00 (5 years ago)
Author:
cpb16
Message:

termnal version executes correctly. (Didnt include init threshold in fucntion ~_~). Need to create new code version. With simplier series of processing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaClassifierComparison.java

    r33447 r33449  
    182182                //Execute classifierType defined from arguement
    183183
     184                File imgCheck = new File(imageFilename);
     185                if(!imgCheck.exists()){System.err.println("Image not found: "+ imageFilename);}
     186
    184187                //Split output by tab for processing in next java program
    185188                //imageFilename = 1, result = 3, classifierType = 4
     
    201204                        break;
    202205                    case "morphology":
    203                         algorithmResult = Algorithm_MorphologyOLD(imageFilename);
     206                        algorithmResult = Algorithm_Morphology(imageFilename);
    204207                        bw.write("Filename:" + '\t' + imageFilename + '\t' + "Classified as:" + '\t' + algorithmResult.getBoolean() + '\t' + "Number of areas:" + '\t' + algorithmResult.getInteger() + '\t' + classifierType + '\n');
    205208                        break;
     
    330333        Boolean isSheetMusic = null;
    331334        Pair returnVariables = new Pair();
     335        int areaCounter = 0;
    332336        try{
    333             //Variables
    334             int areaCounter = 0;
    335337            Mat edgesDetectedRGB = new Mat();
    336338            Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
     339
     340            System.out.println("Width: " + original.width() + " Height: " + original.height());
    337341
    338342            ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();
     
    361365            for (int i = 0; i < contours.size(); i++) {
    362366                double area = Imgproc.contourArea(contours.get(i));
     367                System.out.println("AREA: " + area);
    363368                //Check if area detected meets threshold
    364369                if(area > THRESHOLD_AREA_SIZE) {
    365370                    areaCounter++;
    366                     //System.out.println("AREA: " + area);
    367                 }
    368             }
    369 
    370 
    371 
    372 
    373 
     371
     372                }
     373            }
     374            System.out.println("areacount = " + areaCounter);
    374375
    375376            //Calculates if sheet music or not
    376377            if(areaCounter >= THRESHOLD_AREA_COUNT){
    377                 returnVariables.setBoolean(true);
     378                isSheetMusic = true;
     379                returnVariables.setBoolean(isSheetMusic);
    378380                returnVariables.setInteger(areaCounter);
    379381            }
     
    389391        Boolean isSheetMusic = null;
    390392        Pair returnVariables = new Pair();
     393        int FILLED = -1;
    391394        try{
    392             int FILLED = -1;
    393             //Display Original
    394             //imageViewer("original", original1);
    395             Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
     395            Mat original1 = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
     396            System.out.println("Width: " + original1.width() + " Height: " + original1.height());
     397            Mat original = original1.clone();
     398            Imgproc.adaptiveThreshold(original1, original,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C);
    396399            Mat test = original.clone();
    397             //imageViewer("00 Inverse Binarized Original", test);
    398 
    399 
    400400            //************************************
    401401            //Large Object Removal
     
    408408            Mat denoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));
    409409            Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, denoize);
    410             //imageViewer("01 Denoize - mask", maskLOR);
    411410
    412411            //close up gaps
    413412            Mat gapCloser = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));
    414413            Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_CLOSE, gapCloser);
    415             //imageViewer("02 gap closer - mask", maskLOR);
    416414
    417415            //Isolate large items
    418416            Mat isolateLarge = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8, 8));
    419417            Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_OPEN, isolateLarge);
    420             //imageViewer("03 Isolate Large - mask", maskLOR);
    421418
    422419            //Remove large items from image
    423420            Core.bitwise_not(maskLOR,maskLOR);
    424421            srcLOR.copyTo(dstLOR, maskLOR);
    425             //imageViewer("04 Large Items Removed", dstLOR);
    426422
    427423            //****************************************
     
    435431            Mat startSOR =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7));
    436432            Imgproc.morphologyEx(srcSOR,maskSOR, Imgproc.MORPH_OPEN, startSOR);
    437             //imageViewer("11 show small - mask", maskSOR);
    438433
    439434            Mat highlightSmall = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7));
    440435            Imgproc.dilate(maskSOR, maskSOR, highlightSmall);
    441             //imageViewer("12 highlight small - mask", maskSOR);
     436
    442437
    443438/*              Mat isolateSmall =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10));
     
    449444            Core.bitwise_not(maskSOR, maskSOR);
    450445            srcSOR.copyTo(dstSOR, maskSOR);
    451             //imageViewer("14 Small Items Removed", dstSOR);
    452446
    453447
     
    458452            Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15,2)); //10,2
    459453            Imgproc.erode(dstSOR,test,kernelErode);
    460             //imageViewer("21 Erode plus pre", test);
     454
    461455
    462456            Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //20,3
    463457            Imgproc.dilate(test,test,kernelDilate);
    464             //imageViewer("22 Dilate", test);
     458
    465459
    466460            Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4
    467461            Imgproc.morphologyEx(test, test, Imgproc.MORPH_CLOSE, kernelClose);
    468             //imageViewer("23 Close", test);
     462
    469463
    470464
    471465            Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //10,1
    472466            Imgproc.erode(test,test,kernelErode02);
    473             //imageViewer("24 Erode (Final)", test);
     467
    474468
    475469            //********************************************************************************
     
    511505                }
    512506            }
    513             //imageViewer("80 All Contours found", allContoursFound);
    514             //imageViewer("81 Large Contours Found", largeContoursFound);
    515507
    516508            //*****************************************************************
     
    536528                Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1);
    537529            }
    538             //imageViewer("82 Circles found", circleOutput);
     530
    539531
    540532            //********************************************************************************
     
    551543                Imgproc.circle(centreOutput, new Point(x, y), 4, new Scalar(255, 255, 255), 30);
    552544            }
    553             //imageViewer("83 Centres found", centreOutput);
    554 
    555545
    556546            //***********************************************
     
    563553            Mat postDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(150,15));
    564554            Imgproc.dilate(centreOutput,centreOutput,postDilate);
    565             //imageViewer("91 PostDilated", centreOutput);
    566555
    567556            Mat postClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4
    568557            Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_CLOSE, postClose);
    569             //imageViewer("92 PostClose", centreOutput);
    570558
    571559            Mat postDenoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,100));
    572560            Imgproc.morphologyEx(centreOutput,centreOutput, Imgproc.MORPH_OPEN, postDenoize);
    573             //imageViewer("93 PostDenoize", centreOutput);
    574 
    575             //Mat postOutline = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(50,50));
    576             //Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_GRADIENT, postOutline);
    577561
    578562            //Find area
     
    584568                double area = Imgproc.contourArea(postContours.get(i));
    585569                if(area > THRESHOLD_AREA_SIZE) {
    586                     System.out.println("POST AREA: " + area + "AREA COUNTER: " + areaCounter);
    587                     //Imgproc.drawContours(postContoursFound, postContours, i, new Scalar(0, 255, 0), FILLED);
     570                    //System.err.println("POST AREA: " + area);
     571                    Imgproc.drawContours(postContoursFound, postContours, i, new Scalar(0, 255, 0), FILLED);
    588572                    areaCounter++;
    589573                }
    590574            }
    591 
    592             //imageViewer("93 PostEND", postContoursFound);
    593 
    594             //Calculates if sheet music or not
     575            //Classifier Calculation
    595576            if(areaCounter >= THRESHOLD_AREA_COUNT){
    596                 returnVariables = new Pair(true, areaCounter);
    597                 //returnVariables.setBoolean(true);
    598                 //returnVariables.setInteger(areaCounter);
    599                 System.out.println("TEST RETURN VARIABLES: "+ returnVariables.toString());
    600             }
    601 
     577                returnVariables.setBoolean(true);
     578                returnVariables.setInteger(areaCounter);
     579            }
    602580        }
    603581        catch(Exception e){
Note: See TracChangeset for help on using the changeset viewer.