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

70
LINES

< > BotCompany Repo | #1030561 // DynWebCamAnalyzer

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (15136L) is out of date.

asclass DynWebCamAnalyzer > DynImageSurfaceAndEnabled {
  switchable bool overlay;
  
  transient ReliableSingleThread rstUpdateImage = dm_rst(this, r updateImage);
  transient S info;
  transient JLabel lblInfo;
  transient L<Renderable> overlays;
  
  transient BufferedImage inputImage;
  transient int w, h; // will be set to width & height of inputImage
  transient bool analyzing;
  transient S tempInfo;
  transient RegularlyClearedAverage analysisTime = new(nto_10seconds()); // nanoseconds for analysis
  
  start {
    set zoomToWindowOnSetImage;
    dm_doEvery(100, rstUpdateImage);
  }

  afterVisualize {
    imageSurface_pixelated(imageSurface);
    containerAddFirst(buttons,
      lblInfo = dm_label info(),
      dm_checkBox('overlay));
  }
  
  void updateImage enter {
    if (imageSurface == null || !enabled) ret;
    BufferedImage img = dm_webCamImage();
    if (img == null || img == inputImage) ret;
    inputImage = img;
    w = img.getWidth();
    h = img.getHeight();
    
    long time = nanoTime();
    pcall {
      set analyzing;
      tempInfo = null;
      prepareImage();
      time = nanoTime();
      analyzeImage();
    }
    analyzing = false;
    analysisTime.add(nanoTime()-time);
    setInfo(joinNemptiesWithSpacedDot(tempInfo, "Recognition time: " + n2(iceil(analysisTime!)) + " ns"));
    
    BufferedImage img2 = img;
    if (overlay)
      pcall { drawOverlays(img2 = cloneBufferedImage(img)); }
    setImage(img2);
  }
  
  // overload me for preparation (e.g. making integral image)
  void prepareImage {}
  
  // overlord me, uh, i mean, overload me
  // can use inputImage, w, h and setInfo
  void analyzeImage() {
  }
  
  // overlooooad me if you want
  void drawOverlays(BufferedImage img) {
    renderRenderables(img, overlays);
  }
  
  void setInfo(S info) {
    if (analyzing) tempInfo = info;
    else setField(+info);
  }
}

Author comment

Began life as a copy of #1019539

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030561
Snippet name: DynWebCamAnalyzer
Eternal ID of this version: #1030561/23
Text MD5: 10491dff3cf70018397c59dfac9b288b
Author: stefan
Category: javax / stefan's os / web cam / ocr
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-05 00:53:16
Source code size: 1951 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 236 / 514
Version history: 22 change(s)
Referenced in: #1030562 - Web Cam / Central Compass [detects orientation of a line in the center of the image]
#1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)