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.

1  
asclass DynWebCamAnalyzer > DynImageSurfaceAndEnabled {
2  
  switchable bool overlay;
3  
  
4  
  transient ReliableSingleThread rstUpdateImage = dm_rst(this, r updateImage);
5  
  transient S info;
6  
  transient JLabel lblInfo;
7  
  transient L<Renderable> overlays;
8  
  
9  
  transient BufferedImage inputImage;
10  
  transient int w, h; // will be set to width & height of inputImage
11  
  transient bool analyzing;
12  
  transient S tempInfo;
13  
  transient RegularlyClearedAverage analysisTime = new(nto_10seconds()); // nanoseconds for analysis
14  
  
15  
  start {
16  
    set zoomToWindowOnSetImage;
17  
    dm_doEvery(100, rstUpdateImage);
18  
  }
19  
20  
  afterVisualize {
21  
    imageSurface_pixelated(imageSurface);
22  
    containerAddFirst(buttons,
23  
      lblInfo = dm_label info(),
24  
      dm_checkBox('overlay));
25  
  }
26  
  
27  
  void updateImage enter {
28  
    if (imageSurface == null || !enabled) ret;
29  
    BufferedImage img = dm_webCamImage();
30  
    if (img == null || img == inputImage) ret;
31  
    inputImage = img;
32  
    w = img.getWidth();
33  
    h = img.getHeight();
34  
    
35  
    long time = nanoTime();
36  
    pcall {
37  
      set analyzing;
38  
      tempInfo = null;
39  
      prepareImage();
40  
      time = nanoTime();
41  
      analyzeImage();
42  
    }
43  
    analyzing = false;
44  
    analysisTime.add(nanoTime()-time);
45  
    setInfo(joinNemptiesWithSpacedDot(tempInfo, "Recognition time: " + n2(iceil(analysisTime!)) + " ns"));
46  
    
47  
    BufferedImage img2 = img;
48  
    if (overlay)
49  
      pcall { drawOverlays(img2 = cloneBufferedImage(img)); }
50  
    setImage(img2);
51  
  }
52  
  
53  
  // overload me for preparation (e.g. making integral image)
54  
  void prepareImage {}
55  
  
56  
  // overlord me, uh, i mean, overload me
57  
  // can use inputImage, w, h and setInfo
58  
  void analyzeImage() {
59  
  }
60  
  
61  
  // overlooooad me if you want
62  
  void drawOverlays(BufferedImage img) {
63  
    renderRenderables(img, overlays);
64  
  }
65  
  
66  
  void setInfo(S info) {
67  
    if (analyzing) tempInfo = info;
68  
    else setField(+info);
69  
  }
70  
}

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: 237 / 517
Version history: 22 change(s)
Referenced in: [show references]