Added image files for UI update and removed unused ones
|
@ -26,6 +26,7 @@ import com.affectiva.android.affdex.sdk.detector.Face;
|
|||
public class DrawingView extends SurfaceView implements SurfaceHolder.Callback {
|
||||
|
||||
class PointFArraySharer {
|
||||
boolean isPointsMirrored = false;
|
||||
PointF[] nextPointsToDraw = null;
|
||||
}
|
||||
|
||||
|
@ -88,9 +89,10 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
}
|
||||
|
||||
//Updates thread with latest points returned by the onImageResults() event.
|
||||
public void updatePoints(PointF[] pointList) {
|
||||
public void updatePoints(PointF[] pointList, boolean isPointsMirrored) {
|
||||
synchronized (sharer) {
|
||||
sharer.nextPointsToDraw = pointList;
|
||||
sharer.isPointsMirrored = isPointsMirrored;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,10 +141,12 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
|
||||
void draw(Canvas c) {
|
||||
PointF[] points;
|
||||
boolean mirrorPoints;
|
||||
synchronized (sharer) {
|
||||
if (sharer.nextPointsToDraw == null)
|
||||
return;
|
||||
points = sharer.nextPointsToDraw;
|
||||
mirrorPoints = sharer.isPointsMirrored;
|
||||
}
|
||||
|
||||
//Coordinates around which to draw bounding box.
|
||||
|
@ -155,7 +159,12 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
|
||||
//transform from the camera coordinates to our screen coordinates
|
||||
//The camera preview is displayed as a mirror, so X pts have to be mirrored back.
|
||||
float x = (config.imageWidth - points[i].x - 1) * config.screenToImageRatio;
|
||||
float x;
|
||||
if (mirrorPoints) {
|
||||
x = (config.imageWidth - points[i].x) * config.screenToImageRatio;
|
||||
} else {
|
||||
x = (points[i].x) * config.screenToImageRatio;
|
||||
}
|
||||
float y = (points[i].y)* config.screenToImageRatio;
|
||||
|
||||
//We determine the left-most, top-most, right-most, and bottom-most points to draw the bounding box around.
|
||||
|
@ -394,8 +403,8 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback {
|
|||
drawingThread.setMetrics(roll,yaw,pitch,interOcDis,valence);
|
||||
}
|
||||
|
||||
public void updatePoints(PointF[] points) {
|
||||
drawingThread.updatePoints(points);
|
||||
public void updatePoints(PointF[] points, boolean isPointsMirrored) {
|
||||
drawingThread.updatePoints(points, isPointsMirrored);
|
||||
}
|
||||
|
||||
public void invalidatePoints(){
|
||||
|
|
|
@ -67,7 +67,7 @@ import com.affectiva.android.affdex.sdk.detector.Face;
|
|||
*/
|
||||
|
||||
public class MainActivity extends Activity
|
||||
implements Detector.FaceListener, Detector.ImageListener, View.OnTouchListener, CameraDetector.OnCameraEventListener {
|
||||
implements Detector.FaceListener, Detector.ImageListener, View.OnTouchListener, CameraDetector.CameraEventListener {
|
||||
|
||||
private static final String LOG_TAG = "Affectiva";
|
||||
public static final int NUM_METRICS_DISPLAYED = 6;
|
||||
|
@ -114,6 +114,7 @@ public class MainActivity extends Activity
|
|||
int cameraPreviewWidth = 0;
|
||||
int cameraPreviewHeight = 0;
|
||||
CameraDetector.CameraType cameraType;
|
||||
boolean mirrorPoints = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -146,10 +147,14 @@ public class MainActivity extends Activity
|
|||
}
|
||||
|
||||
//TODO: change this to be taken from settings
|
||||
if (isBackFacingCameraDetected)
|
||||
if (isBackFacingCameraDetected) {
|
||||
cameraType = CameraDetector.CameraType.CAMERA_BACK;
|
||||
if (isFrontFacingCameraDetected)
|
||||
mirrorPoints = false;
|
||||
}
|
||||
if (isFrontFacingCameraDetected) {
|
||||
cameraType = CameraDetector.CameraType.CAMERA_FRONT;
|
||||
mirrorPoints = true;
|
||||
}
|
||||
}
|
||||
|
||||
void initializeUI() {
|
||||
|
@ -257,6 +262,7 @@ public class MainActivity extends Activity
|
|||
restoreApplicationSettings();
|
||||
setMenuVisible(true);
|
||||
isMenuShowingForFirstTime = true;
|
||||
mainWindowResumedTasks();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -335,23 +341,6 @@ public class MainActivity extends Activity
|
|||
numberOfFrames = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* We want to start the camera as late as possible, so it does not freeze the application before it has been visually resumed.
|
||||
* We thus post a runnable that will take care of starting the camera.
|
||||
* We also reset variables used to calculate the Processed Frames Per Second.
|
||||
*/
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
if (hasFocus && isFrontFacingCameraDetected) {
|
||||
cameraView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mainWindowResumedTasks();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void mainWindowResumedTasks() {
|
||||
|
||||
startDetector();
|
||||
|
@ -360,6 +349,7 @@ public class MainActivity extends Activity
|
|||
progressBarLayout.setVisibility(View.GONE);
|
||||
}
|
||||
resetFPSCalculations();
|
||||
|
||||
cameraView.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -402,7 +392,6 @@ public class MainActivity extends Activity
|
|||
void performFaceDetectionStoppedTasks() {
|
||||
leftMetricsLayout.animate().alpha(0); //make left and right metrics disappear
|
||||
rightMetricsLayout.animate().alpha(0);
|
||||
drawingView.updatePoints(null);
|
||||
resetFPSCalculations(); //Since the FPS may be different whether a face is being tracked or not, reset variables.
|
||||
}
|
||||
|
||||
|
@ -421,7 +410,7 @@ public class MainActivity extends Activity
|
|||
|
||||
//If faces.size() is 0, we received a frame in which no face was detected
|
||||
if (faces.size() == 0) {
|
||||
drawingView.updatePoints(null); //the drawingView takes null points to mean it doesn't have to draw anything
|
||||
drawingView.updatePoints(null, mirrorPoints); //the drawingView takes null points to mean it doesn't have to draw anything
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -441,7 +430,7 @@ public class MainActivity extends Activity
|
|||
*/
|
||||
if (drawingView.getDrawPointsEnabled() || drawingView.getDrawMeasurementsEnabled()) {
|
||||
drawingView.setMetrics(face.measurements.orientation.getRoll(), face.measurements.orientation.getYaw(), face.measurements.orientation.getPitch(), face.measurements.getInterocularDistance(), face.emotions.getValence());
|
||||
drawingView.updatePoints(face.getFacePoints());
|
||||
drawingView.updatePoints(face.getFacePoints(),mirrorPoints);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -589,16 +578,15 @@ public class MainActivity extends Activity
|
|||
}
|
||||
|
||||
public void settings_button_click(View view) {
|
||||
startActivity(new Intent(this,SettingsActivity.class));
|
||||
startActivity(new Intent(this, SettingsActivity.class));
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void onCameraStarted(boolean b, Throwable throwable) {
|
||||
if (throwable != null) {
|
||||
Toast.makeText(this,"Failed to start camera.",Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraSizeSelected(int cameraWidth, int cameraHeight, ROTATE rotation) {
|
||||
|
@ -653,12 +641,14 @@ public class MainActivity extends Activity
|
|||
if (cameraType == CameraDetector.CameraType.CAMERA_FRONT) {
|
||||
if (isBackFacingCameraDetected) {
|
||||
cameraType = CameraDetector.CameraType.CAMERA_BACK;
|
||||
mirrorPoints = false;
|
||||
} else {
|
||||
Toast.makeText(this,"No back-facing camera found",Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else if (cameraType == CameraDetector.CameraType.CAMERA_BACK) {
|
||||
if (isFrontFacingCameraDetected) {
|
||||
cameraType = CameraDetector.CameraType.CAMERA_FRONT;
|
||||
mirrorPoints = true;
|
||||
} else {
|
||||
Toast.makeText(this,"No front-facing camera found",Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
|
Before Width: | Height: | Size: 205 B |
Before Width: | Height: | Size: 216 B |
Before Width: | Height: | Size: 365 B |
Before Width: | Height: | Size: 379 B |
Before Width: | Height: | Size: 155 B |
Before Width: | Height: | Size: 158 B |
Before Width: | Height: | Size: 248 B |
Before Width: | Height: | Size: 259 B |
Before Width: | Height: | Size: 272 B |
Before Width: | Height: | Size: 305 B |
Before Width: | Height: | Size: 451 B |
Before Width: | Height: | Size: 472 B |
Before Width: | Height: | Size: 411 B |
Before Width: | Height: | Size: 472 B |
Before Width: | Height: | Size: 674 B |
Before Width: | Height: | Size: 713 B |
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/transluscent_circle"
|
||||
android:maxLevel="0"/>
|
||||
<item android:drawable="@drawable/ic_switch_camera_black_48dp"
|
||||
android:maxLevel="1"
|
||||
/>
|
||||
</layer-list>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/transluscent_circle"
|
||||
android:maxLevel="0"/>
|
||||
<item android:drawable="@drawable/ic_switch_camera_white_48dp"
|
||||
android:maxLevel="1"
|
||||
/>
|
||||
</layer-list>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:drawable="@drawable/camera_button_pressed"/>
|
||||
<item android:drawable="@drawable/camera_button_not_pressed" />
|
||||
<item android:state_pressed="true" android:drawable="@drawable/switch_camera_button"/>
|
||||
<item android:drawable="@drawable/switch_camera_button_pressed" />
|
||||
</selector>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/transluscent_circle"
|
||||
android:maxLevel="0"/>
|
||||
<item android:drawable="@drawable/ic_more_vert_black_48dp"
|
||||
android:maxLevel="1"
|
||||
/>
|
||||
</layer-list>
|
|
@ -1,8 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@drawable/transluscent_circle"
|
||||
android:maxLevel="0"/>
|
||||
<item android:drawable="@drawable/ic_more_vert_white_48dp"
|
||||
android:maxLevel="1"
|
||||
/>
|
||||
</layer-list>
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:state_pressed="true" android:drawable="@drawable/settings_button_pressed"/>
|
||||
<item android:drawable="@drawable/settings_button_not_pressed" />
|
||||
<item android:state_pressed="true" android:drawable="@drawable/settings_button_pressed_1"/>
|
||||
<item android:drawable="@drawable/settings_button" />
|
||||
</selector>
|
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
<solid
|
||||
android:color="#88FFFFFF"/>
|
||||
<corners
|
||||
android:radius="24dp"/>
|
||||
<size android:height="48dp"
|
||||
android:width="48dp"/>
|
||||
</shape>
|