Download Jar. Uses 24524K of libraries. Click here for Pure Java version (6199L/40K).
!7 static double confidenceThreshold = 10; sbool setViewSize = false; static double timeout = 10; static int skipFirst = 9; static int nn = 0, totalSamples; lib 1008985 // webcam lib 1008987 // bridj lib 1004016 // slf4j api // OpenIMAJ lib 1004905 lib 1004906 lib 1004908 lib 1004909 lib 1004910 lib 1004911 lib 1004912 lib 1004913 lib 1004914 lib 1004915 lib 1004919 lib 1004920 lib 1009014 // processing.face lib 1009015 // object detection lib 1009016 // xpp (xmlpull implementation) import com.github.sarxos.webcam.*; import org.openimaj.image.ImageUtilities; import org.openimaj.image.processing.face.detection.DetectedFace; import org.openimaj.image.processing.face.detection.HaarCascadeDetector; p { final new FaceDetector d; d.onDetect.add(new Runnable { new LinkedList<Pair<Long, Int>> samples; public void run() { int n = l(d.faces); long now = sysNow(); samples.add(pair(now, n)); while (first(samples).a <= now-toMS(timeout)) removeFirst(samples); ++totalSamples; if (totalSamples > skipFirst) { double avg = 0; for (Pair<Long, Int> p : samples) avg += p.b; avg /= l(samples); double threshold = nn == 0 ? 0.7 : 0.3; print(avg); int newNN = iceil(avg-threshold); consoleTitle(newNN + " " + formatDouble(avg, 2)); if (newNN != nn) { nn = newNN; onNNChange(); } } } }); d.start(); } svoid onNNChange() { playWAVSnippet( //#1013246 nn > 0 ? #1013246 : #1013250 ); } // original author Bartosz Firyn (SarXos) sclass FaceDetector { new HaarCascadeDetector detector; Webcam webcam; L<DetectedFace> faces; L onDetect = synchroList(); void start() { //webcam = Webcam.getDefault(); // TODO: better web cam selection webcam = last(webcam.getWebcams()); if (setViewSize) webcam.setViewSize(WebcamResolution.VGA.getSize()); webcam.open(true); thread "Face Detection" { while licensed { if (!webcam.isOpen()) return; L<DetectedFace> _faces = synchroList(); for (DetectedFace f : detector.detectFaces(ImageUtilities.createFImage(webcam.getImage()))) if (f.getConfidence() >= confidenceThreshold) _faces.add(f); faces = _faces; print("Have " + n2(faces, "face")); pnl(map faceToString(faces)); pcallFAll(onDetect); //_print(); } } } } sS faceToString(DetectedFace f) { ret f == null ? "" : f.getBounds() + "*" + f.getConfidence(); }
Began life as a copy of #1009812
download show line numbers debug dex old transpilations
Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1013245 |
Snippet name: | Face detection without webcam window |
Eternal ID of this version: | #1013245/21 |
Text MD5: | 3155bc45338d5a49ed619c903bcbf93d |
Transpilation MD5: | 8d7eceb40d118642849180d845ee22dd |
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:40:26 |
Source code size: | 2656 bytes / 103 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 596 / 1381 |
Version history: | 20 change(s) |
Referenced in: | [show references] |