Changeset 33449
- Timestamp:
- 2019-09-02T17:08:03+12:00 (5 years ago)
- Location:
- other-projects/is-sheet-music-encore/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/is-sheet-music-encore/trunk/Makefile
r33447 r33449 28 28 29 29 run-morphology-20-test: 30 #cd image-identification-terminal/log-all-hires-new/test; rm log-morphology-MU-test.txt30 cd image-identification-terminal/log-all-hires-new/test; rm log-morphology-MU-test.txt 31 31 cd image-identification-terminal; javac javaAccuracyCalculator.java 32 32 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; -
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/.idea/workspace.xml
r33447 r33449 15 15 <entry file="file://$PROJECT_DIR$/image-identification-development/src/Main.java"> 16 16 <provider selected="true" editor-type-id="text-editor"> 17 <state relative-caret-position="- 969">18 <caret line=" 803" selection-start-line="803" selection-end-line="803" />17 <state relative-caret-position="-53"> 18 <caret line="746" column="42" selection-start-line="746" selection-start-column="42" selection-end-line="746" selection-end-column="42" /> 19 19 <folding> 20 20 <element signature="imports" expanded="true" /> … … 40 40 <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java"> 41 41 <provider selected="true" editor-type-id="text-editor"> 42 <state relative-caret-position="3 21">43 <caret line=" 855" column="42" selection-start-line="855" selection-start-column="42" selection-end-line="855" selection-end-column="42" />42 <state relative-caret-position="33"> 43 <caret line="143" column="32" selection-start-line="143" selection-start-column="32" selection-end-line="143" selection-end-column="32" /> 44 44 <folding> 45 45 <element signature="imports" expanded="true" /> 46 <element signature="e#10614#13084#1" /> 47 <element signature="e#13169#15172#1" /> 48 <element signature="e#15241#17864#1" /> 49 <element signature="e#17947#23618#1" /> 50 <element signature="e#23702#27679#1" /> 51 <element signature="e#27746#28924#1" /> 52 <element signature="e#28992#32955#1" /> 53 <element signature="e#35980#35992#0" expanded="true" /> 54 <element signature="e#37714#37726#0" expanded="true" /> 55 <element signature="e#37797#37809#0" expanded="true" /> 56 <element signature="e#41273#41282#0" expanded="true" /> 57 <element signature="e#44803#56145#1" /> 58 <element signature="e#48966#48978#0" expanded="true" /> 59 <element signature="e#49049#49061#0" expanded="true" /> 60 <element signature="e#49131#49143#0" expanded="true" /> 61 <element signature="e#52896#52905#0" expanded="true" /> 46 <element signature="class#Pair#0;class#MainMorph#0" /> 47 <element signature="method#imageViewer#0;class#MainMorph#0" /> 48 <element signature="e#11259#13729#1" /> 49 <element signature="e#13814#15817#1" /> 50 <element signature="e#15886#18509#1" /> 51 <element signature="e#18593#24264#1" /> 52 <element signature="e#24349#28326#1" /> 53 <element signature="e#28394#29572#1" /> 54 <element signature="e#29641#33604#1" /> 55 <element signature="e#33714#45393#1" /> 56 <element signature="e#42969#43036#0" /> 57 <element signature="e#45494#55203#1" /> 62 58 </folding> 63 59 </state> … … 68 64 <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java"> 69 65 <provider selected="true" editor-type-id="text-editor"> 70 <state relative-caret-position=" 406">71 <caret line=" 606" column="5" lean-forward="true" selection-start-line="606" selection-start-column="5" selection-end-line="606" selection-end-column="5" />66 <state relative-caret-position="338"> 67 <caret line="135" column="4" selection-start-line="135" selection-start-column="4" selection-end-line="160" selection-end-column="5" /> 72 68 <folding> 73 69 <element signature="imports" expanded="true" /> 74 70 <element signature="method#init#0;class#javaClassifierComparison#0" /> 75 <element signature="e#3021#4256#0" />76 71 <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" /> 77 72 <element signature="class#Pair#0;class#javaClassifierComparison#0" /> 78 73 <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" /> 79 74 <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" /> 75 <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" /> 80 76 <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" /> 81 <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" />82 <element signature="e#20655#20667#0" expanded="true" />83 <element signature="e#20738#20750#0" expanded="true" />84 <element signature="e#20820#20832#0" expanded="true" />85 <element signature="e#24593#24602#0" expanded="true" />86 77 <element signature="method#Classifier_LineCounter#0;class#javaClassifierComparison#0" /> 87 78 <element signature="method#Classifier_ClusterDetection#0;class#javaClassifierComparison#0" /> … … 108 99 <find>coo.31924062612282-9.png</find> 109 100 <find>FILLED</find> 101 <find>test</find> 110 102 </findStrings> 111 103 </component> … … 244 236 <entry file="file://$PROJECT_DIR$/image-identification-development/src/Main.java"> 245 237 <provider selected="true" editor-type-id="text-editor"> 246 <state relative-caret-position="- 969">247 <caret line=" 803" selection-start-line="803" selection-end-line="803" />238 <state relative-caret-position="-53"> 239 <caret line="746" column="42" selection-start-line="746" selection-start-column="42" selection-end-line="746" selection-end-column="42" /> 248 240 <folding> 249 241 <element signature="imports" expanded="true" /> … … 267 259 <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java"> 268 260 <provider selected="true" editor-type-id="text-editor"> 269 <state relative-caret-position=" 406">270 <caret line=" 606" column="5" lean-forward="true" selection-start-line="606" selection-start-column="5" selection-end-line="606" selection-end-column="5" />261 <state relative-caret-position="338"> 262 <caret line="135" column="4" selection-start-line="135" selection-start-column="4" selection-end-line="160" selection-end-column="5" /> 271 263 <folding> 272 264 <element signature="imports" expanded="true" /> 273 265 <element signature="method#init#0;class#javaClassifierComparison#0" /> 274 <element signature="e#3021#4256#0" />275 266 <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" /> 276 267 <element signature="class#Pair#0;class#javaClassifierComparison#0" /> 277 268 <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" /> 278 269 <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" /> 270 <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" /> 279 271 <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" /> 280 <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" />281 <element signature="e#20655#20667#0" expanded="true" />282 <element signature="e#20738#20750#0" expanded="true" />283 <element signature="e#20820#20832#0" expanded="true" />284 <element signature="e#24593#24602#0" expanded="true" />285 272 <element signature="method#Classifier_LineCounter#0;class#javaClassifierComparison#0" /> 286 273 <element signature="method#Classifier_ClusterDetection#0;class#javaClassifierComparison#0" /> … … 295 282 <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java"> 296 283 <provider selected="true" editor-type-id="text-editor"> 297 <state relative-caret-position="3 21">298 <caret line=" 855" column="42" selection-start-line="855" selection-start-column="42" selection-end-line="855" selection-end-column="42" />284 <state relative-caret-position="33"> 285 <caret line="143" column="32" selection-start-line="143" selection-start-column="32" selection-end-line="143" selection-end-column="32" /> 299 286 <folding> 300 287 <element signature="imports" expanded="true" /> 301 <element signature="e#10614#13084#1" /> 302 <element signature="e#13169#15172#1" /> 303 <element signature="e#15241#17864#1" /> 304 <element signature="e#17947#23618#1" /> 305 <element signature="e#23702#27679#1" /> 306 <element signature="e#27746#28924#1" /> 307 <element signature="e#28992#32955#1" /> 308 <element signature="e#35980#35992#0" expanded="true" /> 309 <element signature="e#37714#37726#0" expanded="true" /> 310 <element signature="e#37797#37809#0" expanded="true" /> 311 <element signature="e#41273#41282#0" expanded="true" /> 312 <element signature="e#44803#56145#1" /> 313 <element signature="e#48966#48978#0" expanded="true" /> 314 <element signature="e#49049#49061#0" expanded="true" /> 315 <element signature="e#49131#49143#0" expanded="true" /> 316 <element signature="e#52896#52905#0" expanded="true" /> 288 <element signature="class#Pair#0;class#MainMorph#0" /> 289 <element signature="method#imageViewer#0;class#MainMorph#0" /> 290 <element signature="e#11259#13729#1" /> 291 <element signature="e#13814#15817#1" /> 292 <element signature="e#15886#18509#1" /> 293 <element signature="e#18593#24264#1" /> 294 <element signature="e#24349#28326#1" /> 295 <element signature="e#28394#29572#1" /> 296 <element signature="e#29641#33604#1" /> 297 <element signature="e#33714#45393#1" /> 298 <element signature="e#42969#43036#0" /> 299 <element signature="e#45494#55203#1" /> 317 300 </folding> 318 301 </state> -
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/image-identification-development/src/Main.java
r33437 r33449 760 760 761 761 //String default_file = hiresDirectory+ "MU/SheetMusic/mdp.39015096402204-2.png"; 762 String default_file = hiresDirectory+ "MU/SheetMusic/mdp.39015096408490-3.png"; 762 //String default_file = hiresDirectory+ "MU/SheetMusic/mdp.39015096408490-3.png"; 763 //String default_file = hiresDirectory + "MU/SheetMusic/coo.31924062612282-9.png"; 764 763 765 //String default_file = directory+"NotSheetMusic/coo.31924062612282-9.png"; 764 766 //String default_file = directory+"NotSheetMusic/mdp.39015097852365-2.png"; 765 767 //String default_file ="TestImages/NotNot/mdp.39015080972303-3.png"; 766 768 //String default_file =hiresDirectory+"BK/NotSheetMusic/aeu.ark+=13960=t2q53nq6w-6.png"; 767 //String default_file = "/Scratch/cpb16/is-sheet-music-encore/image-identification-terminal/TestImages/test-coo.31924062612282-9.png"; 769 770 String default_file = "/Scratch/cpb16/is-sheet-music-encore/image-identification-terminal/TestImages/test-coo.31924062612282-9.png"; 771 //String default_file = "/Scratch/cpb16/is-sheet-music-encore/image-identification-terminal/TestImages/mdp.39015080937769-1.png"; 772 //String default_file = "/Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU/SheetMusic/coo.31924062612282-9.png"; 768 773 //String default_file =hiresDirectory+"BK/NotSheetMusic/aeu.ark+=13960=t9z03w65z-4.png"; 769 774 … … 776 781 String filename = ((args.length > 0) ? args[0] : default_file); 777 782 File file = new File(filename); 783 778 784 if(!file.exists()){System.err.println("Image not found: "+ filename);} 779 785 … … 782 788 // Load an image 783 789 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 790 System.out.println("Width: " + original.width() + " Height: " + original.height()); 784 791 // Edge detection 785 792 -
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/image-identification-development/src/MainMorph.java
r33447 r33449 114 114 115 115 public class MainMorph { 116 static public class Pair{ 117 //Privates 118 private Boolean _b; 119 private Integer _i; 120 121 //Constructor 122 public Pair(Boolean b, Integer i){ 123 _b = b; 124 _i = i; 125 } 126 public Pair(){ 127 _b = null; 128 _i = null; 129 } 130 131 //Getters 132 public Boolean getBoolean() {return _b;} 133 public Integer getInteger() {return _i;} 134 135 //Setters 136 public void setBoolean (Boolean b){_b = b;} 137 public void setInteger (Integer i){_i = i;} 138 139 //ToString 140 public String toString() {return "Boolean: " + _b + " Integer: " + _i;} 141 } 142 116 143 //CODE VERSIONS 117 static int CODE_VERSION = 8;144 static int CODE_VERSION = 9; 118 145 static int IMAGE_VERSION = 3; 119 146 //GLOBAL_CONSTANTS … … 158 185 } 159 186 } 160 161 162 187 163 188 //MAIN … … 192 217 //String default_file =hiresDirectory+"MU/NotSheetMusic/mdp.39015096363935-1.png"; 193 218 //String default_file =hiresDirectory+"MU/SheetMusic/coo.31924062612282-9.png"; 194 195 //System.out.println(default_file); 196 //String default_file = "/Scratch/cpb16/is-sheet-music-encore/image-identification-terminal/TestImages/test-coo.31924062612282-9.png"; 219 //String default_file = "/Scratch/cpb16/is-sheet-music-encore/image-identification-terminal/TestImages/hi-res-test-coo.31924062612282-9.png"; 220 //TestNew images used 221 222 //String default_file = hiresDirectory+"/MU/SheetMusic/aeu.ark+=13960=t93787r1w-10.png"; 223 //String default_file = "hiresDirectory+"/MU/SheetMusic/bc.ark+=13960=t2j72dt1p-10.png"; 224 //String default_file = hiresDirectory+"/MU/SheetMusic/bc.ark+=13960=t2j72dt1p-7.png"; //Handwritten 225 //String default_file = hiresDirectory+"/MU/SheetMusic/bc.ark+=13960=t2j72dt1p-8.png"; //Handwritten 226 //String default_file = hiresDirectory+"/MU/SheetMusic/bc.ark+=13960=t2j72dt1p-9.png"; //Handwritten 227 //String default_file = hiresDirectory+"/MU/SheetMusic/coo.31924062612282-9.png"; 228 //String default_file = hiresDirectory+"/MU/SheetMusic/dul1.ark+=13960=t2x41569k-10.png"; 229 //String default_file = hiresDirectory+"/MU/SheetMusic/dul1.ark+=13960=t2x41569k-7.png"; 230 //String default_file = hiresDirectory+"/MU/SheetMusic/dul1.ark+=13960=t2x41569k-8.png"; 231 //String default_file = hiresDirectory+"/MU/SheetMusic/dul1.ark+=13960=t2x41569k-9.png"; 232 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-10.png"; 233 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-1.png"; 234 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-2.png"; 235 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-3.png"; 236 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-4.png"; 237 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-5.png"; 238 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-6.png"; 239 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-7.png"; 240 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-8.png"; 241 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-9.png"; 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 197 257 //String default_file = testDirectory+"TestImages/MorphTester.png"; 198 258 //String default_file = testDirectory+"TestImages/NotSheetMusic01.png"; … … 803 863 804 864 //***************************************************************** 805 //Circles and centreson processed images865 //Circles on processed images 806 866 //***************************************************************** 807 808 //Init arrays 809 Mat circleOutput = allContoursFound.clone(); 810 MatOfPoint2f[] contoursPoly = new MatOfPoint2f[largeContours.size()]; 811 Point[] centers = new Point[largeContours.size()]; 812 float[][] radius = new float[largeContours.size()][1]; 813 814 //Fill arrays 815 for (int i = 0; i < largeContours.size(); i++) { 816 contoursPoly[i] = new MatOfPoint2f(); 817 Imgproc.approxPolyDP(new MatOfPoint2f(largeContours.get(i).toArray()), contoursPoly[i], 1, true); 818 centers[i] = new Point(); 819 Imgproc.minEnclosingCircle(contoursPoly[i], centers[i], radius[i]); 820 821 } 822 //Draw circle for each large contour 823 for (int i = 0; i < largeContours.size(); i++) { 824 Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1); 825 } 826 imageViewer("82 Circles found", circleOutput); 867 // //Init arrays 868 // Mat circleOutput = allContoursFound.clone(); 869 // MatOfPoint2f[] contoursPoly = new MatOfPoint2f[largeContours.size()]; 870 // Point[] centers = new Point[largeContours.size()]; 871 // float[][] radius = new float[largeContours.size()][1]; 872 // 873 // //Fill arrays 874 // for (int i = 0; i < largeContours.size(); i++) { 875 // contoursPoly[i] = new MatOfPoint2f(); 876 // Imgproc.approxPolyDP(new MatOfPoint2f(largeContours.get(i).toArray()), contoursPoly[i], 1, true); 877 // centers[i] = new Point(); 878 // Imgproc.minEnclosingCircle(contoursPoly[i], centers[i], radius[i]); 879 // 880 // } 881 // //Draw circle for each large contour 882 // for (int i = 0; i < largeContours.size(); i++) { 883 // Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1); 884 // } 885 // imageViewer("82 Circles found", circleOutput); 827 886 828 887 //******************************************************************************** 829 //Centroids - 888 //Centroids -Everything must be to scale 830 889 //******************************************************************************** 831 890 … … 908 967 if(CODE_VERSION == 81) { 909 968 910 //Display Original 911 //imageViewer("original", original1); 912 913 Mat test = original.clone(); 914 915 916 //imageViewer("00 Inverse Binarized Original", test); 917 918 919 //************************************ 920 //Large Object Removal 921 //************************************ 922 Mat srcLOR = original.clone(); 923 Mat maskLOR = new Mat(); 924 Mat dstLOR = new Mat(); 925 926 //denoize 927 Mat denoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 928 Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, denoize); 929 //imageViewer("01 Denoize - mask", maskLOR); 930 931 //close up gaps 932 Mat gapCloser = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 933 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_CLOSE, gapCloser); 934 //imageViewer("02 gap closer - mask", maskLOR); 935 936 //Isolate large items 937 Mat isolateLarge = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8, 8)); 938 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_OPEN, isolateLarge); 939 //imageViewer("03 Isolate Large - mask", maskLOR); 940 941 //Remove large items from image 942 Core.bitwise_not(maskLOR,maskLOR); 943 srcLOR.copyTo(dstLOR, maskLOR); 944 //imageViewer("04 Large Items Removed", dstLOR); 945 946 //**************************************** 947 //Small object removal (SOR) 948 //**************************************** 949 950 Mat srcSOR = dstLOR.clone(); 951 Mat maskSOR = new Mat(); 952 Mat dstSOR = new Mat(); 953 954 Mat startSOR =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 955 Imgproc.morphologyEx(srcSOR,maskSOR, Imgproc.MORPH_OPEN, startSOR); 956 //imageViewer("11 show small - mask", maskSOR); 957 958 Mat highlightSmall = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 959 Imgproc.dilate(maskSOR, maskSOR, highlightSmall); 960 //imageViewer("12 highlight small - mask", maskSOR); 969 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 970 Pair returnVariables = new Pair(); 971 int FILLED = -1; 972 try{ 973 //Mat original1 = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 974 //System.out.println("Width: " + original1.width() + " Height: " + original1.height()); 975 //Mat original = original1.clone(); 976 //Imgproc.adaptiveThreshold(original1, original,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 977 978 Mat test = original.clone(); 979 //************************************ 980 //Large Object Removal 981 //************************************ 982 Mat srcLOR = original.clone(); 983 Mat maskLOR = new Mat(); 984 Mat dstLOR = new Mat(); 985 986 //denoize 987 Mat denoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 988 Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, denoize); 989 990 //close up gaps 991 Mat gapCloser = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 992 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_CLOSE, gapCloser); 993 994 //Isolate large items 995 Mat isolateLarge = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8, 8)); 996 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_OPEN, isolateLarge); 997 998 //Remove large items from image 999 Core.bitwise_not(maskLOR,maskLOR); 1000 srcLOR.copyTo(dstLOR, maskLOR); 1001 1002 //**************************************** 1003 //Small object removal (SOR) 1004 //**************************************** 1005 1006 Mat srcSOR = dstLOR.clone(); 1007 Mat maskSOR = new Mat(); 1008 Mat dstSOR = new Mat(); 1009 1010 Mat startSOR =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 1011 Imgproc.morphologyEx(srcSOR,maskSOR, Imgproc.MORPH_OPEN, startSOR); 1012 1013 Mat highlightSmall = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 1014 Imgproc.dilate(maskSOR, maskSOR, highlightSmall); 1015 961 1016 962 1017 /* Mat isolateSmall =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10)); … … 965 1020 */ 966 1021 967 //Remove small items from image 968 Core.bitwise_not(maskSOR, maskSOR); 969 srcSOR.copyTo(dstSOR, maskSOR); 970 //imageViewer("14 Small Items Removed", dstSOR); 971 972 973 //**************************************** 974 //start staff line detection 975 //**************************************** 976 977 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15,2)); //10,2 978 Imgproc.erode(dstSOR,test,kernelErode); 979 //imageViewer("21 Erode plus pre", test); 980 981 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //20,3 982 Imgproc.dilate(test,test,kernelDilate); 983 //imageViewer("22 Dilate", test); 984 985 Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 986 Imgproc.morphologyEx(test, test, Imgproc.MORPH_CLOSE, kernelClose); 987 //imageViewer("23 Close", test); 988 989 990 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //10,1 991 Imgproc.erode(test,test,kernelErode02); 992 //imageViewer("24 Erode (Final)", test); 993 994 //******************************************************************************** 995 //DETECT OUTLINE AND FIND AREA OF THESE LINES. 996 //******************************************************************************** 997 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 998 ArrayList<MatOfPoint> largeContours = new ArrayList<MatOfPoint>(); 999 ArrayList<MatOfPoint> postContours = new ArrayList<MatOfPoint>(); 1000 Mat hierarchy = new Mat(); 1001 1002 //PARAMETERS: input image, output array of arrays, output array, contour retrieval mode, contour approximation method. 1003 //(contours) output array of arrays: Detected contours. Each contour is stored as a vector of points 1004 //(hierarchy) output array: Optional output vector, containing information about the image topology. 1005 //https://docs.opencv.org/3.3.1/d3/dc0/group__imgproc__shape.html#ga17ed9f5d79ae97bd4c7cf18403e1689a 1006 1007 Imgproc.findContours(test, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 1008 1009 System.out.println(contours.size()); 1010 //Draw contours and record areas 1011 Mat allContoursFound = Mat.zeros(test.size(), CvType.CV_8UC3); 1012 Mat largeContoursFound = allContoursFound.clone() ; 1013 Mat postContoursFound = allContoursFound.clone(); 1014 int areaCounter = 0; 1015 1016 //Have created a preprocess to remove large objects. 1017 //Need to now finalized Classifier, re try area detection. 1018 //Paths to take - rectangle boxes around detected contours over threshold (area or perimeter) 1019 //Just use area and periemter to determine if sheet music 1020 //Discuss with david before weekend perhaps? 1021 1022 Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8 1023 for (int i = 0; i < contours.size(); i++) { 1024 double area = Imgproc.contourArea(contours.get(i)); 1025 if(area > 100) { 1026 //System.out.println("AREA: " + area); 1027 Imgproc.drawContours(largeContoursFound, contours, i, new Scalar(255, 0, 0), FILLED); 1028 //create list of large coutours found 1029 largeContours.add(contours.get(i)); 1030 } 1031 } 1032 //imageViewer("80 All Contours found", allContoursFound); 1033 //imageViewer("81 Large Contours Found", largeContoursFound); 1034 1035 //***************************************************************** 1036 //Circles and centres on processed images 1037 //***************************************************************** 1038 1039 //Init arrays 1040 Mat circleOutput = allContoursFound.clone(); 1041 MatOfPoint2f[] contoursPoly = new MatOfPoint2f[largeContours.size()]; 1042 Point[] centers = new Point[largeContours.size()]; 1043 float[][] radius = new float[largeContours.size()][1]; 1044 1045 //Fill arrays 1046 for (int i = 0; i < largeContours.size(); i++) { 1047 contoursPoly[i] = new MatOfPoint2f(); 1048 Imgproc.approxPolyDP(new MatOfPoint2f(largeContours.get(i).toArray()), contoursPoly[i], 1, true); 1049 centers[i] = new Point(); 1050 Imgproc.minEnclosingCircle(contoursPoly[i], centers[i], radius[i]); 1051 1052 } 1053 //Draw circle for each large contour 1054 for (int i = 0; i < largeContours.size(); i++) { 1055 Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1); 1056 } 1057 //imageViewer("82 Circles found", circleOutput); 1058 1059 //******************************************************************************** 1060 //Centroids - Everything must be to scale 1061 //******************************************************************************** 1062 1063 ArrayList<Moments> mu = new ArrayList<Moments>(largeContours.size()); 1064 Mat centreOutput = Mat.zeros(largeContoursFound.size(), CvType.CV_8UC3); 1065 for (int i = 0; i < largeContours.size(); i++) { 1066 mu.add(i, Imgproc.moments(largeContours.get(i), false)); 1067 Moments p = mu.get(i); 1068 int x = (int) (p.get_m10() / p.get_m00()); 1069 int y = (int) (p.get_m01() / p.get_m00()); 1070 Imgproc.circle(centreOutput, new Point(x, y), 4, new Scalar(255, 255, 255), 30); 1071 } 1072 //imageViewer("83 Centres found", centreOutput); 1073 1074 1075 //*********************************************** 1076 //PostProcessing - Morphology Classifier 1077 // Use dilation to "Connect the dots" 1078 // Testing showed the centroids were clustered together 1079 // Then use area or perimeter as a classifier filter 1080 //REFINEREFINEREIFEN 1081 //REFINEREFINEREIFEN 1082 //REFINEREFINEREIFEN 1083 //REFINEREFINEREIFEN 1084 //REFINEREFINEREIFEN 1085 //REFINEREFINEREIFEN 1086 //*********************************************** 1087 1088 Mat postDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(150,15)); 1089 Imgproc.dilate(centreOutput,centreOutput,postDilate); 1090 //imageViewer("91 PostDilated", centreOutput); 1091 1092 Mat postClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 1093 Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_CLOSE, postClose); 1094 //imageViewer("92 PostClose", centreOutput); 1095 1096 Mat postDenoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,100)); 1097 Imgproc.morphologyEx(centreOutput,centreOutput, Imgproc.MORPH_OPEN, postDenoize); 1098 //imageViewer("93 PostDenoize", centreOutput); 1099 1100 //Mat postOutline = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(50,50)); 1101 //Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_GRADIENT, postOutline); 1102 1103 1104 1105 //Find area 1106 Mat centreOutputGrey = new Mat(); 1107 Imgproc.cvtColor(centreOutput, centreOutputGrey, Imgproc.COLOR_RGB2GRAY); 1108 Imgproc.findContours(centreOutputGrey, postContours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 1109 1110 for (int i = 0; i < postContours.size(); i++) { 1111 double area = Imgproc.contourArea(postContours.get(i)); 1112 if(area > 10000) { 1113 //System.out.println("POST AREA: " + area); 1114 Imgproc.drawContours(postContoursFound, postContours, i, new Scalar(0, 255, 0), FILLED); 1115 areaCounter++; 1116 } 1117 } 1118 //imageViewer("93 PostEND", postContoursFound); 1119 1120 //Classifier Calculation 1121 if(areaCounter >= THRESHOLD_AREA_COUNT){ 1122 //System.out.println("THIS IS SHEET MUSIC"); 1123 //System.out.println(areaCounter); 1124 } 1125 1126 1022 //Remove small items from image 1023 Core.bitwise_not(maskSOR, maskSOR); 1024 srcSOR.copyTo(dstSOR, maskSOR); 1025 1026 1027 //**************************************** 1028 //start staff line detection 1029 //**************************************** 1030 1031 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15,2)); //10,2 1032 Imgproc.erode(dstSOR,test,kernelErode); 1033 1034 1035 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //20,3 1036 Imgproc.dilate(test,test,kernelDilate); 1037 1038 1039 Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 1040 Imgproc.morphologyEx(test, test, Imgproc.MORPH_CLOSE, kernelClose); 1041 1042 1043 1044 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //10,1 1045 Imgproc.erode(test,test,kernelErode02); 1046 1047 1048 //******************************************************************************** 1049 //DETECT OUTLINE AND FIND AREA OF THESE LINES. 1050 //******************************************************************************** 1051 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 1052 ArrayList<MatOfPoint> largeContours = new ArrayList<MatOfPoint>(); 1053 ArrayList<MatOfPoint> postContours = new ArrayList<MatOfPoint>(); 1054 Mat hierarchy = new Mat(); 1055 1056 //PARAMETERS: input image, output array of arrays, output array, contour retrieval mode, contour approximation method. 1057 //(contours) output array of arrays: Detected contours. Each contour is stored as a vector of points 1058 //(hierarchy) output array: Optional output vector, containing information about the image topology. 1059 //https://docs.opencv.org/3.3.1/d3/dc0/group__imgproc__shape.html#ga17ed9f5d79ae97bd4c7cf18403e1689a 1060 1061 Imgproc.findContours(test, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 1062 1063 System.out.println(contours.size()); 1064 //Draw contours and record areas 1065 Mat allContoursFound = Mat.zeros(test.size(), CvType.CV_8UC3); 1066 Mat largeContoursFound = allContoursFound.clone() ; 1067 Mat postContoursFound = allContoursFound.clone(); 1068 int areaCounter = 0; 1069 1070 //Have created a preprocess to remove large objects. 1071 //Need to now finalized Classifier, re try area detection. 1072 //Paths to take - rectangle boxes around detected contours over threshold (area or perimeter) 1073 //Just use area and periemter to determine if sheet music 1074 //Discuss with david before weekend perhaps? 1075 1076 Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8 1077 for (int i = 0; i < contours.size(); i++) { 1078 double area = Imgproc.contourArea(contours.get(i)); 1079 if(area > 100) { 1080 //System.out.println("AREA: " + area); 1081 Imgproc.drawContours(largeContoursFound, contours, i, new Scalar(255, 0, 0), FILLED); 1082 //create list of large coutours found 1083 largeContours.add(contours.get(i)); 1084 } 1085 } 1086 1087 //***************************************************************** 1088 //Circles and centres on processed images 1089 //***************************************************************** 1090 1091 //Init arrays 1092 Mat circleOutput = allContoursFound.clone(); 1093 MatOfPoint2f[] contoursPoly = new MatOfPoint2f[largeContours.size()]; 1094 Point[] centers = new Point[largeContours.size()]; 1095 float[][] radius = new float[largeContours.size()][1]; 1096 1097 //Fill arrays 1098 for (int i = 0; i < largeContours.size(); i++) { 1099 contoursPoly[i] = new MatOfPoint2f(); 1100 Imgproc.approxPolyDP(new MatOfPoint2f(largeContours.get(i).toArray()), contoursPoly[i], 1, true); 1101 centers[i] = new Point(); 1102 Imgproc.minEnclosingCircle(contoursPoly[i], centers[i], radius[i]); 1103 1104 } 1105 //Draw circle for each large contour 1106 for (int i = 0; i < largeContours.size(); i++) { 1107 Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1); 1108 } 1109 1110 1111 //******************************************************************************** 1112 //Centroids - Everything must be to scale 1113 //******************************************************************************** 1114 1115 ArrayList<Moments> mu = new ArrayList<Moments>(largeContours.size()); 1116 Mat centreOutput = Mat.zeros(largeContoursFound.size(), CvType.CV_8UC3); 1117 for (int i = 0; i < largeContours.size(); i++) { 1118 mu.add(i, Imgproc.moments(largeContours.get(i), false)); 1119 Moments p = mu.get(i); 1120 int x = (int) (p.get_m10() / p.get_m00()); 1121 int y = (int) (p.get_m01() / p.get_m00()); 1122 Imgproc.circle(centreOutput, new Point(x, y), 4, new Scalar(255, 255, 255), 30); 1123 } 1124 1125 //*********************************************** 1126 //PostProcessing - Morphology Classifier 1127 // Use dilation to "Connect the dots" 1128 // Testing showed the centroids were clustered together 1129 // Then use area or perimeter as a classifier filter 1130 //*********************************************** 1131 1132 Mat postDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(150,15)); 1133 Imgproc.dilate(centreOutput,centreOutput,postDilate); 1134 1135 Mat postClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 1136 Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_CLOSE, postClose); 1137 1138 Mat postDenoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,100)); 1139 Imgproc.morphologyEx(centreOutput,centreOutput, Imgproc.MORPH_OPEN, postDenoize); 1140 1141 //Find area 1142 Mat centreOutputGrey = new Mat(); 1143 Imgproc.cvtColor(centreOutput, centreOutputGrey, Imgproc.COLOR_RGB2GRAY); 1144 Imgproc.findContours(centreOutputGrey, postContours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 1145 1146 for (int i = 0; i < postContours.size(); i++) { 1147 double area = Imgproc.contourArea(postContours.get(i)); 1148 if(area > THRESHOLD_AREA_SIZE) { 1149 //System.err.println("POST AREA: " + area); 1150 Imgproc.drawContours(postContoursFound, postContours, i, new Scalar(0, 255, 0), FILLED); 1151 areaCounter++; 1152 } 1153 } 1154 //Classifier Calculation 1155 if(areaCounter >= THRESHOLD_AREA_COUNT){ 1156 returnVariables.setBoolean(true); 1157 returnVariables.setInteger(areaCounter); 1158 } 1159 } 1160 catch(Exception e){ 1161 System.err.println(e); 1162 } 1163 //return returnVariables; 1127 1164 } 1128 1165 1166 //Reset after david chat 1167 if(CODE_VERSION == 9){ 1168 //1. Remove large items (needs to be larger kernel, should not remove bar lines) 1169 //2. Remove text 1170 //3. Standard plan from presentation 1171 //4. Classify like line clusters. 1172 } 1129 1173 //USE stuc element, to rule out large wide and long pieces of black and white. 1130 1174 -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/Makefile
r33447 r33449 19 19 20 20 testrun-classifier-single-cluster: 21 ./runClassifer.sh TestImages/ test-coo.31924062612282-9.png cluster logSingle.txt -singleNew21 ./runClassifer.sh TestImages/high-res-test-coo.31924062612282-9.png cluster logSingle.txt -singleNew 22 22 echo "Displaying javaImageClassifier output" 23 23 #Calculate the Accuracy of the classifier … … 28 28 29 29 testrun-classifier-single-count: 30 ./runClassifer.sh TestImages/test-coo.31924062612282-9.png count logSingle.txt -singleNew30 ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU/SheetMusic/coo.31924062612282-9.png count logSingle.txt -singleNew 31 31 echo "Displaying javaImageClassifier output" 32 32 #Calculate the Accuracy of the classifier … … 36 36 37 37 testrun-classifier-single-combo: 38 ./runClassifer.sh TestImages/test-coo.31924062612282-9.png combo logSingle.txt -singleNew38 ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU/SheetMusic/coo.31924062612282-9.png combo logSingle.txt -singleNew 39 39 echo "Displaying javaImageClassifier output" 40 40 #Calculate the Accuracy of the classifier … … 45 45 testrun-classifier-single-morph: 46 46 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 47 ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU/SheetMusic/coo.31924062612282-9.png morphology log-all-hires-new/test/logSingle.txt -singleNew 47 ./runClassifer.sh TestImages/hi-res-test-coo.31924062612282-9.png morphology log-all-hires-new/test/logSingle.txt -singleNew 48 #./runClassifer.sh TestImages/low-res-test-coo.31924062612282-9.png morphology log-all-hires-new/test/logSingle.txt -singleNew 49 #./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU/SheetMusic/low-res-test-coo.31924062612282-9.png morphology log-all-hires-new/test/logSingle.txt -singleNew 48 50 echo "Displaying javaImageClassifier output" 49 51 #Calculate the Accuracy of the classifier … … 53 55 54 56 57 -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaClassifierComparison.java
r33447 r33449 182 182 //Execute classifierType defined from arguement 183 183 184 File imgCheck = new File(imageFilename); 185 if(!imgCheck.exists()){System.err.println("Image not found: "+ imageFilename);} 186 184 187 //Split output by tab for processing in next java program 185 188 //imageFilename = 1, result = 3, classifierType = 4 … … 201 204 break; 202 205 case "morphology": 203 algorithmResult = Algorithm_Morphology OLD(imageFilename);206 algorithmResult = Algorithm_Morphology(imageFilename); 204 207 bw.write("Filename:" + '\t' + imageFilename + '\t' + "Classified as:" + '\t' + algorithmResult.getBoolean() + '\t' + "Number of areas:" + '\t' + algorithmResult.getInteger() + '\t' + classifierType + '\n'); 205 208 break; … … 330 333 Boolean isSheetMusic = null; 331 334 Pair returnVariables = new Pair(); 335 int areaCounter = 0; 332 336 try{ 333 //Variables334 int areaCounter = 0;335 337 Mat edgesDetectedRGB = new Mat(); 336 338 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 339 340 System.out.println("Width: " + original.width() + " Height: " + original.height()); 337 341 338 342 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); … … 361 365 for (int i = 0; i < contours.size(); i++) { 362 366 double area = Imgproc.contourArea(contours.get(i)); 367 System.out.println("AREA: " + area); 363 368 //Check if area detected meets threshold 364 369 if(area > THRESHOLD_AREA_SIZE) { 365 370 areaCounter++; 366 //System.out.println("AREA: " + area); 367 } 368 } 369 370 371 372 373 371 372 } 373 } 374 System.out.println("areacount = " + areaCounter); 374 375 375 376 //Calculates if sheet music or not 376 377 if(areaCounter >= THRESHOLD_AREA_COUNT){ 377 returnVariables.setBoolean(true); 378 isSheetMusic = true; 379 returnVariables.setBoolean(isSheetMusic); 378 380 returnVariables.setInteger(areaCounter); 379 381 } … … 389 391 Boolean isSheetMusic = null; 390 392 Pair returnVariables = new Pair(); 393 int FILLED = -1; 391 394 try{ 392 int FILLED = -1;393 //Display Original394 //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); 396 399 Mat test = original.clone(); 397 //imageViewer("00 Inverse Binarized Original", test);398 399 400 400 //************************************ 401 401 //Large Object Removal … … 408 408 Mat denoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 409 409 Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, denoize); 410 //imageViewer("01 Denoize - mask", maskLOR);411 410 412 411 //close up gaps 413 412 Mat gapCloser = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 414 413 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_CLOSE, gapCloser); 415 //imageViewer("02 gap closer - mask", maskLOR);416 414 417 415 //Isolate large items 418 416 Mat isolateLarge = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8, 8)); 419 417 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_OPEN, isolateLarge); 420 //imageViewer("03 Isolate Large - mask", maskLOR);421 418 422 419 //Remove large items from image 423 420 Core.bitwise_not(maskLOR,maskLOR); 424 421 srcLOR.copyTo(dstLOR, maskLOR); 425 //imageViewer("04 Large Items Removed", dstLOR);426 422 427 423 //**************************************** … … 435 431 Mat startSOR =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 436 432 Imgproc.morphologyEx(srcSOR,maskSOR, Imgproc.MORPH_OPEN, startSOR); 437 //imageViewer("11 show small - mask", maskSOR);438 433 439 434 Mat highlightSmall = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 440 435 Imgproc.dilate(maskSOR, maskSOR, highlightSmall); 441 //imageViewer("12 highlight small - mask", maskSOR); 436 442 437 443 438 /* Mat isolateSmall =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10)); … … 449 444 Core.bitwise_not(maskSOR, maskSOR); 450 445 srcSOR.copyTo(dstSOR, maskSOR); 451 //imageViewer("14 Small Items Removed", dstSOR);452 446 453 447 … … 458 452 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15,2)); //10,2 459 453 Imgproc.erode(dstSOR,test,kernelErode); 460 //imageViewer("21 Erode plus pre", test); 454 461 455 462 456 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //20,3 463 457 Imgproc.dilate(test,test,kernelDilate); 464 //imageViewer("22 Dilate", test); 458 465 459 466 460 Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 467 461 Imgproc.morphologyEx(test, test, Imgproc.MORPH_CLOSE, kernelClose); 468 //imageViewer("23 Close", test); 462 469 463 470 464 471 465 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //10,1 472 466 Imgproc.erode(test,test,kernelErode02); 473 //imageViewer("24 Erode (Final)", test); 467 474 468 475 469 //******************************************************************************** … … 511 505 } 512 506 } 513 //imageViewer("80 All Contours found", allContoursFound);514 //imageViewer("81 Large Contours Found", largeContoursFound);515 507 516 508 //***************************************************************** … … 536 528 Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1); 537 529 } 538 //imageViewer("82 Circles found", circleOutput); 530 539 531 540 532 //******************************************************************************** … … 551 543 Imgproc.circle(centreOutput, new Point(x, y), 4, new Scalar(255, 255, 255), 30); 552 544 } 553 //imageViewer("83 Centres found", centreOutput);554 555 545 556 546 //*********************************************** … … 563 553 Mat postDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(150,15)); 564 554 Imgproc.dilate(centreOutput,centreOutput,postDilate); 565 //imageViewer("91 PostDilated", centreOutput);566 555 567 556 Mat postClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 568 557 Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_CLOSE, postClose); 569 //imageViewer("92 PostClose", centreOutput);570 558 571 559 Mat postDenoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,100)); 572 560 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);577 561 578 562 //Find area … … 584 568 double area = Imgproc.contourArea(postContours.get(i)); 585 569 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); 588 572 areaCounter++; 589 573 } 590 574 } 591 592 //imageViewer("93 PostEND", postContoursFound); 593 594 //Calculates if sheet music or not 575 //Classifier Calculation 595 576 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 } 602 580 } 603 581 catch(Exception e){
Note:
See TracChangeset
for help on using the changeset viewer.