Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

80
LINES

< > BotCompany Repo | #1022991 // Learn Dogs vs Cats Prelude v2 [dev.]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (11807L/64K).

!7

cmodule LearnDogsVsCats > DynSingleFunctionWithPrintLog {
  /*switchable*/ transient File dir = userDir("dev/dogs-vs-cats/train");
  transient int eyeWidth = /*32*/10;
  transient double eyeSurround = 0.5;
  
  transient L<File> allImageFiles;
  transient L<BWImage> allEyeImages;
  transient Map<BWImage, File> eyeImageSources;
  transient ImageSurface is, isFound;
   
  start {
    if (!dm_osBooting())
      thread { doIt(); }
  }
  
  JComponent makeButtons() {
    ret hstackWithSpacing(super.makeButtons(),
      jbutton("Random Image", rThread randomImage));
  }
  
  void randomImage {
    recognizeImage(random(allImageFiles));
  }

  void doIt {
    // load scaled down test images
    
    allImageFiles = listImageFiles(dir);
    Map<File, LPair<Rect, S>> markingsMap = new Map;
    for (File f : allImageFiles)
      mapPutIfNemptyValue(markingsMap, f, loadImageFileMarkings(f));
    pnlStruct(markingsMap);
    if (empty(markingsMap)) ret with print("No marked images found in " + dir);
    
    new Map<File, BWIntegralImage> iImages;
    for (File f : keys(markingsMap))
      iImages.put(f, BWIntegralImage(f));
    print("Have " + n2(iImages, "integral image") + ", total size: " + str_toM(deepObjectSize(iImages)));
    
    allEyeImages = new L;
    eyeImageSources = new Map;
    for (File f : keys(markingsMap))
      if (fileNameContains(f, "cat"))
        for (Pair<Rect, S> mark : markingsMap.get(f))
          if (eqic(mark.b, "eye")) {
            BWImage img = bwResizeSmooth(iBWImageToBWImage(safeClipIBWImage(virtualScaledIntegralImageBW(iImages.get(f)),
              growRectProportionally(eyeSurround, mark.a)
            )), eyeWidth);
            allEyeImages.add(img);
            eyeImageSources.put(img, f);
          }
    //showImage(mergeBWImagesVertically(allEyeImages));
    
    //showImage(scaleDownUsingIntegralImageBW(random(values(iImages)), 256));
    //showImage(iBWImageToBWImage(virtualScaledIntegralImageBW(random(values(iImages)), 256)));

    //File f = random(allImageFiles);
    File f = firstFileWithName(allImageFiles, "cat.2516.jpg");
    
    recognizeImage(f);
  }
  
  void recognizeImage(File f) {
    print(f);
    
    BWII_MultiPatternFinder finder = new(allEyeImages, BWIntegralImage(f));
    disposePIFrame(is);
    is = null;
    
    for (FoundImg found : finder) {
      if (is == null || is.getImage().getWidth() != finder.currentScaleWidth)
        is = showImage(is, iBWImageToBWImage(finder.scaled));
      print(found + " / " + eyeImageSources.get(finder.pattern));
      overlaySelectionsOnImageSurface(is, ll(foundImgRect(found)));
      isFound = showZoomedImage(isFound, "Found", finder.pattern);
    }
  }
}

Author comment

Began life as a copy of #1022975

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, cfunsshuasjs, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1022991
Snippet name: Learn Dogs vs Cats Prelude v2 [dev.]
Eternal ID of this version: #1022991/12
Text MD5: ef5a48618637a88d9d77ed8e1b5f76c1
Transpilation MD5: 8b95840bc60470e563a55848f9ae77b0
Author: stefan
Category: javax / a.i.
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-04-17 17:25:15
Source code size: 2773 bytes / 80 lines
Pitched / IR pitched: No / No
Views / Downloads: 213 / 477
Version history: 11 change(s)
Referenced in: [show references]