Change score color and store face in scenario rather than extract emotions on each tick
This commit is contained in:
parent
7f0feb346c
commit
162186cea1
4 changed files with 40 additions and 30 deletions
|
@ -19,6 +19,9 @@ public enum Emotion {
|
||||||
|
|
||||||
public float getValueFromFace(Face face)
|
public float getValueFromFace(Face face)
|
||||||
{
|
{
|
||||||
|
if(face == null)
|
||||||
|
return 0f;
|
||||||
|
|
||||||
switch (this) {
|
switch (this) {
|
||||||
case ANGER:
|
case ANGER:
|
||||||
return face.emotions.getAnger();
|
return face.emotions.getAnger();
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package com.rubenvandeven.emotionhero;
|
package com.rubenvandeven.emotionhero;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.media.AudioAttributes;
|
import android.media.AudioAttributes;
|
||||||
|
@ -9,12 +8,9 @@ import android.media.AudioManager;
|
||||||
import android.media.SoundPool;
|
import android.media.SoundPool;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v7.app.ActionBar;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
@ -176,7 +172,6 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL
|
||||||
detector = new CameraDetector(this, CameraDetector.CameraType.CAMERA_FRONT, cameraPreview, 1, Detector.FaceDetectorMode.LARGE_FACES);
|
detector = new CameraDetector(this, CameraDetector.CameraType.CAMERA_FRONT, cameraPreview, 1, Detector.FaceDetectorMode.LARGE_FACES);
|
||||||
detector.setLicensePath("emotionhero_dev.license");
|
detector.setLicensePath("emotionhero_dev.license");
|
||||||
|
|
||||||
detector.setMaxProcessRate(10);
|
|
||||||
detector.setDetectAllEmotions(true);
|
detector.setDetectAllEmotions(true);
|
||||||
detector.setDetectAllAppearances(false);
|
detector.setDetectAllAppearances(false);
|
||||||
detector.setDetectAllEmojis(false);
|
detector.setDetectAllEmojis(false);
|
||||||
|
@ -223,19 +218,13 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL
|
||||||
} else {
|
} else {
|
||||||
hideText(); // hide textView as we want as few elements as possible.
|
hideText(); // hide textView as we want as few elements as possible.
|
||||||
Face face = list.get(0);
|
Face face = list.get(0);
|
||||||
currentScenario.setCurrentAttributeScoresForFace(face);
|
currentScenario.setCurrentFace(face);
|
||||||
scenarioView.setCurrentAttributeScoresForFace(face);
|
scenarioView.setCurrentAttributeScoresForFace(face);
|
||||||
|
|
||||||
// String paramString = "";
|
// if(frame instanceof Frame.ByteArrayFrame)
|
||||||
// paramString += "Anger " + String.format("%02.2f", face.emotions.getAnger()) + "%\n";
|
// {
|
||||||
// paramString += "Contempt " + String.format("%02.2f", face.emotions.getContempt()) + "%\n";
|
// Frame.ByteArrayFrame byteArrayFrame = (Frame.ByteArrayFrame) frame;
|
||||||
// paramString += "Disgust " + String.format("%02.2f", face.emotions.getDisgust()) + "%\n";
|
// }
|
||||||
// paramString += "Fear " + String.format("%02.2f", face.emotions.getFear()) + "%\n";
|
|
||||||
// paramString += "Joy " + String.format("%02.2f", face.emotions.getJoy()) + "%\n";
|
|
||||||
// paramString += "Sadness " + String.format("%02.2f", face.emotions.getSadness()) + "%\n";
|
|
||||||
// paramString += "Surprise " + String.format("%02.2f", face.emotions.getSurprise()) + "%\n";
|
|
||||||
//
|
|
||||||
// paramText.setText(paramString);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
package com.rubenvandeven.emotionhero;
|
package com.rubenvandeven.emotionhero;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.affectiva.android.affdex.sdk.Frame;
|
||||||
import com.affectiva.android.affdex.sdk.detector.Face;
|
import com.affectiva.android.affdex.sdk.detector.Face;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -14,6 +19,8 @@ import java.util.TimerTask;
|
||||||
|
|
||||||
abstract public class Scenario {
|
abstract public class Scenario {
|
||||||
|
|
||||||
|
public Bitmap currentFrameBitmap;
|
||||||
|
|
||||||
static int DESIRED_FPS = 25;
|
static int DESIRED_FPS = 25;
|
||||||
|
|
||||||
float duration = 0;
|
float duration = 0;
|
||||||
|
@ -42,7 +49,7 @@ abstract public class Scenario {
|
||||||
* The scorres in this moment, as to draw them on the screen.
|
* The scorres in this moment, as to draw them on the screen.
|
||||||
* Indexes are Emotion ordinals
|
* Indexes are Emotion ordinals
|
||||||
*/
|
*/
|
||||||
private Map<Emotion, Float> currentAttributeScores = new HashMap<>();
|
private Face currentFace;
|
||||||
|
|
||||||
ArrayList<Target> targets = new ArrayList<>();
|
ArrayList<Target> targets = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -63,6 +70,8 @@ abstract public class Scenario {
|
||||||
* Extra bonus given
|
* Extra bonus given
|
||||||
*/
|
*/
|
||||||
public boolean isSpotOn = false;
|
public boolean isSpotOn = false;
|
||||||
|
// public Bitmap image; //image at time of score
|
||||||
|
public Face face; // face at time of score
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,10 +117,11 @@ abstract public class Scenario {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(target.timestamp <= runningTime) {
|
if(target.timestamp <= runningTime) {
|
||||||
float scored_value = currentAttributeScores.get(target.emotion);
|
float scored_value = target.emotion.getValueFromFace(currentFace);
|
||||||
float required_value = target.value;
|
float required_value = target.value;
|
||||||
Score score = new Score();
|
Score score = new Score();
|
||||||
score.value = Math.round(100 - Math.abs(scored_value-required_value));
|
score.value = Math.round(100 - Math.abs(scored_value-required_value));
|
||||||
|
score.face = currentFace;
|
||||||
scores.add(score);
|
scores.add(score);
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -241,11 +251,9 @@ abstract public class Scenario {
|
||||||
|
|
||||||
|
|
||||||
// TODO: create AttributeScoreCollection class, with this method.
|
// TODO: create AttributeScoreCollection class, with this method.
|
||||||
public void setCurrentAttributeScoresForFace(Face face)
|
public void setCurrentFace(Face face)
|
||||||
{
|
{
|
||||||
for(Emotion emotion: Emotion.values()) {
|
currentFace = face;
|
||||||
currentAttributeScores.put(emotion, emotion.getValueFromFace(face));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFinished()
|
public boolean isFinished()
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
|
import android.graphics.Rect;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
|
@ -38,7 +39,7 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback
|
||||||
private Paint mainPaint = new Paint();
|
private Paint mainPaint = new Paint();
|
||||||
private Paint attrScorePaint = new Paint();
|
private Paint attrScorePaint = new Paint();
|
||||||
private Paint linePaint = new Paint();
|
private Paint linePaint = new Paint();
|
||||||
|
private Paint scorePaint = new Paint();
|
||||||
|
|
||||||
// see: http://blog.danielnadeau.io/2012/01/android-canvas-beginners-tutorial.html
|
// see: http://blog.danielnadeau.io/2012/01/android-canvas-beginners-tutorial.html
|
||||||
class PanelThread extends Thread {
|
class PanelThread extends Thread {
|
||||||
|
@ -60,12 +61,12 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
Canvas c;
|
Canvas c;
|
||||||
while (_run) { //When setRunning(false) occurs, _run is
|
while (_run) { //When setRunning(false) occurs, _run is
|
||||||
c = null; //set to false and loop ends, stopping thread
|
c = null; //set to false and loop ends, stopping thread
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// c = _surfaceHolder.lockCanvas(null);
|
|
||||||
c = _surfaceHolder.lockCanvas(null);
|
c = _surfaceHolder.lockCanvas(null);
|
||||||
synchronized (_surfaceHolder) {
|
synchronized (_surfaceHolder) {
|
||||||
//Insert methods to modify positions of items in onDraw()
|
//Insert methods to modify positions of items in onDraw()
|
||||||
|
@ -85,10 +86,12 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback
|
||||||
getHolder().addCallback(this);
|
getHolder().addCallback(this);
|
||||||
_scenario = s;
|
_scenario = s;
|
||||||
|
|
||||||
|
scorePaint.setColor(Color.YELLOW);
|
||||||
|
scorePaint.setTextSize(50);
|
||||||
|
scorePaint.setTypeface(Typeface.DEFAULT_BOLD);
|
||||||
|
|
||||||
//setup paints for drawing
|
//setup paints for drawing
|
||||||
mainPaint.setColor(Color.GRAY);
|
mainPaint.setColor(Color.GRAY);
|
||||||
mainPaint.setTextSize(40);
|
|
||||||
mainPaint.setTypeface(Typeface.SANS_SERIF);
|
|
||||||
|
|
||||||
linePaint.setColor(Color.GRAY);
|
linePaint.setColor(Color.GRAY);
|
||||||
linePaint.setStrokeWidth(5);
|
linePaint.setStrokeWidth(5);
|
||||||
|
@ -180,15 +183,22 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback
|
||||||
float diff_y = sec_height * _scenario.getTime();
|
float diff_y = sec_height * _scenario.getTime();
|
||||||
|
|
||||||
for(Scenario.Target target: _scenario.getTargets()) {
|
for(Scenario.Target target: _scenario.getTargets()) {
|
||||||
Paint targetPaint = (target.score == null) ? emoPaints.get(target.emotion) : emoScoredPaints.get(target.emotion);
|
// Paint targetPaint = (target.score == null) ? emoPaints.get(target.emotion) : emoScoredPaints.get(target.emotion);
|
||||||
float cy = bottomline_height - (target.timestamp * sec_height) + diff_y;
|
float cy = bottomline_height - (target.timestamp * sec_height) + diff_y;
|
||||||
|
|
||||||
float cx = padding_left + (step_y * target.emotion.ordinal() + step_y / 2);
|
float cx = padding_left + (step_y * target.emotion.ordinal() + step_y / 2);
|
||||||
|
|
||||||
canvas.drawCircle(cx, cy, max_ball_radius * target.value/100, targetPaint);
|
canvas.drawCircle(cx, cy, max_ball_radius * target.value/100, emoPaints.get(target.emotion));
|
||||||
|
|
||||||
if(target.score != null) {
|
if(target.score != null) {
|
||||||
canvas.drawText(Float.toString(target.score.value), cx, cy, targetPaint);
|
canvas.drawText(Float.toString(target.score.value), cx, cy, emoPaints.get(target.emotion));
|
||||||
|
canvas.drawCircle(cx, cy, max_ball_radius * target.score.value/100, emoScoredPaints.get(target.emotion));
|
||||||
|
|
||||||
|
// TODO: Use target.score.face to set Rect src.
|
||||||
|
// if(target.score.image != null) {
|
||||||
|
// Rect rect = new Rect((int) cx-10, (int) cy-10, (int) cx+10, (int) cy+10);
|
||||||
|
// canvas.drawBitmap(target.score.image, null, rect, null);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -196,7 +206,7 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback
|
||||||
// canvas.drawText(target_text, cx, y_pos + diff_y , emoPaint);
|
// canvas.drawText(target_text, cx, y_pos + diff_y , emoPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas.drawText("Total: " + Float.toString(_scenario.getTotalScore()), 50, 50, mainPaint);
|
canvas.drawText("Total: " + Float.toString(_scenario.getTotalScore()), 50, 50, scorePaint);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue