Download Jar. Uses 24524K of libraries. Click here for Pure Java version (6201L/40K).
1 | !7 |
2 | |
3 | static double confidenceThreshold = 10; |
4 | sbool setViewSize = false; |
5 | static double timeout = 10; |
6 | static int skipFirst = 9; |
7 | static int nn = 0, totalSamples; |
8 | |
9 | lib 1008985 // webcam |
10 | lib 1008987 // bridj |
11 | lib 1004016 // slf4j api |
12 | |
13 | // OpenIMAJ |
14 | lib 1004905 lib 1004906 lib 1004908 lib 1004909 lib 1004910 |
15 | lib 1004911 lib 1004912 lib 1004913 lib 1004914 lib 1004915 |
16 | lib 1004919 lib 1004920 |
17 | lib 1009014 // processing.face |
18 | lib 1009015 // object detection |
19 | lib 1009016 // xpp (xmlpull implementation) |
20 | |
21 | import com.github.sarxos.webcam.*; |
22 | |
23 | import org.openimaj.image.ImageUtilities; |
24 | import org.openimaj.image.processing.face.detection.DetectedFace; |
25 | import org.openimaj.image.processing.face.detection.HaarCascadeDetector; |
26 | import org.openimaj.image.processing.face.detection.keypoints.FKEFaceDetector; |
27 | |
28 | p { |
29 | final new FaceDetector d; |
30 | d.onDetect.add(new Runnable { |
31 | new LinkedList<Pair<Long, Int>> samples; |
32 | |
33 | public void run() { |
34 | int n = l(d.faces); |
35 | long now = sysNow(); |
36 | samples.add(pair(now, n)); |
37 | while (first(samples).a <= now-toMS(timeout)) |
38 | removeFirst(samples); |
39 | |
40 | ++totalSamples; |
41 | if (totalSamples > skipFirst) { |
42 | double avg = 0; |
43 | for (Pair<Long, Int> p : samples) |
44 | avg += p.b; |
45 | avg /= l(samples); |
46 | |
47 | double threshold = nn == 0 ? 0.7 : 0.3; |
48 | print(avg); |
49 | int newNN = iceil(avg-threshold); |
50 | consoleTitle(newNN + " " + formatDouble(avg, 2)); |
51 | |
52 | if (newNN != nn) { |
53 | nn = newNN; |
54 | onNNChange(); |
55 | } |
56 | } |
57 | } |
58 | }); |
59 | d.start(); |
60 | } |
61 | |
62 | svoid onNNChange() { |
63 | playWAVSnippet( |
64 | //#1013246 |
65 | nn > 0 ? #1013246 : #1013251 |
66 | ); |
67 | } |
68 | |
69 | // original author Bartosz Firyn (SarXos) |
70 | sclass FaceDetector { |
71 | new FKEFaceDetector detector; |
72 | Webcam webcam; |
73 | L<DetectedFace> faces; |
74 | L onDetect = synchroList(); |
75 | |
76 | void start() { |
77 | //webcam = Webcam.getDefault(); // TODO: better web cam selection |
78 | webcam = last(webcam.getWebcams()); |
79 | if (setViewSize) |
80 | webcam.setViewSize(WebcamResolution.VGA.getSize()); |
81 | webcam.open(true); |
82 | |
83 | thread "Face Detection" { |
84 | while licensed { |
85 | if (!webcam.isOpen()) return; |
86 | L<DetectedFace> _faces = synchroList(); |
87 | for (DetectedFace f : detector.detectFaces(ImageUtilities.createFImage(webcam.getImage()))) |
88 | if (f.getConfidence() >= confidenceThreshold) |
89 | _faces.add(f); |
90 | faces = _faces; |
91 | |
92 | print("Have " + n2(faces, "face")); |
93 | pnl(map faceToString(faces)); |
94 | |
95 | pcallFAll(onDetect); |
96 | //_print(); |
97 | } |
98 | } |
99 | } |
100 | } |
101 | |
102 | sS faceToString(DetectedFace f) { |
103 | ret f == null ? "" : f.getBounds() + "*" + f.getConfidence(); |
104 | } |
Began life as a copy of #1013245
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1013252 |
Snippet name: | Face detection FKE Detector |
Eternal ID of this version: | #1013252/4 |
Text MD5: | f40c6243c40f4c5418cce2ac665c8a28 |
Transpilation MD5: | 01052fe71d50dfb0ef3d22f812fab689 |
Author: | stefan |
Category: | javax / desktop / camera |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-12-29 09:53:18 |
Source code size: | 2732 bytes / 104 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 505 / 1055 |
Version history: | 3 change(s) |
Referenced in: | [show references] |