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

104
LINES

< > BotCompany Repo | #1013252 // Face detection FKE Detector

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 24524K of libraries. Click here for Pure Java version (6201L/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;
import org.openimaj.image.processing.face.detection.keypoints.FKEFaceDetector;

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 : #1013251
  );
}

// original author Bartosz Firyn (SarXos)
sclass FaceDetector {
	new FKEFaceDetector 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();
}

Author comment

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: 379 / 756
Version history: 3 change(s)
Referenced in: [show references]