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

65
LINES

< > BotCompany Repo | #1019539 // Live Web Cam Face Finder v2 [Dyn Module]

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

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

!7

cmodule WebCamFaceFinder > DynImageSurfaceAndEnabled {
  transient BufferedImage lastImage;
  FaceFinderByPictures1 finder;
  switchable bool overlay;
  switchable bool useFullFinder;
  switchable bool withNoFace = true;
  transient ReliableSingleThread rstUpdateImage = dm_rst(this, r updateImage);
  transient long duration = -1; // ms per recognition
  transient JLabel lblInfo;

  start-thread {
    dm_onFieldChange useFullFinder(r makeFinder);
    dm_onFieldChange withNoFace(r makeFinder);
    dm_runInQAndWait(r makeFinder);
    doEvery(100, rstUpdateImage);
  }

  void makeFinder {
    FaceFinderByPictures1 finder;
    File f = newFile(withNoFace ? ai_faceFinderDir("with-no-face") : ai_faceFinderDir(),
      useFullFinder
        ? "full-finder.struct"
        : "smallest-finder-over-95.struct");
    finder = (FaceFinderByPictures1) unstructFileOpt(f);
    if (finder != null)
      print("Made finder: " + f);
    else {
      finder = defaultFaceFinderByPictures();
      print("Using default finder");
    }
    setField(+finder);
  }
  
  afterVisualize {
    imageSurface_pixelated(imageSurface);
    containerAddFirst(buttons,
      lblInfo = jlabel(),
      dm_checkBox('overlay),
      dm_checkBox('useFullFinder),
      dm_checkBox('withNoFace));
  }
  
  void updateImage enter {
    if (imageSurface == null || !enabled) ret;
    final BufferedImage img = dm_webCamImage();
    temp tempAfterwards(r { lastImage = img });
    if (img == null || img == lastImage) ret;
    RGBImage rgb = RGBImage(img);
    long time = sysNow(); 
    FoundImgPlus<RGBImage> found = finder.getPlus(rgb);
    setField(duration := sysNow()-time);
    setText(lblInfo, duration + " ms. Score: " + formatIntPercent_99(toIntPercent(foundImgScore(found))));
    setSelection(foundImgToRect(found));
    if (overlay) {
      BufferedImage img2 = cloneBufferedImage(img);
      if (found != null)
        //fillRect(img2, found.r, Color.white);
        drawScaledPixelatedImage(img2, toBufferedImage(found.data), found.r);
      setImage(img2);
    } else
      setImage(img);
  }
}

Author comment

Began life as a copy of #1019214

download  show line numbers  debug dex  old transpilations   

Travelled to 12 computer(s): bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019539
Snippet name: Live Web Cam Face Finder v2 [Dyn Module]
Eternal ID of this version: #1019539/44
Text MD5: dbc7da7ad44e700c9f12c49b7dea2553
Transpilation MD5: d7e4f7ceb97a0a551c704fc6eb84c574
Author: stefan
Category: javax / stefan's os / web cam
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-05-05 20:28:14
Source code size: 2149 bytes / 65 lines
Pitched / IR pitched: No / No
Views / Downloads: 533 / 1603
Version history: 43 change(s)
Referenced in: [show references]