Uses 911K of libraries. Click here for Pure Java version (11495L/62K).
1 | !7 |
2 | |
3 | cmodule WebCamFaceFinder > DynImageSurfaceAndEnabled { |
4 | transient BufferedImage lastImage; |
5 | FaceFinderByPictures1 finder; |
6 | switchable bool overlay; |
7 | switchable bool useFullFinder; |
8 | switchable bool withNoFace = true; |
9 | transient ReliableSingleThread rstUpdateImage = dm_rst(this, r updateImage); |
10 | transient long duration = -1; // ms per recognition |
11 | transient JLabel lblInfo; |
12 | |
13 | start-thread { |
14 | dm_onFieldChange useFullFinder(r makeFinder); |
15 | dm_onFieldChange withNoFace(r makeFinder); |
16 | dm_runInQAndWait(r makeFinder); |
17 | doEvery(100, rstUpdateImage); |
18 | } |
19 | |
20 | void makeFinder { |
21 | FaceFinderByPictures1 finder; |
22 | File f = newFile(withNoFace ? ai_faceFinderDir("with-no-face") : ai_faceFinderDir(), |
23 | useFullFinder |
24 | ? "full-finder.struct" |
25 | : "smallest-finder-over-95.struct"); |
26 | finder = (FaceFinderByPictures1) unstructFileOpt(f); |
27 | if (finder != null) |
28 | print("Made finder: " + f); |
29 | else { |
30 | finder = defaultFaceFinderByPictures(); |
31 | print("Using default finder"); |
32 | } |
33 | setField(+finder); |
34 | } |
35 | |
36 | afterVisualize { |
37 | imageSurface_pixelated(imageSurface); |
38 | containerAddFirst(buttons, |
39 | lblInfo = jlabel(), |
40 | dm_checkBox('overlay), |
41 | dm_checkBox('useFullFinder), |
42 | dm_checkBox('withNoFace)); |
43 | } |
44 | |
45 | void updateImage enter { |
46 | if (imageSurface == null || !enabled) ret; |
47 | final BufferedImage img = dm_webCamImage(); |
48 | temp tempAfterwards(r { lastImage = img }); |
49 | if (img == null || img == lastImage) ret; |
50 | RGBImage rgb = RGBImage(img); |
51 | long time = sysNow(); |
52 | FoundImgPlus<RGBImage> found = finder.getPlus(rgb); |
53 | setField(duration := sysNow()-time); |
54 | setText(lblInfo, duration + " ms. Score: " + formatIntPercent_99(toIntPercent(foundImgScore(found)))); |
55 | setSelection(foundImgToRect(found)); |
56 | if (overlay) { |
57 | BufferedImage img2 = cloneBufferedImage(img); |
58 | if (found != null) |
59 | //fillRect(img2, found.r, Color.white); |
60 | drawScaledPixelatedImage(img2, toBufferedImage(found.data), found.r); |
61 | setImage(img2); |
62 | } else |
63 | setImage(img); |
64 | } |
65 | } |
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: | 535 / 1607 |
Version history: | 43 change(s) |
Referenced in: | [show references] |