Changeset 33589
- Timestamp:
- 2019-10-21T21:45:10+13:00 (5 years ago)
- Location:
- other-projects/is-sheet-music-encore/trunk
- Files:
-
- 34 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/is-sheet-music-encore/trunk/EndToEndSystem.sh
r33458 r33589 14 14 #Test/Dev Scripts 15 15 #**************************************************************************************************** 16 17 18 16 if [ $type == "argTest" ] ; then 17 if [ $# != 3 ] ; then 18 echo "Usage:./EndToEndSystem <ClassifierType> <ResultSubDirectory> <borderIgnoreAmount> " 19 exit 1 20 fi 21 location=$2 22 borderIgnoreAmount=$3 23 cd image-identification-terminal 24 mkdir log-EndToEnd/$location/ 25 #Delete files if exists 26 if [ -d log-EndToEnd/$location ] ; then 27 echo "removing folder logEndToEnd/$location" 28 rm -r log-EndToEnd/$location/ 29 mkdir log-EndToEnd/$location/ 30 fi 31 32 echo $'\n***********************************************\n' >> log-EndToEnd/$location/results.txt 33 echo "Start Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 34 echo >> log-EndToEnd/$location/results.txt #Add Space 35 cat configClassifierComparison.properties >> log-EndToEnd/$location/results.txt #Add config 36 echo $'ARGUEMENT DETAILS: \n' >> log-EndToEnd/$location/results.txt 37 echo "borderIgnoreAmount: $borderIgnoreAmount. That is to say that outer $borderIgnoreAmount% of the image was not considered by the algorithm." >> log-EndToEnd/$location/results.txt 38 echo "[NYI]" >> log-EndToEnd/$location/results.txt 39 echo >> log-EndToEnd/$location/results.txt #Space 40 41 #Compile 42 echo "Compiling java programs..." 43 javac javaAccuracyCalculator.java 44 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 45 46 #Classifiers 47 echo "Successfuly Compiled, running classifer now..." 48 ./runClassiferV02.sh -argTest /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU morphology log-EndToEnd/$location/log-morph-MU.txt $borderIgnoreAmount 49 50 #Accuracy Calculation 51 echo "Successfuly Classified, writing results now..." 52 java javaAccuracyCalculator log-EndToEnd/$location/log-morph-MU.txt morph-MU log-EndToEnd/$location/results.txt 53 echo >>log-EndToEnd/$location/results.txt 54 echo "End Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 55 #.././calculateCorpusAccuracy.sh 56 57 #less log-EndToEnd/$location/results.txt 58 exit $? 59 fi 19 60 20 61 #**************************************************************************************************** … … 30 71 fi 31 72 echo $new_page_num 32 exit 173 exit $? 33 74 fi 34 75 #**************************************************************************************************** 35 76 #Classifier Scripts [HIGHRES BY DEFUALT] 36 77 #**************************************************************************************************** 78 79 #Morphology - No args 80 37 81 if [ $type == "morph" ] ; then 38 82 if [ $# != 2 ] ; then 39 echo "Usage:./EndToEndSystem cluster<ResultSubDirectory> "83 echo "Usage:./EndToEndSystem <ClassifierType> <ResultSubDirectory> " 40 84 exit 1 41 85 fi … … 49 93 #Classifiers 50 94 echo "Successfuly Compiled, running classifer now..." 51 ./runClassifer .sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU morphology log-EndToEnd/$location/log-morph-MU.txt -allNew52 ./runClassifer .sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK morphology log-EndToEnd/$location/log-morph-BK.txt -allNew53 ./runClassifer .sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP morphology log-EndToEnd/$location/log-morph-MP.txt -allNew54 ./runClassifer .sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE morphology log-EndToEnd/$location/log-morph-SE.txt -allNew95 ./runClassiferV02.sh -all /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU morphology log-EndToEnd/$location/log-morph-MU.txt 96 ./runClassiferV02.sh -all /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK morphology log-EndToEnd/$location/log-morph-BK.txt 97 ./runClassiferV02.sh -all /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP morphology log-EndToEnd/$location/log-morph-MP.txt 98 ./runClassiferV02.sh -all /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE morphology log-EndToEnd/$location/log-morph-SE.txt 55 99 #Results 56 100 echo "Successfuly Classified, writing results now..." … … 67 111 .././calculateCorpusAccuracy.sh 68 112 less log-EndToEnd/$location/results.txt 69 exit 1 70 fi 113 exit $? 114 fi 115 116 #Cluster - No args 71 117 72 118 if [ $type == "cluster" ] ; then 73 119 74 120 if [ $# != 2 ] ; then 75 echo "Usage:./EndToEndSystem cluster<ResultSubDirectory>"121 echo "Usage:./EndToEndSystem <ClassifierType> <ResultSubDirectory>" 76 122 exit 1 77 123 fi … … 84 130 #Classifiers 85 131 echo "Successfuly Compiled, running classifer now..." 86 #./runClassifer .sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU cluster log-EndToEnd/$location/log-cluster-MU.txt -allNew87 #./runClassifer .sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK cluster log-EndToEnd/$location/log-cluster-BK.txt -allNew88 #./runClassifer .sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP cluster log-EndToEnd/$location/log-cluster-MP.txt -allNew89 #./runClassifer .sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE cluster log-EndToEnd/$location/log-cluster-SE.txt -allNew132 #./runClassiferV02.sh -all /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU cluster log-EndToEnd/$location/log-cluster-MU.txt 133 #./runClassiferV02.sh -all /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK cluster log-EndToEnd/$location/log-cluster-BK.txt 134 #./runClassiferV02.sh -all /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP cluster log-EndToEnd/$location/log-cluster-MP.txt 135 #./runClassiferV02.sh -all /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE cluster log-EndToEnd/$location/log-cluster-SE.txt 90 136 #Results 91 137 echo "Successfuly Classified, writing results now..." … … 102 148 .././calculateCorpusAccuracy.sh 103 149 less log-EndToEnd/$location/results.txt 104 exit 1 105 fi 150 exit $? 151 fi 152 153 #Morphology - Border Args -Corpus - No Map 154 155 if [ $type == "morph-border" ] ; then 156 if [ $# != 3 ] ; then 157 echo "Usage:./EndToEndSystem <ClassifierType> <ResultSubDirectory> <borderIgnoreAmount> " 158 exit 1 159 fi 160 location=$2 161 borderIgnoreAmount=$3 162 cd image-identification-terminal 163 mkdir log-EndToEnd/$location/ 164 #Delete files if exists 165 if [ -d log-EndToEnd/$location ] ; then 166 echo "removing folder logEndToEnd/$location" 167 rm -r log-EndToEnd/$location/ 168 mkdir log-EndToEnd/$location/ 169 fi 170 171 echo $'\n***********************************************\n' >> log-EndToEnd/$location/results.txt 172 echo "Start Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 173 echo >> log-EndToEnd/$location/results.txt #Add Space 174 cat configClassifierComparison.properties >> log-EndToEnd/$location/results.txt #Add config 175 echo $'ARGUEMENT DETAILS: \n' >> log-EndToEnd/$location/results.txt 176 echo "borderIgnoreAmount: $borderIgnoreAmount. That is to say that outer $borderIgnoreAmount% of the image was not considered by the algorithm." >> log-EndToEnd/$location/results.txt 177 echo "[NYI]" >> log-EndToEnd/$location/results.txt 178 echo >> log-EndToEnd/$location/results.txt #Space 179 180 #Compile 181 echo "Compiling java programs..." 182 javac javaAccuracyCalculator.java 183 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 184 185 #Classifiers 186 echo "Successfuly Compiled, running classifer now..." 187 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU morphology log-EndToEnd/$location/log-morph-MU.txt $borderIgnoreAmount 188 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK morphology log-EndToEnd/$location/log-morph-BK.txt $borderIgnoreAmount 189 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE morphology log-EndToEnd/$location/log-morph-SE.txt $borderIgnoreAmount 190 191 #Accuracy Calculation 192 echo "Successfuly Classified, writing results now..." 193 java javaAccuracyCalculator log-EndToEnd/$location/log-morph-MU.txt morph-MU log-EndToEnd/$location/results.txt 194 java javaAccuracyCalculator log-EndToEnd/$location/log-morph-BK.txt morph-BK log-EndToEnd/$location/results.txt 195 java javaAccuracyCalculator log-EndToEnd/$location/log-morph-SE.txt morph-SE log-EndToEnd/$location/results.txt 196 echo >>log-EndToEnd/$location/results.txt 197 echo "End Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 198 #.././calculateCorpusAccuracy.sh 199 200 #less log-EndToEnd/$location/results.txt 201 exit $? 202 fi 203 204 #HoughTransform - Cluster Args -Corpus - No Map 205 206 if [ $type == "cluster-border" ] ; then 207 if [ $# != 3 ] ; then 208 echo "Usage:./EndToEndSystem <ClassifierType> <ResultSubDirectory> <borderIgnoreAmount> " 209 exit 1 210 fi 211 location=$2 212 borderIgnoreAmount=$3 213 cd image-identification-terminal 214 mkdir log-EndToEnd/$location/ 215 #Delete files if exists 216 if [ -d log-EndToEnd/$location ] ; then 217 echo "removing folder logEndToEnd/$location" 218 rm -r log-EndToEnd/$location/ 219 mkdir log-EndToEnd/$location/ 220 fi 221 222 echo $'\n***********************************************\n' >> log-EndToEnd/$location/results.txt 223 echo "Start Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 224 echo >> log-EndToEnd/$location/results.txt #Add Space 225 cat configClassifierComparison.properties >> log-EndToEnd/$location/results.txt #Add config 226 echo $'ARGUEMENT DETAILS: \n' >> log-EndToEnd/$location/results.txt 227 echo "borderIgnoreAmount: $borderIgnoreAmount. That is to say that outer $borderIgnoreAmount% of the image was not considered by the algorithm." >> log-EndToEnd/$location/results.txt 228 echo "[NYI]" >> log-EndToEnd/$location/results.txt 229 echo >> log-EndToEnd/$location/results.txt #Space 230 231 #Compile 232 echo "Compiling java programs..." 233 javac javaAccuracyCalculator.java 234 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 235 236 #Classifiers 237 echo "Successfuly Compiled, running classifer now..." 238 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU cluster log-EndToEnd/$location/log-cluster-MU.txt $borderIgnoreAmount 239 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK cluster log-EndToEnd/$location/log-cluster-BK.txt $borderIgnoreAmount 240 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE cluster log-EndToEnd/$location/log-cluster-SE.txt $borderIgnoreAmount 241 242 #Accuracy Calculation 243 echo "Successfuly Classified, writing results now..." 244 java javaAccuracyCalculator log-EndToEnd/$location/log-cluster-MU.txt cluster-MU log-EndToEnd/$location/results.txt 245 java javaAccuracyCalculator log-EndToEnd/$location/log-cluster-BK.txt cluster-BK log-EndToEnd/$location/results.txt 246 java javaAccuracyCalculator log-EndToEnd/$location/log-cluster-SE.txt cluster-SE log-EndToEnd/$location/results.txt 247 echo >>log-EndToEnd/$location/results.txt 248 echo "End Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 249 #.././calculateCorpusAccuracy.sh 250 251 #less log-EndToEnd/$location/results.txt 252 exit $? 253 fi 254 255 256 257 #HoughTransform - Count Args -Corpus - No Map 258 259 if [ $type == "count-border" ] ; then 260 if [ $# != 3 ] ; then 261 echo "Usage:./EndToEndSystem <ClassifierType> <ResultSubDirectory> <borderIgnoreAmount> " 262 exit 1 263 fi 264 location=$2 265 borderIgnoreAmount=$3 266 cd image-identification-terminal 267 mkdir log-EndToEnd/$location/ 268 #Delete files if exists 269 if [ -d log-EndToEnd/$location ] ; then 270 echo "removing folder logEndToEnd/$location" 271 rm -r log-EndToEnd/$location/ 272 mkdir log-EndToEnd/$location/ 273 fi 274 275 echo $'\n***********************************************\n' >> log-EndToEnd/$location/results.txt 276 echo "Start Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 277 echo >> log-EndToEnd/$location/results.txt #Add Space 278 cat configClassifierComparison.properties >> log-EndToEnd/$location/results.txt #Add config 279 echo $'ARGUEMENT DETAILS: \n' >> log-EndToEnd/$location/results.txt 280 echo "borderIgnoreAmount: $borderIgnoreAmount. That is to say that outer $borderIgnoreAmount% of the image was not considered by the algorithm." >> log-EndToEnd/$location/results.txt 281 echo "[NYI]" >> log-EndToEnd/$location/results.txt 282 echo >> log-EndToEnd/$location/results.txt #Space 283 284 #Compile 285 echo "Compiling java programs..." 286 javac javaAccuracyCalculator.java 287 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 288 289 #Classifiers 290 echo "Successfuly Compiled, running classifer now..." 291 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU count log-EndToEnd/$location/log-count-MU.txt $borderIgnoreAmount 292 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK count log-EndToEnd/$location/log-count-BK.txt $borderIgnoreAmount 293 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE count log-EndToEnd/$location/log-count-SE.txt $borderIgnoreAmount 294 295 #Accuracy Calculation 296 echo "Successfuly Classified, writing results now..." 297 java javaAccuracyCalculator log-EndToEnd/$location/log-count-MU.txt count-MU log-EndToEnd/$location/results.txt 298 java javaAccuracyCalculator log-EndToEnd/$location/log-count-BK.txt count-BK log-EndToEnd/$location/results.txt 299 java javaAccuracyCalculator log-EndToEnd/$location/log-count-SE.txt count-SE log-EndToEnd/$location/results.txt 300 echo >>log-EndToEnd/$location/results.txt 301 echo "End Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 302 #.././calculateCorpusAccuracy.sh 303 304 #less log-EndToEnd/$location/results.txt 305 exit $? 306 fi 307 308 309 310 311 312 #Map SCRIPT 313 314 if [ $type == "map-hough-morph" ] ; then 315 if [ $# != 3 ] ; then 316 echo "Usage:./EndToEndSystem <ClassifierType> <ResultSubDirectory> <borderIgnoreAmount> " 317 exit 1 318 fi 319 location=$2 320 borderIgnoreAmount=$3 321 cd image-identification-terminal 322 mkdir log-EndToEnd/$location/ 323 #Delete files if exists 324 if [ -d log-EndToEnd/$location ] ; then 325 echo "removing folder logEndToEnd/$location" 326 rm -r log-EndToEnd/$location/ 327 mkdir log-EndToEnd/$location/ 328 fi 329 330 echo $'\n***********************************************\n' >> log-EndToEnd/$location/results.txt 331 echo "Start Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 332 echo >> log-EndToEnd/$location/results.txt #Add Space 333 cat configClassifierComparison.properties >> log-EndToEnd/$location/results.txt #Add config 334 echo $'ARGUEMENT DETAILS: \n' >> log-EndToEnd/$location/results.txt 335 echo "borderIgnoreAmount: $borderIgnoreAmount. That is to say that outer $borderIgnoreAmount% of the image was not considered by the algorithm." >> log-EndToEnd/$location/results.txt 336 echo "[NYI]" >> log-EndToEnd/$location/results.txt 337 echo >> log-EndToEnd/$location/results.txt 338 339 #Compile 340 echo "Compiling java programs..." 341 javac javaAccuracyCalculator.java 342 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 343 344 #Classifiers 345 echo "Successfuly Compiled, running classifer now..." 346 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP count log-EndToEnd/$location/log-count-MP.txt $borderIgnoreAmount 347 ./runClassiferV02.sh -borderAll /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP morphology log-EndToEnd/$location/log-morph-MP.txt $borderIgnoreAmount 348 349 #Accuracy Calculation 350 echo "Successfuly Classified, writing results now..." 351 java javaAccuracyCalculator log-EndToEnd/$location/log-count-MP.txt count-MP log-EndToEnd/$location/results.txt 352 java javaAccuracyCalculator log-EndToEnd/$location/log-morph-MP.txt morph-MP log-EndToEnd/$location/results.txt 353 354 echo >>log-EndToEnd/$location/results.txt 355 echo "End Time: $(date +"%T")" >> log-EndToEnd/$location/results.txt #Add End Time 356 #.././calculateCorpusAccuracy.sh 357 358 #less log-EndToEnd/$location/results.txt 359 exit $? 360 fi 361 362 363 364 106 365 107 366 -
other-projects/is-sheet-music-encore/trunk/Makefile
r33458 r33589 1 #********** 2 #Quick CMD for EndToEndSystem.sh 3 #********** 4 ete-twentyMU-borders-quick: 5 ./EndToEndSystem.sh argTest argTest0p 0 6 ./EndToEndSystem.sh argTest argTest5p 5 7 ./EndToEndSystem.sh argTest argTest10p 10 8 ./EndToEndSystem.sh argTest argTest20p 20 9 ./EndToEndSystem.sh argTest argTest40p 40 10 cd image-identification-terminal/log-EndToEnd; cat */results.txt > BatchResults.txt 11 12 ete-all-borders-morph: 13 ./EndToEndSystem.sh morph-border morph-border-at-0 0 14 ./EndToEndSystem.sh morph-border morph-border-at-5 5 15 ./EndToEndSystem.sh morph-border morph-border-at-10 10 16 ./EndToEndSystem.sh morph-border morph-border-at-20 20 17 ./EndToEndSystem.sh morph-border morph-border-at-40 40 18 cd image-identification-terminal/log-EndToEnd; cat morph*/results.txt > BatchResultsMorph.txt 19 20 ete-all-borders-cluster: 21 ./EndToEndSystem.sh cluster-border cluster-border-at-0 0 22 ./EndToEndSystem.sh cluster-border cluster-border-at-5 5 23 ./EndToEndSystem.sh cluster-border cluster-border-at-10 10 24 ./EndToEndSystem.sh cluster-border cluster-border-at-20 20 25 ./EndToEndSystem.sh cluster-border cluster-border-at-40 40 26 cd image-identification-terminal/log-EndToEnd; cat cluster*/results.txt > BatchResultsCluster.txt 27 28 ete-all-borders-count: 29 ./EndToEndSystem.sh count-border count-border-at-0 0 30 ./EndToEndSystem.sh count-border count-border-at-5 5 31 ./EndToEndSystem.sh count-border count-border-at-10 10 32 ./EndToEndSystem.sh count-border count-border-at-20 20 33 ./EndToEndSystem.sh count-border count-border-at-40 40 34 cd image-identification-terminal/log-EndToEnd; cat count*/results.txt > BatchResultsCount.txt 35 36 #BLOCKSIZE (CHANGED MAIN COMPARISION JAVA FILE FROM 15 to BLOCKSIZE) 37 38 ete-all-borders-count-BLOCKSIZED: 39 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-0 0 40 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-5 5 41 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-10 10 42 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-20 20 43 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-40 40 44 cd image-identification-terminal/log-EndToEnd; cat count-borderBLOCKSIZED*/results.txt > BatchResultsCountBLOCKSIZED.txt 45 ete-all-borders-morph-BLOCKSIZED: 46 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-0 0 47 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-5 5 48 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-10 10 49 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-20 20 50 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-40 40 51 cd image-identification-terminal/log-EndToEnd; cat morph-borderBLOCKSIZED*/results.txt > BatchResultsMorphBLOCKSIZED.txt 52 53 ete-blocksize-both-ob-args: 54 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-0 0 55 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-0 0 56 57 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-5 5 58 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-5 5 59 60 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-10 10 61 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-10 10 62 63 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-20 20 64 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-20 20 65 66 ./EndToEndSystem.sh count-border count-borderBLOCKSIZED-at-40 40 67 ./EndToEndSystem.sh morph-border morph-borderBLOCKSIZED-at-40 40 68 69 cd image-identification-terminal/log-EndToEnd; cat count-borderBLOCKSIZED*/results.txt > BatchResultsCountBLOCKSIZED.txt 70 cd image-identification-terminal/log-EndToEnd; cat morph-borderBLOCKSIZED*/results.txt > BatchResultsMorphBLOCKSIZED.txt 1 71 #********** 2 72 #Utilities/Test … … 10 80 download-single: 11 81 ./COMPX520-RUN-PNG-hi-res.sh coo1.ark:/13960/t2t448j81 1 /.. 12 82 13 83 test-get-page-numbers-map: 14 84 cd java-gen-corpus; javac javaGenMapPageCountChecker.java … … 17 87 18 88 test-gen-new-5000-map: 19 89 #MAKE SURE TO RUN source SETUP.bash prior to this cmd 20 90 cd java-gen-corpus; javac javaGenMap5000ValidIDList.java 21 91 cd java-gen-corpus; java javaGenMap5000ValidIDList gen-500-MP-hathiFullIDList.txt gen-5000-MapList02.txt 22 92 23 93 test-gen-new-5000-local-map: 24 94 #MAKE SURE TO RUN source SETUP.bash prior to this cmd 25 95 cd java-gen-corpus; javac javaGenMapLocal5000ValidIDList.java 26 96 cd java-gen-corpus; java javaGenMapLocal5000ValidIDList MapListNumPages.txt gen-5000-Local-MapList.txt 27 28 29 run-morphology-20-test: 30 cd image-identification-terminal/log-all-hires-new/test; rm *.txt 31 cd image-identification-terminal; javac javaAccuracyCalculator.java 32 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 33 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU morphology log-all-hires-new/test/log-morphology-MU-test.txt -testNew 97 98 run-morphology-20-test-time: 99 time make run-morphology-20-test 100 run-morphology-20-test: 101 #cd image-identification-terminal/log-all-hires-new/test; rm *.txt 102 cd image-identification-terminal; javac javaAccuracyCalculator.java 103 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 104 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE morphology log-all-hires-new/test/log-morphology-SE-test.txt -testNew 34 105 cd image-identification-terminal; date >> log-all-hires-new/test/results.txt 35 106 cd image-identification-terminal; cat configClassifierComparison.properties >> log-all-hires-new/test/results.txt 36 cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/test/log-morphology- MU-test.txt morphology-MUlog-all-hires-new/test/results.txt107 cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/test/log-morphology-SE-test.txt morphology-SE log-all-hires-new/test/results.txt 37 108 cd image-identification-terminal; less log-all-hires-new/test/results.txt 38 cd image-identification-terminal; less log-all-hires-new/test/log-morphology- MU-test.txt109 cd image-identification-terminal; less log-all-hires-new/test/log-morphology-SE-test.txt 39 110 40 111 run-morph-single: … … 56 127 make hi-res-download-map 57 128 hi-res-download-map: 58 ./ FirstAndLastTest-DOWNLOADER-PNG.sh java-gen-corpus/gen-5000-Local-MapList.txt MP129 ./COMPX520-MAP-DOWNLOADER-PNG.sh MapListGen/gen-500-Local-MapList-final.txt MP 59 130 60 131 ###################################### … … 66 137 cd java-gen-corpus; java javaGenFullIDList hathiFull.txt gen-10000-MU-hathiFullIDList.txt MU 67 138 cd java-gen-corpus; java javaGenFirstAndLastTenIDList gen-10000-MU-hathiFullIDList.txt 10000 gen-10000-MU-hathiValidIDList.txt 68 139 #./FirstAndLastTest-DOWNLOADER-PNG.sh java-gen-corpus/gen-10000-MU-hathiValidIDList.txt MU 69 140 70 141 … … 79 150 80 151 run-cluster-corpus-hires: 81 82 cd image-identification-terminal; javac javaAccuracyCalculator.java 83 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 84 152 #Compile 153 cd image-identification-terminal; javac javaAccuracyCalculator.java 154 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 155 #Run classifier 85 156 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU cluster log-all-hires-new/log-cluster-MU.txt -allNew 86 157 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK cluster log-all-hires-new/log-cluster-BK.txt -allNew 87 158 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP cluster log-all-hires-new/log-cluster-MP.txt -allNew 88 159 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE cluster log-all-hires-new/log-cluster-SE.txt -allNew 89 160 #Calculate accuracy 90 161 cd image-identification-terminal; echo configClassifierComparison.properties >> log-all-hires-new/results.txt 91 162 cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/log-cluster-MU.txt cluster-MU log-all-hires-new/results.txt … … 97 168 98 169 run-count-corpus-hires: 99 100 cd image-identification-terminal; javac javaAccuracyCalculator.java 101 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 102 170 #Compile 171 cd image-identification-terminal; javac javaAccuracyCalculator.java 172 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 173 #Run classifier 103 174 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU count log-all-hires-new/log-count-MU.txt -allNew 104 175 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK count log-all-hires-new/log-count-BK.txt -allNew 105 176 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP count log-all-hires-new/log-count-MP.txt -allNew 106 177 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE count log-all-hires-new/log-count-SE.txt -allNew 107 178 #Calculate accuracy 108 179 cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/log-count-MU.txt count-MU log-all-hires-new/results.txt 109 180 cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/log-count-BK.txt count-BK log-all-hires-new/results.txt … … 115 186 #Cluster and Count 116 187 run-combo-corpus-hires: 117 118 cd image-identification-terminal; javac javaAccuracyCalculator.java 119 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 120 188 #Compile 189 cd image-identification-terminal; javac javaAccuracyCalculator.java 190 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; 191 #Run classifier 121 192 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MU combo log-all-hires-new/log-combo-MU.txt -allNew 122 193 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/BK combo log-all-hires-new/log-combo-BK.txt -allNew 123 194 #cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/MP combo log-all-hires-new/log-combo-MP.txt -allNew 124 195 cd image-identification-terminal; ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/hires-download-images/SE combo log-all-hires-new/log-combo-SE.txt -allNew 125 196 #Calculate accuracy 126 197 cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/log-combo-MU.txt combo-MU log-all-hires-new/results.txt 127 198 cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/log-combo-BK.txt combo-BK log-all-hires-new/results.txt 128 199 #cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/log-combo-MP.txt combo-MP log-all-hires-new/results.txt 129 200 cd image-identification-terminal; java javaAccuracyCalculator log-all-hires-new/log-combo-SE.txt combo-SE log-all-hires-new/results.txt 130 201 #Display the results … … 150 221 #************** 151 222 run-houghlinesP-refined-corpus: 152 223 #cd image-identification-terminal; cd log-all; rm *.txt 153 224 #Compile 154 225 cd image-identification-terminal; javac javaAccuracyCalculator.java … … 184 255 #Display the results 185 256 cd image-identification-terminal; less log-all-hires/results.txt 186 257 187 258 #*********** 188 259 #OLDGEN 189 260 #*********** 190 261 #MUSIC, Including Sheet music 191 262 gen-500-MU: 192 263 cd java-gen-corpus; javac *.java -
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/.idea/workspace.xml
r33458 r33589 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=" 557">18 <caret line="7 79" column="12" selection-start-line="779" selection-start-column="12" selection-end-line="779" selection-end-column="12" />17 <state relative-caret-position="2014"> 18 <caret line="760" selection-start-line="760" selection-end-line="760" /> 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=" 383">43 <caret line=" 236" column="54" selection-start-line="236" selection-start-column="54" selection-end-line="236" selection-end-column="54" />42 <state relative-caret-position="106"> 43 <caret line="1351" column="52" selection-start-line="1351" selection-start-column="52" selection-end-line="1351" selection-end-column="52" /> 44 44 <folding> 45 45 <element signature="imports" expanded="true" /> 46 46 <element signature="method#imageViewer#0;class#MainMorph#0" /> 47 <element signature="e#14232#16729#1" />48 <element signature="e#16814#18826#1" />49 <element signature="e#18895#21536#1" />50 <element signature="e#21620#27308#1" />51 <element signature="e#27393#31396#1" />52 <element signature="e#31464#32641#1" />53 <element signature="e#32710#36690#1" />54 <element signature="e#36800#48520#1" />55 <element signature="e#45567#45616#0" />56 <element signature="e#48614#59515#1" />57 <element signature="e#59847#68195#1" />58 <element signature="e#61117#61159#0" />59 47 </folding> 60 48 </state> … … 65 53 <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java"> 66 54 <provider selected="true" editor-type-id="text-editor"> 67 <state relative-caret-position=" 225">68 <caret line=" 592" column="12" selection-start-line="592" selection-start-column="12" selection-end-line="592" selection-end-column="12" />55 <state relative-caret-position="6897"> 56 <caret line="442" column="23" selection-start-line="442" selection-start-column="23" selection-end-line="442" selection-end-column="23" /> 69 57 <folding> 70 58 <element signature="imports" expanded="true" /> 71 <element signature="method#init#0;class#javaClassifierComparison#0" />72 59 <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" /> 73 60 <element signature="class#Pair#0;class#javaClassifierComparison#0" /> 74 <element signature="method#main#0;class#javaClassifierComparison#0" /> 75 <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" /> 76 <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" /> 77 <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" /> 78 <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" /> 61 <element signature="method#init#0;class#javaClassifierComparison#0" /> 79 62 <element signature="method#Classifier_LineCounter#0;class#javaClassifierComparison#0" /> 80 63 <element signature="method#Classifier_ClusterDetection#0;class#javaClassifierComparison#0" /> … … 83 66 <element signature="method#lineComparison#0;class#javaClassifierComparison#0" /> 84 67 <element signature="method#ClusterCheck#0;class#javaClassifierComparison#0" /> 68 <element signature="method#Algorithm_MorphologyOLD2#0;class#javaClassifierComparison#0" /> 69 <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" /> 85 70 </folding> 86 71 </state> … … 102 87 <find>FILLED</find> 103 88 <find>test</find> 89 <find>binarized</find> 90 <find>THRESHOLD_C</find> 104 91 </findStrings> 105 92 </component> … … 109 96 <option value="$PROJECT_DIR$/../image-identification-terminal/javaImageClassifier.java" /> 110 97 <option value="$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison" /> 98 <option value="$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java" /> 111 99 <option value="$PROJECT_DIR$/image-identification-development/src/Main.java" /> 112 <option value="$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java" />113 100 <option value="$PROJECT_DIR$/image-identification-development/src/MainMorph.java" /> 114 101 </list> … … 191 178 <window_info anchor="bottom" id="Message" order="0" /> 192 179 <window_info anchor="bottom" id="Find" order="1" weight="0.32962137" /> 193 <window_info anchor="bottom" id="Run" order="2" weight="0. 42316258" />180 <window_info anchor="bottom" id="Run" order="2" weight="0.2037862" /> 194 181 <window_info anchor="bottom" id="Debug" order="3" weight="0.3997773" /> 195 182 <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> … … 207 194 <window_info anchor="right" id="Maven" order="5" weight="0.3299298" /> 208 195 </layout> 196 <layout-to-restore> 197 <window_info content_ui="combo" id="Project" order="0" weight="0.19783024" /> 198 <window_info id="Structure" order="1" side_tool="true" weight="0.25" /> 199 <window_info id="Designer" order="2" /> 200 <window_info id="UI Designer" order="3" /> 201 <window_info id="Favorites" order="4" side_tool="true" /> 202 <window_info anchor="bottom" id="Message" order="0" /> 203 <window_info anchor="bottom" id="Find" order="1" weight="0.32962137" /> 204 <window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.42316258" /> 205 <window_info anchor="bottom" id="Debug" order="3" weight="0.3997773" /> 206 <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> 207 <window_info anchor="bottom" id="Inspection" order="5" weight="0.4" /> 208 <window_info anchor="bottom" id="TODO" order="6" /> 209 <window_info anchor="bottom" id="Version Control" order="7" /> 210 <window_info anchor="bottom" id="Terminal" order="8" weight="0.32962137" /> 211 <window_info anchor="bottom" id="Event Log" order="9" side_tool="true" weight="0.32962137" /> 212 <window_info anchor="bottom" id="Messages" order="10" weight="0.32962137" /> 213 <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" /> 214 <window_info anchor="right" id="Ant Build" order="1" weight="0.24952137" /> 215 <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" /> 216 <window_info anchor="right" id="Palette" order="3" /> 217 <window_info anchor="right" id="Palette	" order="4" /> 218 <window_info anchor="right" id="Maven" order="5" weight="0.3299298" /> 219 </layout-to-restore> 209 220 </component> 210 221 <component name="antWorkspaceConfiguration"> … … 238 249 <entry file="file://$PROJECT_DIR$/image-identification-development/src/Main.java"> 239 250 <provider selected="true" editor-type-id="text-editor"> 240 <state relative-caret-position=" 557">241 <caret line="7 79" column="12" selection-start-line="779" selection-start-column="12" selection-end-line="779" selection-end-column="12" />251 <state relative-caret-position="2014"> 252 <caret line="760" selection-start-line="760" selection-end-line="760" /> 242 253 <folding> 243 254 <element signature="imports" expanded="true" /> … … 261 272 <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java"> 262 273 <provider selected="true" editor-type-id="text-editor"> 263 <state relative-caret-position=" 225">264 <caret line=" 592" column="12" selection-start-line="592" selection-start-column="12" selection-end-line="592" selection-end-column="12" />274 <state relative-caret-position="6897"> 275 <caret line="442" column="23" selection-start-line="442" selection-start-column="23" selection-end-line="442" selection-end-column="23" /> 265 276 <folding> 266 277 <element signature="imports" expanded="true" /> 267 <element signature="method#init#0;class#javaClassifierComparison#0" />268 278 <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" /> 269 279 <element signature="class#Pair#0;class#javaClassifierComparison#0" /> 270 <element signature="method#main#0;class#javaClassifierComparison#0" /> 271 <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" /> 272 <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" /> 273 <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" /> 274 <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" /> 280 <element signature="method#init#0;class#javaClassifierComparison#0" /> 275 281 <element signature="method#Classifier_LineCounter#0;class#javaClassifierComparison#0" /> 276 282 <element signature="method#Classifier_ClusterDetection#0;class#javaClassifierComparison#0" /> … … 279 285 <element signature="method#lineComparison#0;class#javaClassifierComparison#0" /> 280 286 <element signature="method#ClusterCheck#0;class#javaClassifierComparison#0" /> 287 <element signature="method#Algorithm_MorphologyOLD2#0;class#javaClassifierComparison#0" /> 288 <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" /> 281 289 </folding> 282 290 </state> … … 285 293 <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java"> 286 294 <provider selected="true" editor-type-id="text-editor"> 287 <state relative-caret-position=" 383">288 <caret line=" 236" column="54" selection-start-line="236" selection-start-column="54" selection-end-line="236" selection-end-column="54" />295 <state relative-caret-position="106"> 296 <caret line="1351" column="52" selection-start-line="1351" selection-start-column="52" selection-end-line="1351" selection-end-column="52" /> 289 297 <folding> 290 298 <element signature="imports" expanded="true" /> 291 299 <element signature="method#imageViewer#0;class#MainMorph#0" /> 292 <element signature="e#14232#16729#1" />293 <element signature="e#16814#18826#1" />294 <element signature="e#18895#21536#1" />295 <element signature="e#21620#27308#1" />296 <element signature="e#27393#31396#1" />297 <element signature="e#31464#32641#1" />298 <element signature="e#32710#36690#1" />299 <element signature="e#36800#48520#1" />300 <element signature="e#45567#45616#0" />301 <element signature="e#48614#59515#1" />302 <element signature="e#59847#68195#1" />303 <element signature="e#61117#61159#0" />304 300 </folding> 305 301 </state> -
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/image-identification-development/src/Main.java
r33455 r33589 111 111 static int STANDARD_DEVIATION_THRESHOLD = 6; 112 112 static int MINLINECOUNT = 40; 113 static int MAXLINEGAP = 1; //4113 static int MAXLINEGAP = 1; 114 114 static double THRESHOLD_C = 4; 115 115 static double SLOPEGRADIENT = 0.02; //0.02 … … 757 757 //!!!!!!!!!!!!!!!!!!!!!!!!!!!NOTNOT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 758 758 //coo.31924062612282-9.png 8 lines 759 //String default_file = hiresDirectory+ "MU/SheetMusic/mdp.39015096400919-9.png"; 759 String default_file = hiresDirectory+ "MU/SheetMusic/mdp.39015096400919-9.png"; 760 //String default_file = hiresDirectory+ "MU/SheetMusic/coo.31924062612282-9.png"; 760 761 761 762 //String default_file = hiresDirectory+ "MU/SheetMusic/mdp.39015096402204-2.png"; … … 778 779 //String default_file = "TestImages/SheetMusic01.png"; 779 780 //String default_file = "TestImages/SheetMusic02.png"; 780 String default_file = "TestImages/vLine.png";781 //String default_file = "TestImages/vLine.png"; 781 782 String filename = ((args.length > 0) ? args[0] : default_file); 782 783 File file = new File(filename); … … 791 792 // Edge detection 792 793 793 Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 1 5, THRESHOLD_C);794 Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 1001, THRESHOLD_C); 794 795 //TEST PARAMETERSImgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 531,1); 795 796 796 797 797 798 // //IGNORE BORDERS OF IMAGE (using crop) 798 // Imgproc.adaptiveThreshold(original, mid,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 1 5, 2);799 // Imgproc.adaptiveThreshold(original, mid,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 1001, 2); 799 800 // double maxX = mid.size().width; 800 801 // double maxY = mid.size().height; 801 // Point cp1 = new Point(maxX/ 10, maxY/10);802 // Point cp1 = new Point(maxX/5, maxY/5); 802 803 // Point cp2 = new Point(maxX - cp1.x, maxY -cp1.y); 803 804 // Rect rectCrop = new Rect(cp1, cp2); 804 805 // edgesDetected = mid.submat(rectCrop); 805 806 806 807 // System.out.println("Width: " + edgesDetected.width() + " Height: " + edgesDetected.height()); 807 808 //****************MORPHOLOGY**************************************************************************************** 808 809 //ADDIOTIONAL FILTERING TO STOP STREAKS … … 833 834 834 835 double minLineLength = edgesDetectedRGB.size().width/8; 835 836 imwrite("houghtest-bin.jpg", edgesDetectedRGB); 836 837 Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 720, HOUGHLINEP_THRESHOLD, minLineLength,MAXLINEGAP); // runs the actual detection 837 838 //System.out.println("Before Gradient Filtering num lines: " + linesP.rows()); … … 856 857 //File filenameTest = new File("TestImages/NotSheetMusic02.png"); 857 858 //BufferedImage i = ImageIO.read(filenameTest); 858 BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB);859 //BufferedImage toBeClassifiedImg = toBufferedImage(edgesDetectedRGB); 859 860 860 861 861 862 //Display Results 863 864 imwrite("houghtest-lines.jpg", edgesDetectedRGB); 862 865 //HighGui.imshow("Source", original); 863 866 //HighGui.imshow("Just Edges", justEdges); //TESTING 864 867 865 866 HighGui.imshow("LINESFOUND", edgesDetectedRGB); 867 HighGui.resizeWindow("LINESFOUND", 1000,1000); 868 869 HighGui.imshow("CLUSTERSFOUND", clustersFoundRGB); 870 HighGui.resizeWindow("CLUSTERSFOUND", 1000,1000); 868 // HighGui.namedWindow("LINESFOUND", HighGui.WINDOW_AUTOSIZE); 869 // HighGui.imshow("LINESFOUND", edgesDetectedRGB); 870 // HighGui.resizeWindow("LINESFOUND", 1000,1000); 871 // 872 // 873 // HighGui.imshow("CLUSTERSFOUND", clustersFoundRGB); 874 // HighGui.namedWindow("CLUSTERSFOUND", HighGui.WINDOW_AUTOSIZE); 875 // HighGui.resizeWindow("CLUSTERSFOUND", 1000,1000); 871 876 872 877 //HighGui.imshow("Detected Lines (in red) - negative", edgesDetectedRGBProb); … … 874 879 System.out.println("LINE COUNT RESULT: " + ClassifierLineCount(horizontalLineCount) + '\t' +"LinesFound: " + horizontalLineCount); //COUNT OF LINES CLASSIFICATION 875 880 //System.out.println("LINE CLUSTER RESULT: " + ClassifierLineClusterOLD(toBeClassifiedImg).get(0) + '\t' + "LinesFound: " + ClassifierLineClusterOLD(toBeClassifiedImg).get(1) + '\t' + "ClustersFound: " + ClassifierLineClusterOLD(toBeClassifiedImg).get(2)); 876 System.out.println("NEW CLUSTER RESULTS: " + ClassifierLineClusterPt(pointArrayList,clustersFoundRGB).get(0) + '\t' + "LinesFound: " + horizontalLineCount + '\t' + "ClustersFound: " + ClassifierLineClusterPt(pointArrayList,clustersFoundRGB).get(1));881 //System.out.println("NEW CLUSTER RESULTS: " + ClassifierLineClusterPt(pointArrayList,clustersFoundRGB).get(0) + '\t' + "LinesFound: " + horizontalLineCount + '\t' + "ClustersFound: " + ClassifierLineClusterPt(pointArrayList,clustersFoundRGB).get(1)); 877 882 //System.out.println(ClassifierLineClusterPt(pointArrayList, clustersFoundRGB)); 878 883 … … 880 885 881 886 // Wait and Exit 882 HighGui.waitKey();887 //HighGui.waitKey(); 883 888 System.exit(0); 884 889 } -
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/image-identification-development/src/MainMorph.java
r33458 r33589 66 66 67 67 import static org.opencv.core.Core.FILLED; 68 import static org.opencv.core.Core.calcCovarMatrix; 68 69 import static org.opencv.core.CvType.CV_8UC3; 69 70 import static org.opencv.highgui.HighGui.createJFrame; … … 193 194 //Variables 194 195 System.out.println("Running Code version: " + CODE_VERSION + " Image Version: " +IMAGE_VERSION); 195 Mat mid = new Mat();196 196 Mat edgesDetectedRGB = new Mat(); 197 197 Mat clustersFoundRGB = new Mat(); … … 209 209 //String default_file =hiresDirectory+"BK/NotSheetMusic/aeu.ark+=13960=t2q53nq6w-6.png"; 210 210 //String default_file =hiresDirectory+"BK/NotSheetMusic/aeu.ark+=13960=t9z03w65z-4.png"; 211 //String default_file =hiresDirectory+"BK/NotSheetMusic/loc.ark+=13960=t50g4443d-5.png"; 211 212 //String default_file =hiresDirectory+"MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-1.png"; 212 213 //String default_file =hiresDirectory+"MU/SheetMusic/emu.010001066823-9.png"; … … 234 235 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-1.png"; //Image evaluation 235 236 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-2.png"; //large numbers 237 //String default_file = hiresDirectory+ "MU/SheetMusic/mdp.39015096400919-9.png"; 236 238 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-3.png"; 237 String default_file = hiresDirectory+"/MU/SheetMusic/mdp.39015080921409-9.png";239 //String default_file = hiresDirectory+"/MU/SheetMusic/mdp.39015080921409-9.png"; 238 240 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-4.png"; 239 241 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-5.png"; … … 242 244 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-8.png"; 243 245 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-9.png"; 246 String default_file = hiresDirectory+"/MU/SheetMusic/mdp.39015096398899-4.png"; 244 247 245 248 … … 260 263 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 261 264 System.out.println("Width: " + original.width() + " Height: " + original.height()); 262 Mat binarized Original= original.clone();265 Mat binarized = original.clone(); 263 266 264 Imgproc.adaptiveThreshold(original, binarizedOriginal,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C);267 //Imgproc.adaptiveThreshold(original, binarized,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 265 268 //TEST PARAMETERSImgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 531,1); 266 269 //Imgproc.threshold(original,original, 127, 255, Imgproc.THRESH_BINARY); 267 270 //************************ 271 //Argument Setup 272 //************************ 273 int tempvariable = 0; 274 if (tempvariable ==1){ 275 Imgproc.adaptiveThreshold(original, binarized, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY_INV, 1001, 5); 276 } 277 else { 278 279 int borderIgnoreAmount = 0; 280 double divisor; 281 switch (borderIgnoreAmount) { 282 case 5: 283 divisor = 40; 284 break; 285 case 10: 286 divisor = 20; 287 break; 288 case 20: 289 divisor = 10; 290 break; 291 case 40: 292 divisor = 5; 293 break; 294 case 0: 295 divisor = -1; 296 break; 297 default: 298 divisor = -1; 299 } 300 if (divisor != -1) { 301 Mat mid = new Mat(); 302 Imgproc.adaptiveThreshold(original, mid, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 303 double maxX = mid.size().width; 304 double maxY = mid.size().height; 305 Point cp1 = new Point(maxX / divisor, maxY / divisor); 306 Point cp2 = new Point(maxX - cp1.x, maxY - cp1.y); 307 Rect rectCrop = new Rect(cp1, cp2); 308 binarized = mid.submat(rectCrop); 309 } else { 310 Imgproc.adaptiveThreshold(original, binarized, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 311 } 312 313 System.out.println("Width: " + binarized.width() + " Height: " + binarized.height()); 314 } 268 315 269 316 //****************MORPHOLOGY**************************************************************************************** … … 276 323 //dynamic morphology?? 277 324 if(CODE_VERSION == 1) { 278 int hori = binarized Original.width();279 int vert = binarized Original.height();325 int hori = binarized.width(); 326 int vert = binarized.height(); 280 327 //Find ratio between 100 and width and 100 and height 281 328 int divX = hori/10; … … 284 331 int sizeY = (vert/divY) * 10; 285 332 286 Mat test = binarized Original.clone();333 Mat test = binarized.clone(); 287 334 imageViewer("Original", test); 288 335 … … 326 373 327 374 //MAKE SURE BLACK & WHITE 328 Mat test = binarized Original.clone();375 Mat test = binarized.clone(); 329 376 imageViewer("00 Binarized Original", test); 330 377 … … 366 413 //Tutorial/Demo Code 367 414 if (CODE_VERSION == 3) { 368 Mat horizontal = binarized Original.clone();369 Mat vertical = binarized Original.clone();415 Mat horizontal = binarized.clone(); 416 Mat vertical = binarized.clone(); 370 417 // Specify size on horizontal axis 371 418 int horizontal_size = horizontal.cols() / 50; … … 420 467 imageViewer("original", original); 421 468 422 Mat test = binarized Original.clone();423 Mat pre = binarized Original.clone();469 Mat test = binarized.clone(); 470 Mat pre = binarized.clone(); 424 471 Mat dst = new Mat(); 425 472 … … 534 581 //Better morphology attempt - dynamic 535 582 if(CODE_VERSION == 5) { 536 int hori = binarized Original.width();537 int vert = binarized Original.height();583 int hori = binarized.width(); 584 int vert = binarized.height(); 538 585 //Find ratio between 100 and width and 100 and height 539 586 int sizeX100 = 10 * (hori/68); … … 551 598 imageViewer("original", original); 552 599 553 Mat test = binarized Original.clone();600 Mat test = binarized.clone(); 554 601 imageViewer("00 Inverse Binarized Original", test); 555 602 … … 643 690 imageViewer("original", original); 644 691 645 Mat src = binarized Original.clone();646 Mat test = binarized Original.clone();692 Mat src = binarized.clone(); 693 Mat test = binarized.clone(); 647 694 Mat mask = new Mat(); 648 695 Mat dst = new Mat(); … … 729 776 imageViewer("original", original); 730 777 731 Mat test = binarized Original.clone();778 Mat test = binarized.clone(); 732 779 733 780 … … 738 785 //Large Object Removal 739 786 //************************************ 740 Mat srcLOR = binarized Original.clone();787 Mat srcLOR = binarized.clone(); 741 788 Mat maskLOR = new Mat(); 742 789 Mat dstLOR = new Mat(); … … 968 1015 //Imgproc.adaptiveThreshold(original1, original,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 969 1016 970 Mat test = binarized Original.clone();1017 Mat test = binarized.clone(); 971 1018 //************************************ 972 1019 //Large Object Removal 973 1020 //************************************ 974 Mat srcLOR = binarized Original.clone();1021 Mat srcLOR = binarized.clone(); 975 1022 Mat maskLOR = new Mat(); 976 1023 Mat dstLOR = new Mat(); … … 1158 1205 //Reset after david chat 1159 1206 if(CODE_VERSION == 9){ 1207 int areaCounter=0; 1160 1208 //Display Original 1161 1209 imageViewer("original", original); 1162 imageViewer("000 Inverse Binarized Original", binarized Original);1210 imageViewer("000 Inverse Binarized Original", binarized); 1163 1211 1164 1212 … … 1166 1214 //1. Large Object Remover 1167 1215 //************************************ 1168 Mat srcLOR = binarized Original.clone();1216 Mat srcLOR = binarized.clone(); 1169 1217 Mat maskLOR = new Mat(); 1170 1218 Mat dstLOR = new Mat(); … … 1176 1224 1177 1225 //Heal the large items 1178 Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(25,25)); 1226 Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(25,25)); //5,5 1179 1227 Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_CLOSE, healLOR); 1180 1228 imageViewer("002 heal objects in mask", maskLOR); 1181 1229 1182 1230 //IsolateLarge 1183 Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30)); 1231 Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30)); //8,8 1184 1232 Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_OPEN, isolateLargeLOR); 1185 1233 imageViewer("003 Isolate large", maskLOR); … … 1254 1302 1255 1303 //4. Classify like line clusters. 1256 Mat base = binarized Original.clone();1304 Mat base = binarized.clone(); 1257 1305 //*********************************** 1258 1306 //3. Isolate straight lines 1259 1307 //*********************************** 1260 1308 //Heal lines 1261 Mat healISL = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8 2,1));1309 Mat healISL = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(86,1)); 1262 1310 Imgproc.morphologyEx(dstLOR,base, Imgproc.MORPH_OPEN, healISL); 1263 1311 imageViewer("202 heal objects in mask", base); … … 1310 1358 System.out.println("i:"+ i + " Height: " + boundRect[i].height); 1311 1359 if(boundRect[i].width > 300){ 1360 areaCounter++; 1312 1361 System.out.println("i:"+ i + " Width: " + boundRect[i].width); 1313 1362 Imgproc.rectangle(rectOutput, boundRect[i].tl(), boundRect[i].br(), new Scalar(255, 0, 0), 20); … … 1318 1367 1319 1368 imageViewer("4000 Rect found", rectOutput); 1369 System.out.println(areaCounter); 1320 1370 1321 1371 … … 1327 1377 Pair returnVariables = new Pair(); 1328 1378 int areaCounter=0; 1379 1380 1329 1381 //Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 1330 //Mat binarizedOriginal = original.clone(); 1331 //Imgproc.adaptiveThreshold(original, binarizedOriginal,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 1382 //Mat binarized = original.clone(); 1383 //Mat mid = new Mat(); 1384 //if(borderCrop > 0){ 1385 //Imgproc.adaptiveThreshold(original, mid,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, 2); 1386 //double maxX = mid.size().width; 1387 //double maxY = mid.size().height; 1388 //Point cp1 = new Point(maxX/10, maxY/10); 1389 //Point cp2 = new Point(maxX - cp1.x, maxY -cp1.y); 1390 //Rect rectCrop = new Rect(cp1, cp2); 1391 //binarized = mid.submat(rectCrop); 1392 //} 1393 //else{ 1394 //Imgproc.adaptiveThreshold(original, binarized,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 1395 //} 1396 1397 1332 1398 try{ 1333 1399 //************************************ 1334 1400 //1. Large Object Remover 1335 1401 //************************************ 1336 Mat srcLOR = binarized Original.clone();1402 Mat srcLOR = binarized.clone(); 1337 1403 Mat maskLOR = new Mat(); 1338 1404 Mat dstLOR = new Mat(); … … 1353 1419 srcLOR.copyTo(dstLOR, maskLOR); 1354 1420 1355 Mat base = binarized Original.clone();1421 Mat base = binarized.clone(); 1356 1422 //*********************************** 1357 1423 //3. Isolate straight lines -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/Makefile
r33449 r33589 36 36 37 37 testrun-classifier-single-combo: 38 ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/ hires-download-images/MU/SheetMusic/coo.31924062612282-9.png combo logSingle.txt -singleNew38 ./runClassifer.sh /Scratch/cpb16/is-sheet-music-encore/image-identification-terminal/TestImages/SheetMusic02.png combo logSingle.txt -singleNew 40 39 39 echo "Displaying javaImageClassifier output" 40 40 #Calculate the Accuracy of the classifier -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaAccuracyCalculator.java
r33439 r33589 28 28 float falseAccuracyRate =0; 29 29 float overallAccuracyRate=0; 30 String notApplicable = "N/A"; 30 31 // 31 32 int sheetMusicCount = 0; … … 93 94 } 94 95 else if (sheetMusicCount == 0) { 96 trueAccuracyRate = -1; 95 97 overallAccuracyRate = falseAccuracyRate; 96 98 } 97 99 else if(notSheetMusicCount == 0) { 100 falseAccuracyRate = -1; 98 101 overallAccuracyRate = trueAccuracyRate; 99 102 } … … 102 105 System.out.println("There is nothing to compare"); 103 106 } 104 105 fw.write("Date: " + d.toString() + '\n' 106 + "Classifier: " + classifierType + '\n' 107 + "truePositive: " + truePositive + '\n' 108 + "falseNegative: " + falseNegative + '\n' 109 + "falsePositve: " + falsePositive + '\n' 110 + "trueNegative: " + trueNegative + '\n' 111 + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\n' 112 + "NotSheetMusicAccuracyRate: " + falseAccuracyRate + "%" + '\n' 113 + "OverallAccuracyRate: " + overallAccuracyRate + "%" + '\n' + 114 "****************************************************************" + '\n'); 107 if(falseAccuracyRate ==-1){ 108 fw.write("Date: " + d.toString() + '\n' 109 + "Classifier: " + classifierType + '\n' 110 + "truePositive: " + truePositive + '\n' 111 + "falseNegative: " + falseNegative + '\n' 112 + "falsePositve: " + falsePositive + '\n' 113 + "trueNegative: " + trueNegative + '\n' 114 + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\n' 115 + "NotSheetMusicAccuracyRate: " + notApplicable + '\n' 116 + "OverallAccuracyRate: " + overallAccuracyRate + "%" + '\n'); 117 } 118 else if(trueAccuracyRate == -1){ 119 fw.write("Date: " + d.toString() + '\n' 120 + "Classifier: " + classifierType + '\n' 121 + "truePositive: " + truePositive + '\n' 122 + "falseNegative: " + falseNegative + '\n' 123 + "falsePositve: " + falsePositive + '\n' 124 + "trueNegative: " + trueNegative + '\n' 125 + "SheetMusicAccuracyRate: " + notApplicable + '\n' 126 + "NotSheetMusicAccuracyRate: " + falseAccuracyRate + "%" + '\n' 127 + "OverallAccuracyRate: " + overallAccuracyRate + "%" + '\n'); 128 } 129 else{ 130 fw.write("Date: " + d.toString() + '\n' 131 + "Classifier: " + classifierType + '\n' 132 + "truePositive: " + truePositive + '\n' 133 + "falseNegative: " + falseNegative + '\n' 134 + "falsePositve: " + falsePositive + '\n' 135 + "trueNegative: " + trueNegative + '\n' 136 + "SheetMusicAccuracyRate: " + trueAccuracyRate + "%" + '\n' 137 + "NotSheetMusicAccuracyRate: " + falseAccuracyRate + "%" + '\n' 138 + "OverallAccuracyRate: " + overallAccuracyRate + "%" + '\n'); 139 } 115 140 buf.close(); 116 141 fw.close(); -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaClassifierComparison.java
r33458 r33589 72 72 static double THRESHOLD_AREA_COUNT; 73 73 74 //******************************************************************************************** 75 //CLASSES 76 //******************************************************************************************** 77 78 //Sets globals based off properties file 79 public static void init(){ 80 try{ 81 Properties config = new Properties(); 82 FileInputStream input = new FileInputStream("configClassifierComparison.properties"); 83 config.load(input); 84 CLASSIFIER_HOUGHLINESP_MIN = Integer.parseInt(config.getProperty("CLASSIFIER_HOUGHLINESP_MIN")); 85 CLASSIFIER_HOUGHLINESP_MAX = Integer.parseInt(config.getProperty("CLASSIFIER_HOUGHLINESP_MAX")); 86 HOUGHLINEP_THRESHOLD = Integer.parseInt(config.getProperty("HOUGHLINEP_THRESHOLD")); 87 STANDARD_DEVIATION_THRESHOLD = Integer.parseInt(config.getProperty("STANDARD_DEVIATION_THRESHOLD")); 88 MINLINECOUNT = Integer.parseInt(config.getProperty("MINLINECOUNT")); 89 MAXLINEGAP = Integer.parseInt(config.getProperty("MAXLINEGAP")); 90 THRESHOLD_C = Double.parseDouble(config.getProperty("THRESHOLD_C")); 91 SLOPEGRADIENT = Double.parseDouble(config.getProperty("SLOPEGRADIENT")); 92 CLUSTER_DISTANCE_MAX = Double.parseDouble(config.getProperty("CLUSTER_DISTANCE_MAX")); 93 CLUSTER_DISTANCE_MIN = Double.parseDouble(config.getProperty("CLUSTER_DISTANCE_MIN")); 94 THRESHOLD_AREA_SIZE = Double.parseDouble(config.getProperty("THRESHOLD_AREA_SIZE")); 95 THRESHOLD_AREA_COUNT = Double.parseDouble(config.getProperty("THRESHOLD_AREA_COUNT")); 96 } 97 catch(Exception e){ 98 e.printStackTrace(); 99 } 100 } 101 74 //****************** 75 //CLASSES 76 //****************** 102 77 static public class StartAndEndPoint { 103 78 //PRIVATES … … 161 136 } 162 137 138 //****************** 139 //TRIGGERS 140 //****************** 141 /**Sets globals based off properties file*/ 142 public static void init(){ 143 try{ 144 Properties config = new Properties(); 145 FileInputStream input = new FileInputStream("configClassifierComparison.properties"); 146 config.load(input); 147 CLASSIFIER_HOUGHLINESP_MIN = Integer.parseInt(config.getProperty("CLASSIFIER_HOUGHLINESP_MIN")); 148 CLASSIFIER_HOUGHLINESP_MAX = Integer.parseInt(config.getProperty("CLASSIFIER_HOUGHLINESP_MAX")); 149 HOUGHLINEP_THRESHOLD = Integer.parseInt(config.getProperty("HOUGHLINEP_THRESHOLD")); 150 STANDARD_DEVIATION_THRESHOLD = Integer.parseInt(config.getProperty("STANDARD_DEVIATION_THRESHOLD")); 151 MINLINECOUNT = Integer.parseInt(config.getProperty("MINLINECOUNT")); 152 MAXLINEGAP = Integer.parseInt(config.getProperty("MAXLINEGAP")); 153 THRESHOLD_C = Double.parseDouble(config.getProperty("THRESHOLD_C")); 154 SLOPEGRADIENT = Double.parseDouble(config.getProperty("SLOPEGRADIENT")); 155 CLUSTER_DISTANCE_MAX = Double.parseDouble(config.getProperty("CLUSTER_DISTANCE_MAX")); 156 CLUSTER_DISTANCE_MIN = Double.parseDouble(config.getProperty("CLUSTER_DISTANCE_MIN")); 157 THRESHOLD_AREA_SIZE = Double.parseDouble(config.getProperty("THRESHOLD_AREA_SIZE")); 158 THRESHOLD_AREA_COUNT = Double.parseDouble(config.getProperty("THRESHOLD_AREA_COUNT")); 159 } 160 catch(Exception e){ 161 e.printStackTrace(); 162 } 163 } 164 /***/ 163 165 public static void main(String[] args) { 164 166 init(); 165 167 try { 166 168 167 if (args.length !=3) {169 if (args.length < 3) { 168 170 System.out.println("Usage: imageClassifier <inputFilename> <classifierType> <outputFilename>"); 171 System.out.println("+ (Optional)<BorderIgnoreAmount[0,5, 10, 20, 40]>"); 169 172 } else { 170 173 Pair algorithmResult = new Pair(); 171 172 174 Boolean result = null; 173 175 String result_cluster = ""; … … 176 178 String outputFilename = args[2]; 177 179 Boolean enableLineClustering = null; 180 178 181 //Prep Writing output to disc 179 182 File log = new File(outputFilename); 180 183 FileWriter fileWriter = new FileWriter(log, true); 181 184 BufferedWriter bw = new BufferedWriter(fileWriter); 182 //Execute classifierType defined from arguement183 184 185 File imgCheck = new File(imageFilename); 185 186 if(!imgCheck.exists()){System.err.println("Image not found: "+ imageFilename);} 186 187 187 //Split output by tab for processing in next java program 188 //imageFilename = 1, result = 3, classifierType = 4 189 188 // 189 190 191 //Arguement Preps 192 int borderIgnoreAmount; 193 if(args.length >= 4){borderIgnoreAmount =Integer.parseInt(args[3]);} 194 else {borderIgnoreAmount=-1;} 195 196 //imageFilename = 1, result = 3, classifierType = 4 ????? 190 197 switch (classifierType) { 198 //Splits output by tab for processing in next java program 191 199 case "count": 192 200 enableLineClustering = false; 193 algorithmResult = Algorithm_HoughLinesP_Single(imageFilename, enableLineClustering );201 algorithmResult = Algorithm_HoughLinesP_Single(imageFilename, enableLineClustering, borderIgnoreAmount); 194 202 bw.write("Filename:" + '\t' + imageFilename + '\t' + "Classified as:" + '\t' + algorithmResult.getBoolean() + '\t' + "Number of lines:" + '\t' + algorithmResult.getInteger() + '\t' + classifierType + '\n'); 195 203 break; 196 204 case "cluster": 197 205 enableLineClustering = true; 198 algorithmResult = Algorithm_HoughLinesP_Single(imageFilename, enableLineClustering );206 algorithmResult = Algorithm_HoughLinesP_Single(imageFilename, enableLineClustering, borderIgnoreAmount); 199 207 bw.write("Filename:" + '\t' + imageFilename + '\t' + "Classified as:" + '\t' + algorithmResult.getBoolean() + '\t' + "Number of lines:" + '\t' + algorithmResult.getInteger() + '\t' + classifierType + '\n'); 200 208 break; 201 209 case "combo": 202 algorithmResult = Algorithm_HoughLinesP_Combo(imageFilename );210 algorithmResult = Algorithm_HoughLinesP_Combo(imageFilename, borderIgnoreAmount); 203 211 bw.write("Filename:" + '\t' + imageFilename + '\t' + "Classified as:" + '\t' + algorithmResult.getBoolean() + '\t' + "Number of lines:" + '\t' + algorithmResult.getInteger() + '\t' + classifierType + '\n'); 204 212 break; 205 213 case "morphology": 206 algorithmResult = Algorithm_Morphology(imageFilename );214 algorithmResult = Algorithm_Morphology(imageFilename, borderIgnoreAmount); 207 215 bw.write("Filename:" + '\t' + imageFilename + '\t' + "Classified as:" + '\t' + algorithmResult.getBoolean() + '\t' + "Number of areas:" + '\t' + algorithmResult.getInteger() + '\t' + classifierType + '\n'); 208 216 break; … … 210 218 System.out.println("unknown algorithm"); 211 219 break; 212 } 213 220 } 214 221 bw.close(); 215 222 } … … 222 229 //ALGORITHM FUNCTIONS 223 230 //****************** 224 private static Pair Algorithm_HoughLinesP_Single(String filename, Boolean enableLineClusterDetection){ 231 private static Pair Algorithm_HoughLinesP_Single(String filename, Boolean enableLineClusterDetection, int borderIgnoreAmount){ 232 //****************EXPLANATION************************************************** 233 // 234 //Load an image in greyscale 235 //Additional matrix to hold results of line detection 236 //Inversed Binarization of image 237 //Detect lines in image 238 //Go thru every line detected and check its gradient is less than SLOPEGRADIENT 239 // 240 //****************EXPLANATION************************************************** 225 241 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 226 242 Boolean isSheetMusic = null; … … 235 251 ArrayList<StartAndEndPoint> pointArrayList = new ArrayList<StartAndEndPoint>(); 236 252 237 //****************EXPLANATION**************************************************238 //239 //Load an image in greyscale240 //Additional matrix to hold results of line detection241 //Inversed Binarization of image242 //Detect lines in image243 //Go thru every line detected and check its gradient is less than SLOPEGRADIENT244 //245 //****************EXPLANATION**************************************************246 247 253 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 254 255 Mat binarized = original.clone(); 256 int blockSize = binarized.height()/3; 257 //BlockSize must be blockSize % 2 == 1 && blockSize > 1 258 while (!(blockSize % 2 == 1 && blockSize > 1)) { 259 blockSize++; 260 } 261 262 263 System.out.println("Width: " + binarized.width() + " Height: " + binarized.height()); 264 //************************ 265 //Argument Setup 266 //************************ 267 double divisor; 268 switch (borderIgnoreAmount){ 269 case 5: 270 divisor = 40; 271 break; 272 case 10: 273 divisor = 20; 274 break; 275 case 20: 276 divisor = 10; 277 break; 278 case 40: 279 divisor = 5; 280 break; 281 case -1: 282 divisor = -1; 283 break; 284 default: divisor = -1; 285 } 286 if(divisor != -1 ) { 287 Mat mid = new Mat(); 288 Imgproc.adaptiveThreshold(original, mid,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, blockSize, THRESHOLD_C); 289 //Remove borders from Mat 290 //Get width and 291 double maxX = mid.size().width; 292 double maxY = mid.size().height; 293 Point cp1 = new Point(maxX / divisor, maxY / divisor); 294 Point cp2 = new Point(maxX - cp1.x, maxY - cp1.y); 295 Rect rectCrop = new Rect(cp1, cp2); 296 binarized = mid.submat(rectCrop); 297 } 298 else{Imgproc.adaptiveThreshold(original, binarized,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, blockSize, THRESHOLD_C);} 299 System.out.println("Width: " + binarized.width() + " Height: " + binarized.height()); 300 edgesDetected = binarized.clone(); 301 302 248 303 Mat linesP = new Mat(); //will hold the results of the detection 249 Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV,15, THRESHOLD_C);250 304 double minLineLength = edgesDetected.size().width/8; 251 305 Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 720, HOUGHLINEP_THRESHOLD, minLineLength, MAXLINEGAP); … … 274 328 return returnVariables; 275 329 } 276 private static Pair Algorithm_HoughLinesP_Combo(String filename){ 330 private static Pair Algorithm_HoughLinesP_Combo(String filename, int borderIgnoreAmount){ 331 //****************EXPLANATION************************************************** 332 // 333 //Load an image in greyscale 334 //Additional matrix to hold results of line detection 335 //Inversed Binarization of image 336 //Detect lines in image 337 //Go thru every line detected and check its gradient is less than SLOPEGRADIENT 338 // 339 //****************EXPLANATION************************************************** 340 277 341 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 278 342 Boolean isSheetMusic = null; … … 281 345 //Variables 282 346 int horizontalLineCount =0; 347 283 348 Mat edgesDetected = new Mat(); 284 349 Mat edgesDetectedRGB = new Mat(); … … 286 351 Mat edgesDetectedRGBProb; 287 352 ArrayList<StartAndEndPoint> pointArrayList = new ArrayList<StartAndEndPoint>(); 288 289 //****************EXPLANATION**************************************************290 //291 //Load an image in greyscale292 //Additional matrix to hold results of line detection293 //Inversed Binarization of image294 //Detect lines in image295 //Go thru every line detected and check its gradient is less than SLOPEGRADIENT296 //297 //****************EXPLANATION**************************************************298 299 353 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 354 355 Mat binarized = original.clone(); 356 int blockSize = binarized.height()/3; 357 while (!(blockSize % 2 == 1 && blockSize > 1)) { 358 blockSize++; 359 } 360 System.out.println("Width: " + binarized.width() + " Height: " + binarized.height()); 361 //************************ 362 //Argument Setup 363 //************************ 364 double divisor; 365 switch (borderIgnoreAmount){ 366 case 5: 367 divisor = 40; 368 break; 369 case 10: 370 divisor = 20; 371 break; 372 case 20: 373 divisor = 10; 374 break; 375 case 40: 376 divisor = 5; 377 break; 378 case -1: 379 divisor = -1; 380 break; 381 default: divisor = -1; 382 } 383 if(divisor != -1 ) { 384 Mat mid = new Mat(); 385 Imgproc.adaptiveThreshold(original, mid,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, blockSize, THRESHOLD_C); 386 //Remove borders from Mat 387 //Get width and 388 double maxX = mid.size().width; 389 double maxY = mid.size().height; 390 Point cp1 = new Point(maxX / divisor, maxY / divisor); 391 Point cp2 = new Point(maxX - cp1.x, maxY - cp1.y); 392 Rect rectCrop = new Rect(cp1, cp2); 393 binarized = mid.submat(rectCrop); 394 } 395 else{Imgproc.adaptiveThreshold(original, binarized,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, blockSize, THRESHOLD_C);} 396 System.out.println("Width: " + binarized.width() + " Height: " + binarized.height()); 397 edgesDetected = binarized.clone(); 398 300 399 Mat linesP = new Mat(); //will hold the results of the detection 301 Imgproc.adaptiveThreshold(original, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV,15, THRESHOLD_C);302 400 double minLineLength = edgesDetected.size().width/8; 303 401 Imgproc.HoughLinesP(edgesDetected, linesP, 1, Math.PI / 720, HOUGHLINEP_THRESHOLD, minLineLength, MAXLINEGAP); … … 320 418 } 321 419 else if (isSheetMusic == false){ 420 System.out.println("TEST"); 322 421 returnVariables = Classifier_ClusterDetection(pointArrayList); 323 422 } … … 328 427 return returnVariables; 329 428 } 330 private static Pair Algorithm_MorphologyOLD2(String filename){ 331 429 private static Pair Algorithm_Morphology(String filename, int borderIgnoreAmount){ 332 430 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 333 Boolean isSheetMusic = null;334 431 Pair returnVariables = new Pair(); 335 432 int areaCounter = 0; 336 try{337 Mat edgesDetectedRGB = new Mat();338 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);339 340 System.out.println("Width: " + original.width() + " Height: " + original.height());341 342 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();343 Mat hierarchy = new Mat();344 345 //Thresholds346 Imgproc.adaptiveThreshold(original, original,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C);347 Mat processed = original.clone();348 //Morphological Processing349 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,1));350 Imgproc.erode(processed,processed,kernelErode);351 352 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,3));353 Imgproc.dilate(processed,processed,kernelDilate);354 355 Mat kernelOpening = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4));356 Imgproc.morphologyEx(processed, processed, Imgproc.MORPH_CLOSE, kernelOpening);357 358 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8,8));359 Imgproc.erode(processed,processed,kernelErode02);360 361 //Detect contours362 Imgproc.findContours(processed, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);363 364 //Record areas365 for (int i = 0; i < contours.size(); i++) {366 double area = Imgproc.contourArea(contours.get(i));367 System.out.println("AREA: " + area);368 //Check if area detected meets threshold369 if(area > THRESHOLD_AREA_SIZE) {370 areaCounter++;371 372 }373 }374 System.out.println("areacount = " + areaCounter);375 376 //Calculates if sheet music or not377 if(areaCounter >= THRESHOLD_AREA_COUNT){378 isSheetMusic = true;379 returnVariables.setBoolean(isSheetMusic);380 returnVariables.setInteger(areaCounter);381 }382 }383 catch(Exception e){384 System.err.println(e);385 }386 return returnVariables;387 }388 private static Pair Algorithm_MorphologyOLD(String filename){389 390 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);391 Boolean isSheetMusic = null;392 Pair returnVariables = new Pair();393 int FILLED = -1;394 try{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);399 Mat test = original.clone();400 //************************************401 //Large Object Removal402 //************************************403 Mat srcLOR = original.clone();404 Mat maskLOR = new Mat();405 Mat dstLOR = new Mat();406 407 //denoize408 Mat denoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));409 Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, denoize);410 411 //close up gaps412 Mat gapCloser = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5));413 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_CLOSE, gapCloser);414 415 //Isolate large items416 Mat isolateLarge = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8, 8));417 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_OPEN, isolateLarge);418 419 //Remove large items from image420 Core.bitwise_not(maskLOR,maskLOR);421 srcLOR.copyTo(dstLOR, maskLOR);422 423 //****************************************424 //Small object removal (SOR)425 //****************************************426 427 Mat srcSOR = dstLOR.clone();428 Mat maskSOR = new Mat();429 Mat dstSOR = new Mat();430 431 Mat startSOR =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7));432 Imgproc.morphologyEx(srcSOR,maskSOR, Imgproc.MORPH_OPEN, startSOR);433 434 Mat highlightSmall = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7));435 Imgproc.dilate(maskSOR, maskSOR, highlightSmall);436 437 438 /* Mat isolateSmall =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10));439 Imgproc.morphologyEx(maskSOR,maskSOR,Imgproc.MORPH_CLOSE, isolateSmall);440 imageViewer("13 isolate small - mask", maskSOR);441 */442 443 //Remove small items from image444 Core.bitwise_not(maskSOR, maskSOR);445 srcSOR.copyTo(dstSOR, maskSOR);446 447 448 //****************************************449 //start staff line detection450 //****************************************451 452 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15,2)); //10,2453 Imgproc.erode(dstSOR,test,kernelErode);454 455 456 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //20,3457 Imgproc.dilate(test,test,kernelDilate);458 459 460 Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4461 Imgproc.morphologyEx(test, test, Imgproc.MORPH_CLOSE, kernelClose);462 463 464 465 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //10,1466 Imgproc.erode(test,test,kernelErode02);467 468 469 //********************************************************************************470 //DETECT OUTLINE AND FIND AREA OF THESE LINES.471 //********************************************************************************472 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>();473 ArrayList<MatOfPoint> largeContours = new ArrayList<MatOfPoint>();474 ArrayList<MatOfPoint> postContours = new ArrayList<MatOfPoint>();475 Mat hierarchy = new Mat();476 477 //PARAMETERS: input image, output array of arrays, output array, contour retrieval mode, contour approximation method.478 //(contours) output array of arrays: Detected contours. Each contour is stored as a vector of points479 //(hierarchy) output array: Optional output vector, containing information about the image topology.480 //https://docs.opencv.org/3.3.1/d3/dc0/group__imgproc__shape.html#ga17ed9f5d79ae97bd4c7cf18403e1689a481 482 Imgproc.findContours(test, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);483 484 System.out.println(contours.size());485 //Draw contours and record areas486 Mat allContoursFound = Mat.zeros(test.size(), CvType.CV_8UC3);487 Mat largeContoursFound = allContoursFound.clone() ;488 Mat postContoursFound = allContoursFound.clone();489 int areaCounter = 0;490 491 //Have created a preprocess to remove large objects.492 //Need to now finalized Classifier, re try area detection.493 //Paths to take - rectangle boxes around detected contours over threshold (area or perimeter)494 //Just use area and periemter to determine if sheet music495 //Discuss with david before weekend perhaps?496 497 Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8498 for (int i = 0; i < contours.size(); i++) {499 double area = Imgproc.contourArea(contours.get(i));500 if(area > 100) {501 //System.out.println("AREA: " + area);502 Imgproc.drawContours(largeContoursFound, contours, i, new Scalar(255, 0, 0), FILLED);503 //create list of large coutours found504 largeContours.add(contours.get(i));505 }506 }507 508 //*****************************************************************509 //Circles and centres on processed images510 //*****************************************************************511 512 //Init arrays513 Mat circleOutput = allContoursFound.clone();514 MatOfPoint2f[] contoursPoly = new MatOfPoint2f[largeContours.size()];515 Point[] centers = new Point[largeContours.size()];516 float[][] radius = new float[largeContours.size()][1];517 518 //Fill arrays519 for (int i = 0; i < largeContours.size(); i++) {520 contoursPoly[i] = new MatOfPoint2f();521 Imgproc.approxPolyDP(new MatOfPoint2f(largeContours.get(i).toArray()), contoursPoly[i], 1, true);522 centers[i] = new Point();523 Imgproc.minEnclosingCircle(contoursPoly[i], centers[i], radius[i]);524 525 }526 //Draw circle for each large contour527 for (int i = 0; i < largeContours.size(); i++) {528 Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1);529 }530 531 532 //********************************************************************************533 //Centroids - Everything must be to scale534 //********************************************************************************535 536 ArrayList<Moments> mu = new ArrayList<Moments>(largeContours.size());537 Mat centreOutput = Mat.zeros(largeContoursFound.size(), CvType.CV_8UC3);538 for (int i = 0; i < largeContours.size(); i++) {539 mu.add(i, Imgproc.moments(largeContours.get(i), false));540 Moments p = mu.get(i);541 int x = (int) (p.get_m10() / p.get_m00());542 int y = (int) (p.get_m01() / p.get_m00());543 Imgproc.circle(centreOutput, new Point(x, y), 4, new Scalar(255, 255, 255), 30);544 }545 546 //***********************************************547 //PostProcessing - Morphology Classifier548 // Use dilation to "Connect the dots"549 // Testing showed the centroids were clustered together550 // Then use area or perimeter as a classifier filter551 //***********************************************552 553 Mat postDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(150,15));554 Imgproc.dilate(centreOutput,centreOutput,postDilate);555 556 Mat postClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4557 Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_CLOSE, postClose);558 559 Mat postDenoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,100));560 Imgproc.morphologyEx(centreOutput,centreOutput, Imgproc.MORPH_OPEN, postDenoize);561 562 //Find area563 Mat centreOutputGrey = new Mat();564 Imgproc.cvtColor(centreOutput, centreOutputGrey, Imgproc.COLOR_RGB2GRAY);565 Imgproc.findContours(centreOutputGrey, postContours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);566 567 for (int i = 0; i < postContours.size(); i++) {568 double area = Imgproc.contourArea(postContours.get(i));569 if(area > THRESHOLD_AREA_SIZE) {570 //System.err.println("POST AREA: " + area);571 Imgproc.drawContours(postContoursFound, postContours, i, new Scalar(0, 255, 0), FILLED);572 areaCounter++;573 }574 }575 //Classifier Calculation576 if(areaCounter >= THRESHOLD_AREA_COUNT){577 returnVariables.setBoolean(true);578 returnVariables.setInteger(areaCounter);579 }580 }581 catch(Exception e){582 System.err.println(e);583 }584 return returnVariables;585 }586 private static Pair Algorithm_Morphology(String filename){587 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);588 Pair returnVariables = new Pair();589 int areaCounter=0;590 433 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 591 Mat binarizedOriginal = original.clone(); 592 Imgproc.adaptiveThreshold(original, binarizedOriginal,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 434 Mat binarized = original.clone(); 435 int blockSize = binarized.height()/3; 436 while (!(blockSize % 2 == 1 && blockSize > 1)) { 437 blockSize++; 438 } 439 System.out.println("Width: " + binarized.width() + " Height: " + binarized.height()); 440 //************************ 441 //Argument Setup 442 //************************ 443 double divisor; 444 switch (borderIgnoreAmount){ 445 case 5: 446 divisor = 40; 447 break; 448 case 10: 449 divisor = 20; 450 break; 451 case 20: 452 divisor = 10; 453 break; 454 case 40: 455 divisor = 5; 456 break; 457 case -1: 458 divisor = -1; 459 break; 460 default: divisor = -1; 461 } 462 if(divisor != -1 ) { 463 Mat mid = new Mat(); 464 Imgproc.adaptiveThreshold(original, mid,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, blockSize, THRESHOLD_C); 465 //Remove borders from Mat 466 //Get width and 467 double maxX = mid.size().width; 468 double maxY = mid.size().height; 469 Point cp1 = new Point(maxX / divisor, maxY / divisor); 470 Point cp2 = new Point(maxX - cp1.x, maxY - cp1.y); 471 Rect rectCrop = new Rect(cp1, cp2); 472 binarized = mid.submat(rectCrop); 473 } 474 else{Imgproc.adaptiveThreshold(original, binarized,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, blockSize, THRESHOLD_C);} 475 System.out.println("Width: " + binarized.width() + " Height: " + binarized.height()); 593 476 try{ 594 477 //************************************ 595 478 //1. Large Object Remover 596 479 //************************************ 597 Mat srcLOR = binarized Original.clone();480 Mat srcLOR = binarized.clone(); 598 481 Mat maskLOR = new Mat(); 599 482 Mat dstLOR = new Mat(); … … 614 497 srcLOR.copyTo(dstLOR, maskLOR); 615 498 616 Mat base = binarized Original.clone();499 Mat base = binarized.clone(); 617 500 //*********************************** 618 501 //3. Isolate straight lines … … 872 755 } 873 756 } 757 758 //****************** 759 //OLD FUNCTIONS 760 //****************** 761 private static Pair Algorithm_MorphologyOLD2(String filename){ 762 763 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 764 Boolean isSheetMusic = null; 765 Pair returnVariables = new Pair(); 766 int areaCounter = 0; 767 try{ 768 Mat edgesDetectedRGB = new Mat(); 769 Mat original = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 770 771 System.out.println("Width: " + original.width() + " Height: " + original.height()); 772 773 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 774 Mat hierarchy = new Mat(); 775 776 //Thresholds 777 Imgproc.adaptiveThreshold(original, original,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 778 Mat processed = original.clone(); 779 //Morphological Processing 780 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,1)); 781 Imgproc.erode(processed,processed,kernelErode); 782 783 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,3)); 784 Imgproc.dilate(processed,processed,kernelDilate); 785 786 Mat kernelOpening = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4)); 787 Imgproc.morphologyEx(processed, processed, Imgproc.MORPH_CLOSE, kernelOpening); 788 789 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8,8)); 790 Imgproc.erode(processed,processed,kernelErode02); 791 792 //Detect contours 793 Imgproc.findContours(processed, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE); 794 795 //Record areas 796 for (int i = 0; i < contours.size(); i++) { 797 double area = Imgproc.contourArea(contours.get(i)); 798 System.out.println("AREA: " + area); 799 //Check if area detected meets threshold 800 if(area > THRESHOLD_AREA_SIZE) { 801 areaCounter++; 802 803 } 804 } 805 System.out.println("areacount = " + areaCounter); 806 807 //Calculates if sheet music or not 808 if(areaCounter >= THRESHOLD_AREA_COUNT){ 809 isSheetMusic = true; 810 returnVariables.setBoolean(isSheetMusic); 811 returnVariables.setInteger(areaCounter); 812 } 813 } 814 catch(Exception e){ 815 System.err.println(e); 816 } 817 return returnVariables; 818 } 819 private static Pair Algorithm_MorphologyOLD(String filename){ 820 821 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 822 Boolean isSheetMusic = null; 823 Pair returnVariables = new Pair(); 824 int FILLED = -1; 825 try{ 826 Mat original1 = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE); 827 System.out.println("Width: " + original1.width() + " Height: " + original1.height()); 828 Mat original = original1.clone(); 829 Imgproc.adaptiveThreshold(original1, original,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C); 830 Mat test = original.clone(); 831 //************************************ 832 //Large Object Removal 833 //************************************ 834 Mat srcLOR = original.clone(); 835 Mat maskLOR = new Mat(); 836 Mat dstLOR = new Mat(); 837 838 //denoize 839 Mat denoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 840 Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, denoize); 841 842 //close up gaps 843 Mat gapCloser = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 844 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_CLOSE, gapCloser); 845 846 //Isolate large items 847 Mat isolateLarge = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(8, 8)); 848 Imgproc.morphologyEx(maskLOR,maskLOR,Imgproc.MORPH_OPEN, isolateLarge); 849 850 //Remove large items from image 851 Core.bitwise_not(maskLOR,maskLOR); 852 srcLOR.copyTo(dstLOR, maskLOR); 853 854 //**************************************** 855 //Small object removal (SOR) 856 //**************************************** 857 858 Mat srcSOR = dstLOR.clone(); 859 Mat maskSOR = new Mat(); 860 Mat dstSOR = new Mat(); 861 862 Mat startSOR =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 863 Imgproc.morphologyEx(srcSOR,maskSOR, Imgproc.MORPH_OPEN, startSOR); 864 865 Mat highlightSmall = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(7,7)); 866 Imgproc.dilate(maskSOR, maskSOR, highlightSmall); 867 868 869 /* Mat isolateSmall =Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10)); 870 Imgproc.morphologyEx(maskSOR,maskSOR,Imgproc.MORPH_CLOSE, isolateSmall); 871 imageViewer("13 isolate small - mask", maskSOR); 872 */ 873 874 //Remove small items from image 875 Core.bitwise_not(maskSOR, maskSOR); 876 srcSOR.copyTo(dstSOR, maskSOR); 877 878 879 //**************************************** 880 //start staff line detection 881 //**************************************** 882 883 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(15,2)); //10,2 884 Imgproc.erode(dstSOR,test,kernelErode); 885 886 887 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //20,3 888 Imgproc.dilate(test,test,kernelDilate); 889 890 891 Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 892 Imgproc.morphologyEx(test, test, Imgproc.MORPH_CLOSE, kernelClose); 893 894 895 896 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //10,1 897 Imgproc.erode(test,test,kernelErode02); 898 899 900 //******************************************************************************** 901 //DETECT OUTLINE AND FIND AREA OF THESE LINES. 902 //******************************************************************************** 903 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 904 ArrayList<MatOfPoint> largeContours = new ArrayList<MatOfPoint>(); 905 ArrayList<MatOfPoint> postContours = new ArrayList<MatOfPoint>(); 906 Mat hierarchy = new Mat(); 907 908 //PARAMETERS: input image, output array of arrays, output array, contour retrieval mode, contour approximation method. 909 //(contours) output array of arrays: Detected contours. Each contour is stored as a vector of points 910 //(hierarchy) output array: Optional output vector, containing information about the image topology. 911 //https://docs.opencv.org/3.3.1/d3/dc0/group__imgproc__shape.html#ga17ed9f5d79ae97bd4c7cf18403e1689a 912 913 Imgproc.findContours(test, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 914 915 System.out.println(contours.size()); 916 //Draw contours and record areas 917 Mat allContoursFound = Mat.zeros(test.size(), CvType.CV_8UC3); 918 Mat largeContoursFound = allContoursFound.clone() ; 919 Mat postContoursFound = allContoursFound.clone(); 920 int areaCounter = 0; 921 922 //Have created a preprocess to remove large objects. 923 //Need to now finalized Classifier, re try area detection. 924 //Paths to take - rectangle boxes around detected contours over threshold (area or perimeter) 925 //Just use area and periemter to determine if sheet music 926 //Discuss with david before weekend perhaps? 927 928 Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8 929 for (int i = 0; i < contours.size(); i++) { 930 double area = Imgproc.contourArea(contours.get(i)); 931 if(area > 100) { 932 //System.out.println("AREA: " + area); 933 Imgproc.drawContours(largeContoursFound, contours, i, new Scalar(255, 0, 0), FILLED); 934 //create list of large coutours found 935 largeContours.add(contours.get(i)); 936 } 937 } 938 939 //***************************************************************** 940 //Circles and centres on processed images 941 //***************************************************************** 942 943 //Init arrays 944 Mat circleOutput = allContoursFound.clone(); 945 MatOfPoint2f[] contoursPoly = new MatOfPoint2f[largeContours.size()]; 946 Point[] centers = new Point[largeContours.size()]; 947 float[][] radius = new float[largeContours.size()][1]; 948 949 //Fill arrays 950 for (int i = 0; i < largeContours.size(); i++) { 951 contoursPoly[i] = new MatOfPoint2f(); 952 Imgproc.approxPolyDP(new MatOfPoint2f(largeContours.get(i).toArray()), contoursPoly[i], 1, true); 953 centers[i] = new Point(); 954 Imgproc.minEnclosingCircle(contoursPoly[i], centers[i], radius[i]); 955 956 } 957 //Draw circle for each large contour 958 for (int i = 0; i < largeContours.size(); i++) { 959 Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1); 960 } 961 962 963 //******************************************************************************** 964 //Centroids - Everything must be to scale 965 //******************************************************************************** 966 967 ArrayList<Moments> mu = new ArrayList<Moments>(largeContours.size()); 968 Mat centreOutput = Mat.zeros(largeContoursFound.size(), CvType.CV_8UC3); 969 for (int i = 0; i < largeContours.size(); i++) { 970 mu.add(i, Imgproc.moments(largeContours.get(i), false)); 971 Moments p = mu.get(i); 972 int x = (int) (p.get_m10() / p.get_m00()); 973 int y = (int) (p.get_m01() / p.get_m00()); 974 Imgproc.circle(centreOutput, new Point(x, y), 4, new Scalar(255, 255, 255), 30); 975 } 976 977 //*********************************************** 978 //PostProcessing - Morphology Classifier 979 // Use dilation to "Connect the dots" 980 // Testing showed the centroids were clustered together 981 // Then use area or perimeter as a classifier filter 982 //*********************************************** 983 984 Mat postDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(150,15)); 985 Imgproc.dilate(centreOutput,centreOutput,postDilate); 986 987 Mat postClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,4)); //4,4 988 Imgproc.morphologyEx(centreOutput, centreOutput, Imgproc.MORPH_CLOSE, postClose); 989 990 Mat postDenoize = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,100)); 991 Imgproc.morphologyEx(centreOutput,centreOutput, Imgproc.MORPH_OPEN, postDenoize); 992 993 //Find area 994 Mat centreOutputGrey = new Mat(); 995 Imgproc.cvtColor(centreOutput, centreOutputGrey, Imgproc.COLOR_RGB2GRAY); 996 Imgproc.findContours(centreOutputGrey, postContours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 997 998 for (int i = 0; i < postContours.size(); i++) { 999 double area = Imgproc.contourArea(postContours.get(i)); 1000 if(area > THRESHOLD_AREA_SIZE) { 1001 //System.err.println("POST AREA: " + area); 1002 Imgproc.drawContours(postContoursFound, postContours, i, new Scalar(0, 255, 0), FILLED); 1003 areaCounter++; 1004 } 1005 } 1006 //Classifier Calculation 1007 if(areaCounter >= THRESHOLD_AREA_COUNT){ 1008 returnVariables.setBoolean(true); 1009 returnVariables.setInteger(areaCounter); 1010 } 1011 } 1012 catch(Exception e){ 1013 System.err.println(e); 1014 } 1015 return returnVariables; 1016 } 874 1017 } -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/runClassifer.sh
r33458 r33589 1 1 #!/bin/bash 2 #https://www.cyberciti.biz/faq/linux-unix-shell-check-if-directory-empty/ 2 3 3 if [ $# != 4 ] ; then 4 echo "Usage: ./testClassifier.sh folder/file classifier_type output_filename type(-a:all -test:100 -single:1)" 1>&2 4 if [ $# -lt 4 ] ; then 5 echo "Usage: ./testClassifier.sh <folder/file> <classifier_type> <output_filename> <amount>" 1>&2 6 echo "<amount> options: -a (all) -test (100) -single (1)" 5 7 exit 1 6 8 fi 7 9 if [ $# -eq 5 ] ; then 10 borderIgnore=$5 11 fi 8 12 source=$1 9 13 classifier_type=$2 10 14 output=$3 15 16 17 11 18 i=0 12 19 j=0 … … 68 75 javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar -Xlint javaClassifierComparison.java; 69 76 #Runs javaImageClassifier on 10 images of each 70 for file in $source/SheetMusic/*.png; do 71 if [ $i -lt 100 ] ; then 72 echo $file 73 echo $output 74 echo $i 75 echo "" 76 java -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar:. -Djava.library.path=/Scratch/cpb16/opencv-3.4.2/build/lib/ javaClassifierComparison $file $classifier_type $output 77 i=$[$i+1] 78 fi 79 done 80 for file in $source/NotSheetMusic/*.png; do 81 if [ $j -lt 100 ] ; then 82 echo $file 83 echo $output 84 echo $j 85 echo "" 86 java -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar:. -Djava.library.path=/Scratch/cpb16/opencv-3.4.2/build/lib/ javaClassifierComparison $file $classifier_type $output 87 j=$[$j+1] 88 fi 89 done 77 if [ "$(ls -A $source/SheetMusic)" ]; then 78 #Not Empty 79 for file in $source/SheetMusic/*.png; do 80 if [ $i -lt 10 ] ; then 81 echo $file 82 echo $output 83 echo $i 84 echo "" 85 java -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar:. -Djava.library.path=/Scratch/cpb16/opencv-3.4.2/build/lib/ javaClassifierComparison $file $classifier_type $output 86 i=$[$i+1] 87 fi 88 done 89 else 90 echo "$source/SheetMusic is Empty" 91 fi 92 93 if [ "$(ls -A $source/NotSheetMusic)" ]; then 94 #Not Empty 95 for file in $source/NotSheetMusic/*.png; do 96 if [ $j -lt 10 ] ; then 97 echo $file 98 echo $output 99 echo $j 100 echo "" 101 java -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar:. -Djava.library.path=/Scratch/cpb16/opencv-3.4.2/build/lib/ javaClassifierComparison $file $classifier_type $output 102 j=$[$j+1] 103 fi 104 done 105 else 106 echo "$source/NotSheetMusic is Empty" 107 fi 90 108 ;; 91 109 #________________________________________________________________________________________________________________________________________________________________________________________ … … 107 125 echo $output 108 126 echo $classifier_type 109 java -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar:. -Djava.library.path=/Scratch/cpb16/opencv-3.4.2/build/lib/ javaClassifierComparison $source $classifier_type $output 127 echo $borderIgnore 128 java -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar:. -Djava.library.path=/Scratch/cpb16/opencv-3.4.2/build/lib/ javaClassifierComparison $source $classifier_type $output $borderIgnore 110 129 ;; 111 130 esac
Note:
See TracChangeset
for help on using the changeset viewer.