Changeset 33458
- Timestamp:
- 2019-09-07T14:30:32+12:00 (5 years ago)
- Location:
- other-projects/is-sheet-music-encore/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/is-sheet-music-encore/trunk/EndToEndSystem.sh
r33455 r33458 37 37 if [ $type == "morph" ] ; then 38 38 if [ $# != 2 ] ; then 39 echo "Usage:./EndToEndSystem cluster <ResultSubDirectory> "39 echo "Usage:./EndToEndSystem cluster <ResultSubDirectory> " 40 40 exit 1 41 41 fi 42 42 location=$2 43 43 44 #Compile 44 45 echo "Compiling java programs..." -
other-projects/is-sheet-music-encore/trunk/Makefile
r33449 r33458 28 28 29 29 run-morphology-20-test: 30 cd image-identification-terminal/log-all-hires-new/test; rm log-morphology-MU-test.txt30 cd image-identification-terminal/log-all-hires-new/test; rm *.txt 31 31 cd image-identification-terminal; javac javaAccuracyCalculator.java 32 32 cd image-identification-terminal; javac -cp /Scratch/cpb16/opencv-3.4.2/build/bin/opencv-342.jar javaClassifierComparison.java; -
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/.idea/workspace.xml
r33455 r33458 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=" 677">17 <state relative-caret-position="557"> 18 18 <caret line="779" column="12" selection-start-line="779" selection-start-column="12" selection-end-line="779" selection-end-column="12" /> 19 19 <folding> … … 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=" 144">43 <caret line=" 1217" column="16" selection-start-line="1217" selection-start-column="16" selection-end-line="1217" selection-end-column="16" />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" /> 44 44 <folding> 45 45 <element signature="imports" expanded="true" /> 46 <element signature="class#Pair#0;class#MainMorph#0" />47 46 <element signature="method#imageViewer#0;class#MainMorph#0" /> 48 <element signature="e#13990#16460#1" /> 49 <element signature="e#16545#18548#1" /> 50 <element signature="e#18617#21240#1" /> 51 <element signature="e#21324#26995#1" /> 52 <element signature="e#27080#31057#1" /> 53 <element signature="e#31125#32303#1" /> 54 <element signature="e#32372#36335#1" /> 55 <element signature="e#36445#48148#1" /> 56 <element signature="e#42969#43036#0" /> 57 <element signature="e#48242#59125#1" /> 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" /> 58 59 </folding> 59 60 </state> … … 64 65 <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java"> 65 66 <provider selected="true" editor-type-id="text-editor"> 66 <state relative-caret-position=" 1539">67 <caret line=" 135" column="4" selection-start-line="135" selection-start-column="4" selection-end-line="160" selection-end-column="5" />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" /> 68 69 <folding> 69 70 <element signature="imports" expanded="true" /> … … 71 72 <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" /> 72 73 <element signature="class#Pair#0;class#javaClassifierComparison#0" /> 74 <element signature="method#main#0;class#javaClassifierComparison#0" /> 73 75 <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" /> 74 76 <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" /> … … 107 109 <option value="$PROJECT_DIR$/../image-identification-terminal/javaImageClassifier.java" /> 108 110 <option value="$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison" /> 111 <option value="$PROJECT_DIR$/image-identification-development/src/Main.java" /> 109 112 <option value="$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java" /> 110 <option value="$PROJECT_DIR$/image-identification-development/src/Main.java" />111 113 <option value="$PROJECT_DIR$/image-identification-development/src/MainMorph.java" /> 112 114 </list> … … 120 122 </component> 121 123 <component name="ProjectFrameBounds" extendedState="6"> 122 <option name="x" value=" 511" />123 <option name="y" value="2 14" />124 <option name="width" value=" 918" />125 <option name="height" value=" 767" />124 <option name="x" value="67" /> 125 <option name="y" value="25" /> 126 <option name="width" value="807" /> 127 <option name="height" value="1025" /> 126 128 </component> 127 129 <component name="ProjectView"> … … 189 191 <window_info anchor="bottom" id="Message" order="0" /> 190 192 <window_info anchor="bottom" id="Find" order="1" weight="0.32962137" /> 191 <window_info anchor="bottom" id="Run" order="2" weight="0. 27951002" />193 <window_info anchor="bottom" id="Run" order="2" weight="0.42316258" /> 192 194 <window_info anchor="bottom" id="Debug" order="3" weight="0.3997773" /> 193 195 <window_info anchor="bottom" id="Cvs" order="4" weight="0.25" /> … … 234 236 </provider> 235 237 </entry> 236 <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java">237 <provider selected="true" editor-type-id="text-editor">238 <state relative-caret-position="1539">239 <caret line="135" column="4" selection-start-line="135" selection-start-column="4" selection-end-line="160" selection-end-column="5" />240 <folding>241 <element signature="imports" expanded="true" />242 <element signature="method#init#0;class#javaClassifierComparison#0" />243 <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" />244 <element signature="class#Pair#0;class#javaClassifierComparison#0" />245 <element signature="method#Algorithm_HoughLinesP_Single#0;class#javaClassifierComparison#0" />246 <element signature="method#Algorithm_HoughLinesP_Combo#0;class#javaClassifierComparison#0" />247 <element signature="method#Algorithm_MorphologyOLD#0;class#javaClassifierComparison#0" />248 <element signature="method#Algorithm_Morphology#0;class#javaClassifierComparison#0" />249 <element signature="method#Classifier_LineCounter#0;class#javaClassifierComparison#0" />250 <element signature="method#Classifier_ClusterDetection#0;class#javaClassifierComparison#0" />251 <element signature="method#removeDuplicates#0;class#javaClassifierComparison#0" />252 <element signature="method#VarianceCalc#0;class#javaClassifierComparison#0" />253 <element signature="method#lineComparison#0;class#javaClassifierComparison#0" />254 <element signature="method#ClusterCheck#0;class#javaClassifierComparison#0" />255 </folding>256 </state>257 </provider>258 </entry>259 238 <entry file="file://$PROJECT_DIR$/image-identification-development/src/Main.java"> 260 239 <provider selected="true" editor-type-id="text-editor"> 261 <state relative-caret-position=" 677">240 <state relative-caret-position="557"> 262 241 <caret line="779" column="12" selection-start-line="779" selection-start-column="12" selection-end-line="779" selection-end-column="12" /> 263 242 <folding> … … 280 259 </provider> 281 260 </entry> 282 <entry file="file://$PROJECT_DIR$/ image-identification-development/src/MainMorph.java">261 <entry file="file://$PROJECT_DIR$/../image-identification-terminal/javaClassifierComparison.java"> 283 262 <provider selected="true" editor-type-id="text-editor"> 284 <state relative-caret-position=" 144">285 <caret line=" 1217" column="16" selection-start-line="1217" selection-start-column="16" selection-end-line="1217" selection-end-column="16" />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" /> 286 265 <folding> 287 266 <element signature="imports" expanded="true" /> 288 <element signature="class#Pair#0;class#MainMorph#0" /> 289 <element signature="method#imageViewer#0;class#MainMorph#0" /> 290 <element signature="e#13990#16460#1" /> 291 <element signature="e#16545#18548#1" /> 292 <element signature="e#18617#21240#1" /> 293 <element signature="e#21324#26995#1" /> 294 <element signature="e#27080#31057#1" /> 295 <element signature="e#31125#32303#1" /> 296 <element signature="e#32372#36335#1" /> 297 <element signature="e#36445#48148#1" /> 298 <element signature="e#42969#43036#0" /> 299 <element signature="e#48242#59125#1" /> 267 <element signature="method#init#0;class#javaClassifierComparison#0" /> 268 <element signature="class#StartAndEndPoint#0;class#javaClassifierComparison#0" /> 269 <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" /> 275 <element signature="method#Classifier_LineCounter#0;class#javaClassifierComparison#0" /> 276 <element signature="method#Classifier_ClusterDetection#0;class#javaClassifierComparison#0" /> 277 <element signature="method#removeDuplicates#0;class#javaClassifierComparison#0" /> 278 <element signature="method#VarianceCalc#0;class#javaClassifierComparison#0" /> 279 <element signature="method#lineComparison#0;class#javaClassifierComparison#0" /> 280 <element signature="method#ClusterCheck#0;class#javaClassifierComparison#0" /> 300 281 </folding> 301 282 </state> 302 283 </provider> 303 284 </entry> 285 <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java"> 286 <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" /> 289 <folding> 290 <element signature="imports" expanded="true" /> 291 <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 </folding> 305 </state> 306 </provider> 307 </entry> 304 308 </component> 305 309 <component name="masterDetails"> -
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/image-identification-development/src/MainMorph.java
r33455 r33458 226 226 //String default_file = hiresDirectory+"/MU/SheetMusic/bc.ark+=13960=t2j72dt1p-8.png"; //Handwritten 227 227 //String default_file = hiresDirectory+"/MU/SheetMusic/bc.ark+=13960=t2j72dt1p-9.png"; //Handwritten 228 String default_file = hiresDirectory+"/MU/SheetMusic/coo.31924062612282-9.png"; //Snippet228 //String default_file = hiresDirectory+"/MU/SheetMusic/coo.31924062612282-9.png"; //Snippet 229 229 //String default_file = hiresDirectory+"/MU/SheetMusic/dul1.ark+=13960=t2x41569k-10.png"; //Generated 230 230 //String default_file = hiresDirectory+"/MU/SheetMusic/dul1.ark+=13960=t2x41569k-7.png"; … … 235 235 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-2.png"; //large numbers 236 236 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-3.png"; 237 String default_file = hiresDirectory+"/MU/SheetMusic/mdp.39015080921409-9.png"; 237 238 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-4.png"; 238 239 //String default_file = hiresDirectory+"/MU/NotSheetMusic/aeu.ark+=13960=t0dv28v9r-5.png"; … … 344 345 imageViewer("04 Close", test); 345 346 346 //Imgproc.threshold(test,test, 127, 255, Imgproc.THRESH_BINARY);347 //imageViewer("05 Binarized", test);347 Imgproc.threshold(test,test, 127, 255, Imgproc.THRESH_BINARY); 348 imageViewer("05 Binarized", test); 348 349 349 350 Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4)); … … 351 352 imageViewer(" 06 Open", test); 352 353 353 // Mat kernelDialateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10)); 354 // Imgproc.dilate(test, test, kernelDialateAgain); 355 // imageViewer("07 Dialate", test); 356 357 //FIGURE OUT FLOOD FILL!! 358 Imgproc.floodFill(test,test, new Point(1,1), new Scalar(2)); 359 354 Mat kernelDialateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10)); 355 Imgproc.dilate(test, test, kernelDialateAgain); 356 imageViewer("07 Dialate", test); 360 357 361 358 Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,50)); 362 359 Imgproc.morphologyEx(test,test,Imgproc.MORPH_CLOSE, kernelCloseAgain); 363 360 imageViewer(" 08 Close Again (Final)", test); 361 362 //FIGURE OUT FLOOD FILL!! 363 //Imgproc.floodFill(test,test, new Point(1,1), new Scalar(2)); 364 364 365 365 } … … 857 857 // Mat circleOutput = allContoursFound.clone(); 858 858 // MatOfPoint2f[] contoursPoly = new MatOfPoint2f[largeContours.size()]; 859 // Rect[] boundRect = new Rect[largeContours.size()]; 859 860 // Point[] centers = new Point[largeContours.size()]; 860 861 // float[][] radius = new float[largeContours.size()][1]; … … 864 865 // contoursPoly[i] = new MatOfPoint2f(); 865 866 // Imgproc.approxPolyDP(new MatOfPoint2f(largeContours.get(i).toArray()), contoursPoly[i], 1, true); 867 // boundRect[i] = Imgproc.boundingRect(new MatOfPoint(contoursPoly[i].toArray())); 866 868 // centers[i] = new Point(); 867 869 // Imgproc.minEnclosingCircle(contoursPoly[i], centers[i], radius[i]); … … 870 872 // //Draw circle for each large contour 871 873 // for (int i = 0; i < largeContours.size(); i++) { 874 // Imgproc.rectangle(drawing, boundRect[i].tl(), boundRect[i].br(), color, 2); 872 875 // Imgproc.circle(circleOutput, centers[i], (int) radius[i][0],new Scalar(255, 0, 0), 1); 873 876 // } … … 1157 1160 //Display Original 1158 1161 imageViewer("original", original); 1159 Mat base = binarizedOriginal.clone(); 1160 imageViewer("00 Inverse Binarized Original", base); 1162 imageViewer("000 Inverse Binarized Original", binarizedOriginal); 1161 1163 1162 1164 1163 1165 //************************************ 1164 //1. Large object Remover1166 //1. Large Object Remover 1165 1167 //************************************ 1166 1168 Mat srcLOR = binarizedOriginal.clone(); … … 1173 1175 imageViewer("001 De-noise", maskLOR); 1174 1176 1175 // heal the large items1176 Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size( 10,10));1177 //Heal the large items 1178 Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(25,25)); 1177 1179 Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_CLOSE, healLOR); 1178 1180 imageViewer("002 heal objects in mask", maskLOR); 1179 1181 1180 1182 //IsolateLarge 1181 Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size( 20,20));1182 Imgproc. erode(maskLOR,maskLOR,isolateLargeLOR);1183 Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30)); 1184 Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_OPEN, isolateLargeLOR); 1183 1185 imageViewer("003 Isolate large", maskLOR); 1184 1186 … … 1187 1189 imageViewer("100 Large Items Removed", dstLOR); 1188 1190 1191 // //CODE FROM PRESENTATION 1192 // Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,1)); 1193 // Imgproc.erode(dstTOR,base,kernelErode); 1194 // imageViewer("201 Erode", base); 1195 // 1196 // Mat kernelDialate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(110,10)); 1197 // Imgproc.dilate(base, base, kernelDialate); 1198 // imageViewer("202 Dialate", base); 1199 // 1200 // Mat kernelErodeAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,20)); 1201 // Imgproc.erode(base,base,kernelErodeAgain); 1202 // imageViewer(" 203 Erode Again", base); 1203 // 1204 // Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(35,20)); 1205 // Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelClose); 1206 // imageViewer("204 Close", base); 1207 // 1208 // Imgproc.threshold(base,base, 127, 255, Imgproc.THRESH_BINARY); 1209 // imageViewer("205 Binarized", base); 1210 // 1211 // Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4)); 1212 // Imgproc.morphologyEx(base,base,Imgproc.MORPH_OPEN, kernelOpen); 1213 // imageViewer("206 Open", base); 1214 // 1215 // Mat kernelDialateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10)); 1216 // Imgproc.dilate(base, base, kernelDialateAgain); 1217 // imageViewer("207 Dialate", base); 1218 // 1219 // Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,50)); 1220 // Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelCloseAgain); 1221 // imageViewer("208 Close Again (Final)", base); 1222 1189 1223 //*********************************** 1190 //2. Text-sized Object Removal 1224 // //3.1 Remove big outlines 1225 // //*********************************** 1226 // Mat srcTOR = base.clone(); 1227 // Mat maskTOR = new Mat(); 1228 // Mat dstTOR = new Mat(); 1229 // 1230 // //Remove small objects in prep for masking (De-Noise) 1231 // Mat removeSmallTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 1232 // Imgproc.morphologyEx(srcTOR,maskTOR, Imgproc.MORPH_OPEN, removeSmallTOR); 1233 // imageViewer("2101 Remove Small from mask", maskTOR); 1234 // 1235 // //heal the large items 1236 // Mat healTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10)); 1237 // Imgproc.morphologyEx(maskTOR,maskTOR, Imgproc.MORPH_CLOSE, healTOR); 1238 // imageViewer("2102 heal objects in mask", maskTOR); 1239 // 1240 // //Highlight black outline 1241 // Mat highlightLargeTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10)); 1242 // Imgproc.erode(maskTOR,maskTOR,highlightLargeTOR); 1243 // imageViewer("2103 highlight objects", maskTOR); 1244 // 1245 // Core.bitwise_not(maskTOR, maskTOR); 1246 // srcTOR.copyTo(dstTOR, maskTOR); 1247 // imageViewer("2200 Black outline Removed", dstTOR); 1248 1249 1250 1251 1252 1253 1254 1255 //4. Classify like line clusters. 1256 Mat base = binarizedOriginal.clone(); 1191 1257 //*********************************** 1192 1193 Mat srcTOR = dstLOR.clone(); 1194 Mat maskTOR = new Mat(); 1195 Mat dstTOR = new Mat(); 1196 1197 //Remove small objects in prep for masking (De-Noise) 1198 Mat removeSmallTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 1199 Imgproc.morphologyEx(srcTOR,maskTOR, Imgproc.MORPH_OPEN, removeSmallTOR); 1200 imageViewer("101 Remove Small from mask", maskTOR); 1201 1202 //heal the large items 1203 Mat healTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10)); 1204 Imgproc.morphologyEx(maskTOR,maskTOR, Imgproc.MORPH_CLOSE, healTOR); 1205 imageViewer("102 heal objects in mask", maskTOR); 1206 1207 //Highlight black outline 1208 Mat highlightLargeTOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,10)); 1209 Imgproc.erode(maskTOR,maskTOR,highlightLargeTOR); 1210 imageViewer("103 highlight objects", maskTOR); 1211 1212 Core.bitwise_not(maskTOR, maskTOR); 1213 srcTOR.copyTo(dstTOR, maskTOR); 1214 imageViewer("200 Black outline Removed", dstTOR); 1215 1258 //3. Isolate straight lines 1216 1259 //*********************************** 1217 //3. Standard plan from presentation (TAKEN FROM CODE VERSION 5) 1260 //Heal lines 1261 Mat healISL = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(82,1)); 1262 Imgproc.morphologyEx(dstLOR,base, Imgproc.MORPH_OPEN, healISL); 1263 imageViewer("202 heal objects in mask", base); 1264 1265 //Make White Blobs 1266 1267 //NEED THIS?? 1268 Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,1)); 1269 Imgproc.morphologyEx(base,base,Imgproc.MORPH_OPEN, kernelOpen); 1270 imageViewer("203 Open", base); 1271 //NEED THIS? 1272 1273 Mat kernelDilateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10)); 1274 Imgproc.dilate(base, base, kernelDilateAgain); 1275 imageViewer("204 Dilate", base); 1276 1277 Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(12,50)); 1278 Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelCloseAgain); 1279 imageViewer("205 Close Again (Final)", base); 1280 1218 1281 //*********************************** 1219 Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,2)); 1220 Imgproc.erode(dstTOR,base,kernelErode); 1221 imageViewer("201 Erode plus pre", base); 1222 1223 Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,2)); 1224 Imgproc.dilate(base,base,kernelDilate); 1225 imageViewer("202 Dilate", base); 1226 1227 Mat kernelClosing = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(20,5)); 1228 Imgproc.morphologyEx(base, base, Imgproc.MORPH_CLOSE, kernelClosing); 1229 imageViewer("203 Close", base); 1230 1231 Mat kernelErode02 = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,2)); 1232 Imgproc.erode(base,base,kernelErode02); 1233 imageViewer("204 Erode (Final)", base); 1234 1235 //4. Classify like line clusters. 1282 //4. Find 'Clusters' 1283 // Need to find areas, using bounding boxes 1284 // Find how tall the bounding box is, if its taller than 'x' then classify as Sheet Music 1285 //*********************************** 1286 1287 //***************************************************************** 1288 //4.1 Prep Rectangles on processed images 1289 //***************************************************************** 1290 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 1291 Mat hierarchy = new Mat(); 1292 Imgproc.findContours(base, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 1293 //Draw contours and record areas 1294 Mat allContoursFound = Mat.zeros(base.size(), CvType.CV_8UC3); 1295 Mat rectOutput = allContoursFound.clone(); 1296 Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8 1297 //Init arrays 1298 MatOfPoint2f[] contoursPoly = new MatOfPoint2f[contours.size()]; 1299 Rect[] boundRect = new Rect[contours.size()]; 1300 1301 //Fill arrays 1302 for (int i = 0; i < contours.size(); i++) { 1303 contoursPoly[i] = new MatOfPoint2f(); 1304 Imgproc.approxPolyDP(new MatOfPoint2f(contours.get(i).toArray()), contoursPoly[i], 1, true); 1305 boundRect[i] = Imgproc.boundingRect(new MatOfPoint(contoursPoly[i].toArray())); 1306 } 1307 //Draw circle for each large contour 1308 for (int i = 0; i < contours.size(); i++) { 1309 if(boundRect[i].height > 100){ 1310 System.out.println("i:"+ i + " Height: " + boundRect[i].height); 1311 if(boundRect[i].width > 300){ 1312 System.out.println("i:"+ i + " Width: " + boundRect[i].width); 1313 Imgproc.rectangle(rectOutput, boundRect[i].tl(), boundRect[i].br(), new Scalar(255, 0, 0), 20); 1314 } 1315 } 1316 } 1317 1318 1319 imageViewer("4000 Rect found", rectOutput); 1320 1321 1322 1236 1323 } 1237 //USE stuc element, to rule out large wide and long pieces of black and white. 1238 1324 //ClassfierComparsion - Reset after david chat 1325 if(CODE_VERSION == 91){ 1326 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 1327 Pair returnVariables = new Pair(); 1328 int areaCounter=0; 1329 //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); 1332 try{ 1333 //************************************ 1334 //1. Large Object Remover 1335 //************************************ 1336 Mat srcLOR = binarizedOriginal.clone(); 1337 Mat maskLOR = new Mat(); 1338 Mat dstLOR = new Mat(); 1339 1340 //Remove small objects in prep for masking (De-Noise) 1341 Mat removeSmallLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 1342 Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, removeSmallLOR); 1343 1344 //Heal the large items 1345 Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(25,25)); 1346 Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_CLOSE, healLOR); 1347 1348 //IsolateLarge 1349 Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30)); 1350 Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_OPEN, isolateLargeLOR); 1351 1352 Core.bitwise_not(maskLOR,maskLOR); 1353 srcLOR.copyTo(dstLOR, maskLOR); 1354 1355 Mat base = binarizedOriginal.clone(); 1356 //*********************************** 1357 //3. Isolate straight lines 1358 //*********************************** 1359 //Heal lines 1360 Mat healISL = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(82,1)); 1361 Imgproc.morphologyEx(dstLOR,base, Imgproc.MORPH_OPEN, healISL); 1362 1363 //Make White Blobs 1364 Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,1)); 1365 Imgproc.morphologyEx(base,base,Imgproc.MORPH_OPEN, kernelOpen); 1366 1367 Mat kernelDilateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10)); 1368 Imgproc.dilate(base, base, kernelDilateAgain); 1369 1370 Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(12,50)); 1371 Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelCloseAgain); 1372 1373 //*********************************** 1374 //4. Find 'Clusters' 1375 // Need to find areas, using bounding boxes 1376 // Find how tall the bounding box is, if its taller than 'x' then classify as Sheet Music 1377 //*********************************** 1378 1379 //***************************************************************** 1380 //4.1 Prep Rectangles on processed images 1381 //***************************************************************** 1382 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 1383 Mat hierarchy = new Mat(); 1384 Imgproc.findContours(base, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 1385 //Draw contours and record areas 1386 Mat allContoursFound = Mat.zeros(base.size(), CvType.CV_8UC3); 1387 Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8 1388 //Init arrays 1389 MatOfPoint2f[] contoursPoly = new MatOfPoint2f[contours.size()]; 1390 Rect[] boundRect = new Rect[contours.size()]; 1391 1392 //Fill arrays 1393 for (int i = 0; i < contours.size(); i++) { 1394 contoursPoly[i] = new MatOfPoint2f(); 1395 Imgproc.approxPolyDP(new MatOfPoint2f(contours.get(i).toArray()), contoursPoly[i], 1, true); 1396 boundRect[i] = Imgproc.boundingRect(new MatOfPoint(contoursPoly[i].toArray())); 1397 } 1398 //Draw circle for each large contour 1399 //MAKE THE COMPARING VALUES GLOBAL CONSTANTS 1400 for (int i = 0; i < contours.size(); i++) { 1401 if(boundRect[i].height > 100){ 1402 if(boundRect[i].width > 300){ 1403 areaCounter++; 1404 } 1405 } 1406 } 1407 1408 //Classifier Calculation 1409 if(areaCounter >= THRESHOLD_AREA_COUNT){ 1410 returnVariables.setBoolean(true); 1411 returnVariables.setInteger(areaCounter); 1412 } 1413 } 1414 catch(Exception e){ 1415 System.err.println(e); 1416 } 1417 //return returnVariables; 1418 } 1239 1419 1240 1420 //****************MORPHOLOGY**************************************************************************************** -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/configClassifierComparison.properties
r33447 r33458 14 14 #MORPHOLOGY 15 15 THRESHOLD_AREA_SIZE = 10000 16 THRESHOLD_AREA_COUNT = 1016 THRESHOLD_AREA_COUNT = 2 17 17 18 18 -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/javaClassifierComparison.java
r33449 r33458 328 328 return returnVariables; 329 329 } 330 private static Pair Algorithm_MorphologyOLD (String filename){330 private static Pair Algorithm_MorphologyOLD2(String filename){ 331 331 332 332 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); … … 386 386 return returnVariables; 387 387 } 388 private static Pair Algorithm_Morphology (String filename){388 private static Pair Algorithm_MorphologyOLD(String filename){ 389 389 390 390 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); … … 573 573 } 574 574 } 575 //Classifier Calculation 576 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 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); 593 try{ 594 //************************************ 595 //1. Large Object Remover 596 //************************************ 597 Mat srcLOR = binarizedOriginal.clone(); 598 Mat maskLOR = new Mat(); 599 Mat dstLOR = new Mat(); 600 601 //Remove small objects in prep for masking (De-Noise) 602 Mat removeSmallLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(5,5)); 603 Imgproc.morphologyEx(srcLOR,maskLOR, Imgproc.MORPH_OPEN, removeSmallLOR); 604 605 //Heal the large items 606 Mat healLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(25,25)); 607 Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_CLOSE, healLOR); 608 609 //IsolateLarge 610 Mat isolateLargeLOR = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(30,30)); 611 Imgproc.morphologyEx(maskLOR,maskLOR, Imgproc.MORPH_OPEN, isolateLargeLOR); 612 613 Core.bitwise_not(maskLOR,maskLOR); 614 srcLOR.copyTo(dstLOR, maskLOR); 615 616 Mat base = binarizedOriginal.clone(); 617 //*********************************** 618 //3. Isolate straight lines 619 //*********************************** 620 //Heal lines 621 Mat healISL = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(82,1)); 622 Imgproc.morphologyEx(dstLOR,base, Imgproc.MORPH_OPEN, healISL); 623 624 //Make White Blobs 625 Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,1)); 626 Imgproc.morphologyEx(base,base,Imgproc.MORPH_OPEN, kernelOpen); 627 628 Mat kernelDilateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10)); 629 Imgproc.dilate(base, base, kernelDilateAgain); 630 631 Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(12,50)); 632 Imgproc.morphologyEx(base,base,Imgproc.MORPH_CLOSE, kernelCloseAgain); 633 634 //*********************************** 635 //4. Find 'Clusters' 636 // Need to find areas, using bounding boxes 637 // Find how tall the bounding box is, if its taller than 'x' then classify as Sheet Music 638 //*********************************** 639 640 //***************************************************************** 641 //4.1 Prep Rectangles on processed images 642 //***************************************************************** 643 ArrayList<MatOfPoint> contours = new ArrayList<MatOfPoint>(); 644 Mat hierarchy = new Mat(); 645 Imgproc.findContours(base, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE); 646 //Draw contours and record areas 647 Mat allContoursFound = Mat.zeros(base.size(), CvType.CV_8UC3); 648 Imgproc.drawContours(allContoursFound, contours, -1, new Scalar(0, 255, 0), 1); //USES LINE_8 649 //Init arrays 650 MatOfPoint2f[] contoursPoly = new MatOfPoint2f[contours.size()]; 651 Rect[] boundRect = new Rect[contours.size()]; 652 653 //Fill arrays 654 for (int i = 0; i < contours.size(); i++) { 655 contoursPoly[i] = new MatOfPoint2f(); 656 Imgproc.approxPolyDP(new MatOfPoint2f(contours.get(i).toArray()), contoursPoly[i], 1, true); 657 boundRect[i] = Imgproc.boundingRect(new MatOfPoint(contoursPoly[i].toArray())); 658 } 659 //Draw circle for each large contour 660 //MAKE THE COMPARING VALUES GLOBAL CONSTANTS 661 for (int i = 0; i < contours.size(); i++) { 662 if(boundRect[i].height > 100){ 663 if(boundRect[i].width > 300){ 664 areaCounter++; 665 } 666 } 667 } 668 575 669 //Classifier Calculation 576 670 if(areaCounter >= THRESHOLD_AREA_COUNT){ -
other-projects/is-sheet-music-encore/trunk/image-identification-terminal/runClassifer.sh
r33437 r33458 69 69 #Runs javaImageClassifier on 10 images of each 70 70 for file in $source/SheetMusic/*.png; do 71 if [ $i -lt 10 ] ; then71 if [ $i -lt 100 ] ; then 72 72 echo $file 73 73 echo $output … … 79 79 done 80 80 for file in $source/NotSheetMusic/*.png; do 81 if [ $j -lt 10 ] ; then81 if [ $j -lt 100 ] ; then 82 82 echo $file 83 83 echo $output
Note:
See TracChangeset
for help on using the changeset viewer.