Skip to content

Commit 18ff20c

Browse files
committed
Add smiling expression tracking support for LookAtMe 2.0, current issue is easily adding the status for the android app developer to access
1 parent 84ad25a commit 18ff20c

File tree

9 files changed

+105
-22
lines changed

9 files changed

+105
-22
lines changed

.idea/caches/build_file_checksums.ser

50 Bytes
Binary file not shown.

.idea/gradle.xml

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+13-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LookAtMe/src/main/java/com/pd/lookatme/LookAtMe.java

+76-14
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
public class LookAtMe extends VideoView {
2626

2727
private String status = "";
28+
private String smilingStatus = "";
2829
private CameraSource cameraSource;
2930
private Context activityContext;
31+
private int timesSmiled = 0;
3032

3133
public void init(Context activityContext) {
3234
this.activityContext = activityContext;
@@ -43,6 +45,11 @@ public void init(Context activityContext, String mode){
4345
createCameraSource(mode);
4446
}
4547

48+
public void initWithSmilingStatus(Context activityContext){
49+
this.activityContext = activityContext;
50+
createCameraSourceWithSmilingStatus();
51+
}
52+
4653
public void resume(){
4754
if (cameraSource != null) {
4855
try {
@@ -51,7 +58,6 @@ public void resume(){
5158
Toast.makeText(activityContext, "Grant Permission and restart app", Toast.LENGTH_SHORT).show();
5259
}
5360
cameraSource.start();
54-
//Log.d("some8","Starting first");
5561
}
5662
catch (IOException e) {
5763
e.printStackTrace();
@@ -62,11 +68,10 @@ public void resume(){
6268
public void paused(){
6369
if (cameraSource != null) {
6470
cameraSource.stop();
65-
//Log.d("some6","stopped here");
6671
}
72+
6773
if (this.isPlaying()) {
6874
this.pause();
69-
//Log.d("some7","Paused() here");
7075
}
7176
}
7277

@@ -114,17 +119,23 @@ public String getStatus(){
114119
return status;
115120
}
116121

117-
public void setLookMe(){
118-
//Log.d("this is found","camerasource is " + cameraSource);
122+
public String getSmilingStatus(){
123+
return smilingStatus;
124+
}
125+
126+
public int getTimesSmiled(){
127+
return timesSmiled;
128+
}
119129

130+
public void setLookMe(){
120131
try {
121132
if (ActivityCompat.checkSelfPermission(activityContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
122133
ActivityCompat.requestPermissions((Activity) activityContext, new String[]{Manifest.permission.CAMERA}, 1);
123134

124135
Toast.makeText(activityContext, "Grant Permission and restart app", Toast.LENGTH_SHORT).show();
125136
}
126137
cameraSource.start();
127-
Log.d("ReadThis", "camerasource started, outside");
138+
Log.d("ReadThis", "camera-source started, outside");
128139
}
129140
catch (IOException e) {
130141
e.printStackTrace();
@@ -142,17 +153,14 @@ private EyesTracker() {
142153
@Override
143154
public void onUpdate(Detector.Detections<Face> detections, Face face) {
144155
if (face.getIsLeftEyeOpenProbability() > THRESHOLD || face.getIsRightEyeOpenProbability() > THRESHOLD) {
145-
// Log.d("some9", "Eyes Detecting");
146156

147157
if (!isPlaying())
148158
start();
149159

150160
status = "Eyes Detected and open, so video continues";
151-
//Log.d("some3", "Started due to eyes detected");
152161
}
153162
else {
154163
if (isPlaying()){
155-
// Log.d("some4","Paused due to eyes closed");
156164
pause();
157165
}
158166

@@ -165,7 +173,43 @@ public void onMissing(Detector.Detections<Face> detections) {
165173
super.onMissing(detections);
166174
status = "Face Not Detected!";
167175
pause();
168-
//Log.d("some5","Face is Missing");
176+
}
177+
178+
@Override
179+
public void onDone() {
180+
super.onDone();
181+
}
182+
}
183+
184+
private class FaceTracker extends Tracker<Face> {
185+
private final float THRESHOLD = 0.75f;
186+
187+
private FaceTracker(){
188+
189+
}
190+
191+
@Override
192+
public void onUpdate(Detector.Detections<Face> detections, Face face) {
193+
if(face.getIsSmilingProbability() > THRESHOLD) {
194+
smilingStatus = "smiling";
195+
timesSmiled++;
196+
Log.d("smile", String.valueOf(getTimesSmiled()));
197+
198+
if(timesSmiled > 100){
199+
timesSmiled -= 100;
200+
201+
Log.d("Smiling","You smiled for 100 frames!");
202+
203+
}
204+
}
205+
else{
206+
smilingStatus = "Not smiling";
207+
}
208+
}
209+
210+
@Override
211+
public void onMissing(Detector.Detections<Face> detections) {
212+
super.onMissing(detections);
169213
}
170214

171215
@Override
@@ -188,7 +232,27 @@ private void createCameraSource() {
188232
}
189233
else
190234
cameraSource.start();
191-
//Log.d("ReadThis", "camerasource started, inside");
235+
}
236+
catch (IOException e) {
237+
e.printStackTrace();
238+
}
239+
}
240+
241+
private void createCameraSourceWithSmilingStatus() {
242+
FaceDetector detector = new FaceDetector.Builder(activityContext).setTrackingEnabled(true).setClassificationType(FaceDetector.ALL_CLASSIFICATIONS).setMode(FaceDetector.FAST_MODE).build();
243+
244+
FaceTracker faceTracker = new FaceTracker();
245+
detector.setProcessor(new LargestFaceFocusingProcessor(detector, faceTracker));
246+
247+
cameraSource = new CameraSource.Builder(activityContext, detector).setRequestedPreviewSize(1024, 768).setFacing(CameraSource.CAMERA_FACING_FRONT).setRequestedFps(30.0f).build();
248+
249+
try {
250+
if (ActivityCompat.checkSelfPermission(activityContext, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
251+
ActivityCompat.requestPermissions((Activity) activityContext, new String[]{Manifest.permission.CAMERA}, 1);
252+
Toast.makeText(activityContext, "Grant Permission and restart app", Toast.LENGTH_SHORT).show();
253+
}
254+
else
255+
cameraSource.start();
192256
}
193257
catch (IOException e) {
194258
e.printStackTrace();
@@ -217,7 +281,6 @@ private void createCameraSource(String mode) {
217281
}
218282
else
219283
cameraSource.start();
220-
//Log.d("ReadThis", "camerasource started, inside");
221284
}
222285
catch (IOException e) {
223286
e.printStackTrace();
@@ -226,7 +289,7 @@ private void createCameraSource(String mode) {
226289

227290
private void createCameraSource(String mode, String cameraFace) {
228291

229-
// Let the mode be fast or accurate
292+
// Let the mode be fast or accurate and
230293
// Let the cameraFace be front or back
231294

232295
FaceDetector detector;
@@ -250,7 +313,6 @@ private void createCameraSource(String mode, String cameraFace) {
250313
}
251314
else
252315
cameraSource.start();
253-
//Log.d("ReadThis", "camerasource started, inside");
254316
}
255317
catch (IOException e) {
256318
e.printStackTrace();

app/src/main/java/com/pd/lookme/MainActivity.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import android.net.Uri;
44
import android.support.v7.app.AppCompatActivity;
55
import android.os.Bundle;
6+
import android.util.Log;
67
import android.widget.TextView;
8+
import android.widget.Toast;
79
import android.widget.VideoView;
810

911
import com.pd.lookatme.LookAtMe;
@@ -21,12 +23,14 @@ protected void onCreate(Bundle savedInstanceState) {
2123
lookAtMe = findViewById(R.id.lookme);
2224
textView = findViewById(R.id.textView2);
2325

24-
lookAtMe.init(this);
26+
//lookAtMe.init(this); for eye tracking status
27+
lookAtMe.initWithSmilingStatus(this); // for smiling status of the user
2528
lookAtMe.setVideoURI(Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.videoplayback));
2629

2730
lookAtMe.start();
2831
lookAtMe.setLookMe();
2932

33+
3034
this.showStatus();
3135
}
3236

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.1.4'
10+
classpath 'com.android.tools.build:gradle:3.3.2'
1111

1212

1313
// NOTE: Do not place your application dependencies here; they belong
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Mar 02 07:55:19 CET 2019
1+
#Mon May 13 10:18:57 CEST 2019
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include ':app', ':LookAtMe'
1+
include ':app', ':LookAtMe', ':lookatad'

0 commit comments

Comments
 (0)