Changeset 33418


Ignore:
Timestamp:
2019-08-15T13:53:28+12:00 (2 years ago)
Author:
cpb16
Message:

made progress with morphology, based one image, need to refine further, then test on multiple images

Location:
other-projects/is-sheet-music-encore/trunk/image-identification-dev-02
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/.idea/workspace.xml

    r33415 r33418  
    1515        <entry file="file://$PROJECT_DIR$/image-identification-development/src/Main.java">
    1616          <provider selected="true" editor-type-id="text-editor">
    17             <state relative-caret-position="2394">
    18               <caret line="780" selection-start-line="780" selection-end-line="780" />
     17            <state relative-caret-position="2774">
     18              <caret line="800" column="12" selection-start-line="800" selection-start-column="12" selection-end-line="800" selection-end-column="92" />
    1919              <folding>
    2020                <element signature="imports" expanded="true" />
     
    4040        <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java">
    4141          <provider selected="true" editor-type-id="text-editor">
    42             <state relative-caret-position="340">
    43               <caret line="275" lean-forward="true" selection-start-line="275" selection-end-line="275" />
     42            <state relative-caret-position="347">
     43              <caret line="306" column="41" selection-start-line="306" selection-start-column="41" selection-end-line="306" selection-end-column="41" />
    4444              <folding>
    45                 <element signature="class#StartAndEndPoint#0;class#MainMor#0" />
    46                 <element signature="method#toBufferedImage#0;class#MainMor#0" />
     45                <element signature="e#9745#9798#1" />
     46                <element signature="e#10939#13586#1" />
    4747              </folding>
    4848            </state>
     
    156156      <window_info anchor="bottom" id="Messages" order="10" weight="0.32962137" />
    157157      <window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
    158       <window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
     158      <window_info anchor="right" id="Ant Build" order="1" weight="0.24952137" />
    159159      <window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
    160160      <window_info anchor="right" id="Palette" order="3" />
     
    162162      <window_info anchor="right" id="Maven" order="5" weight="0.3299298" />
    163163    </layout>
     164  </component>
     165  <component name="antWorkspaceConfiguration">
     166    <option name="IS_AUTOSCROLL_TO_SOURCE" value="false" />
     167    <option name="FILTER_TARGETS" value="false" />
    164168  </component>
    165169  <component name="editorHistoryManager">
     
    206210    <entry file="file://$PROJECT_DIR$/image-identification-development/src/Main.java">
    207211      <provider selected="true" editor-type-id="text-editor">
    208         <state relative-caret-position="2394">
    209           <caret line="780" selection-start-line="780" selection-end-line="780" />
     212        <state relative-caret-position="2774">
     213          <caret line="800" column="12" selection-start-line="800" selection-start-column="12" selection-end-line="800" selection-end-column="92" />
    210214          <folding>
    211215            <element signature="imports" expanded="true" />
     
    229233    <entry file="file://$PROJECT_DIR$/image-identification-development/src/MainMorph.java">
    230234      <provider selected="true" editor-type-id="text-editor">
    231         <state relative-caret-position="340">
    232           <caret line="275" lean-forward="true" selection-start-line="275" selection-end-line="275" />
     235        <state relative-caret-position="347">
     236          <caret line="306" column="41" selection-start-line="306" selection-start-column="41" selection-end-line="306" selection-end-column="41" />
    233237          <folding>
    234             <element signature="class#StartAndEndPoint#0;class#MainMor#0" />
    235             <element signature="method#toBufferedImage#0;class#MainMor#0" />
     238            <element signature="e#9745#9798#1" />
     239            <element signature="e#10939#13586#1" />
    236240          </folding>
    237241        </state>
  • other-projects/is-sheet-music-encore/trunk/image-identification-dev-02/image-identification-development/src/MainMorph.java

    r33415 r33418  
    177177
    178178            //Variables
     179            int codeVersion = 2;
    179180            Mat edgesDetected = new Mat();
    180181            Mat mid = new Mat();
     
    222223            //****************MORPHOLOGY****************************************************************************************
    223224
    224             //Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,8));
    225             //Imgproc.morphologyEx(original, mid, Imgproc.MORPH_OPEN, kernel);
    226             //Imgproc.adaptiveThreshold(mid, edgesDetected,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, 2);
    227 
    228225            // Create the images that will use to extract the horizontal and vertical lines
    229             Mat horizontal = original.clone();
    230             Mat vertical = original.clone();
    231             // Specify size on horizontal axis
    232             int horizontal_size = horizontal.cols() / 30;
    233             // Create structure element for extracting horizontal lines through morphology operations
    234             Mat horizontalStructure = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(horizontal_size,1));
    235             // Apply morphology operations
    236             Imgproc.erode(horizontal, horizontal, horizontalStructure);
    237             Imgproc.dilate(horizontal, horizontal, horizontalStructure);
    238             // Show extracted horizontal lines
    239             showWaitDestroy("horizontal" , horizontal);
    240             // Specify size on vertical axis
    241             int vertical_size = vertical.rows() / 30;
    242             // Create structure element for extracting vertical lines through morphology operations
    243             Mat verticalStructure = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size( 1,vertical_size));
    244             // Apply morphology operations
    245             Imgproc.erode(vertical, vertical, verticalStructure);
    246             Imgproc.dilate(vertical, vertical, verticalStructure);
    247             // Show extracted vertical lines
    248             showWaitDestroy("vertical", vertical);
    249             // Inverse vertical image
    250             Core.bitwise_not(vertical, vertical);
    251             showWaitDestroy("vertical_bit" , vertical);
    252             // Extract edges and smooth image according to the logic
    253             // 1. extract edges
    254             // 2. dilate(edges)
    255             // 3. src.copyTo(smooth)
    256             // 4. blur smooth img
    257             // 5. smooth.copyTo(src, edges)
    258             // Step 1
    259             Mat edges = new Mat();
    260             Imgproc.adaptiveThreshold(vertical, edges, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 3, -2);
    261             showWaitDestroy("edges", edges);
    262             // Step 2
    263             Mat kernel = Mat.ones(2, 2, CvType.CV_8UC1);
    264             Imgproc.dilate(edges, edges, kernel);
    265             showWaitDestroy("dilate", edges);
    266             // Step 3
    267             Mat smooth = new Mat();
    268             vertical.copyTo(smooth);
    269             // Step 4
    270             Imgproc.blur(smooth, smooth, new Size(2, 2));
    271             // Step 5
    272             smooth.copyTo(vertical, edges);
    273             // Show final result
    274             showWaitDestroy("smooth - final", vertical);
    275             System.exit(0);
     226
     227            //dynamic morphology??
     228            if(codeVersion == 1) {
     229                int hori = original.width();
     230                int vert = original.height();
     231                //Find ratio between 100 and width and 100 and height
     232                int divX = hori/10;
     233                int divY = vert/10;
     234                int sizeX = (hori/divX) * 10;
     235                int sizeY = (vert/divY) * 10;
     236
     237                Mat test = original.clone();
     238                showWaitDestroy("Original", test);
     239
     240                System.out.println("hori: " + hori + '\t' + "vert: " + vert);
     241                System.out.println("sizeX: " + sizeX + '\t' + "sizeY: " + sizeY);
     242
     243                Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(sizeX, (sizeY/100)));
     244                Imgproc.erode(test,test,kernelErode);
     245                showWaitDestroy("01 Erode", test);
     246
     247                Mat kernelDialate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(sizeX,(sizeY/10)));
     248                Imgproc.dilate(test, test, kernelDialate);
     249                showWaitDestroy("02 Dialate", test);
     250
     251                Mat kernelErodeAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size((sizeX/10),(sizeY/5)));
     252                Imgproc.erode(test,test,kernelErodeAgain);
     253                showWaitDestroy(" 03 Erode Again", test);
     254
     255                Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size((sizeX/10)*3,(sizeY/10)*3));
     256                Imgproc.morphologyEx(test,test,Imgproc.MORPH_CLOSE, kernelClose);
     257                showWaitDestroy("04 Close", test);
     258
     259                Imgproc.adaptiveThreshold(test, test,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C);
     260                showWaitDestroy("05 Binarized", test);
     261
     262                Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size((sizeX/10),(sizeY/20)));
     263                Imgproc.morphologyEx(test,test,Imgproc.MORPH_OPEN, kernelOpen);
     264                showWaitDestroy(" 06 Open", test);
     265
     266                Mat kernelDialateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size((sizeX/5),(sizeY/100)));
     267                Imgproc.dilate(test, test, kernelDialateAgain);
     268                showWaitDestroy("07 Dialate", test);
     269
     270
     271                Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size((sizeX/10),(sizeY/2)));
     272                Imgproc.morphologyEx(test,test,Imgproc.MORPH_CLOSE, kernelCloseAgain);
     273                showWaitDestroy(" 08 Close Again (Final)", test);
     274            }
     275            //Successful hardcode for morhpology
     276            if (codeVersion == 2) {
     277                Mat test = original.clone();
     278                showWaitDestroy("00 Original", test);
     279
     280                Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,1));
     281                Imgproc.erode(test,test,kernelErode);
     282                showWaitDestroy("01 Erode", test);
     283
     284                Mat kernelDialate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(100,10));
     285                Imgproc.dilate(test, test, kernelDialate);
     286                showWaitDestroy("02 Dialate", test);
     287
     288                Mat kernelErodeAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,20));
     289                Imgproc.erode(test,test,kernelErodeAgain);
     290                showWaitDestroy(" 03 Erode Again", test);
     291
     292                Mat kernelClose = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(50,30));
     293                Imgproc.morphologyEx(test,test,Imgproc.MORPH_CLOSE, kernelClose);
     294                showWaitDestroy("04 Close", test);
     295
     296                Imgproc.adaptiveThreshold(test, test,255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C,Imgproc.THRESH_BINARY_INV, 15, THRESHOLD_C);
     297                showWaitDestroy("05 Binarized", test);
     298
     299                Mat kernelOpen = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4));
     300                Imgproc.morphologyEx(test,test,Imgproc.MORPH_OPEN, kernelOpen);
     301                showWaitDestroy(" 06 Open", test);
     302
     303//                Mat kernelDialateAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1,10));
     304//                Imgproc.dilate(test, test, kernelDialateAgain);
     305//                showWaitDestroy("07 Dialate", test);
     306
     307                //FIGURE OUT FLOOD FILL!!
     308                Imgproc.floodFill(test,test, new Point(1,1), new Scalar(2));
     309
     310
     311                Mat kernelCloseAgain = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(10,50));
     312                Imgproc.morphologyEx(test,test,Imgproc.MORPH_CLOSE, kernelCloseAgain);
     313                showWaitDestroy(" 08 Close Again (Final)", test);
     314
     315            }
     316            //Tutorial/Demo Code
     317            if (codeVersion == 3) {
     318                Mat horizontal = original.clone();
     319                Mat vertical = original.clone();
     320                // Specify size on horizontal axis
     321                int horizontal_size = horizontal.cols() / 50;
     322                // Create structure element for extracting horizontal lines through morphology operations
     323                Mat horizontalStructure = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(horizontal_size, 2));
     324                // Apply morphology operations
     325                Imgproc.erode(horizontal, horizontal, horizontalStructure);
     326                Imgproc.dilate(horizontal, horizontal, horizontalStructure);
     327                // Show extracted horizontal lines
     328                showWaitDestroy("horizontal", horizontal);
     329                // Specify size on vertical axis
     330                int vertical_size = vertical.rows() / 30;
     331                // Create structure element for extracting vertical lines through morphology operations
     332                Mat verticalStructure = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(1, vertical_size));
     333                // Apply morphology operations
     334                Imgproc.erode(vertical, vertical, verticalStructure);
     335                Imgproc.dilate(vertical, vertical, verticalStructure);
     336                // Show extracted vertical lines
     337                showWaitDestroy("vertical", vertical);
     338                // Inverse vertical image
     339                Core.bitwise_not(vertical, vertical);
     340                showWaitDestroy("vertical_bit", vertical);
     341                // Extract edges and smooth image according to the logic
     342                // 1. extract edges
     343                // 2. dilate(edges)
     344                // 3. src.copyTo(smooth)
     345                // 4. blur smooth img
     346                // 5. smooth.copyTo(src, edges)
     347                // Step 1
     348                Mat edges = new Mat();
     349                Imgproc.adaptiveThreshold(vertical, edges, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 3, -2);
     350                showWaitDestroy("edges", edges);
     351                // Step 2
     352                Mat kernel = Mat.ones(2, 2, CvType.CV_8UC1);
     353                Imgproc.dilate(edges, edges, kernel);
     354                showWaitDestroy("dilate", edges);
     355                // Step 3
     356                Mat smooth = new Mat();
     357                vertical.copyTo(smooth);
     358                // Step 4
     359                Imgproc.blur(smooth, smooth, new Size(2, 2));
     360                // Step 5
     361                smooth.copyTo(vertical, edges);
     362                // Show final result
     363                showWaitDestroy("smooth - final", vertical);
     364                System.exit(0);
     365            }
    276366
    277367
Note: See TracChangeset for help on using the changeset viewer.