Frame snapshot sync fix (hopefully) and other randomisation of snapshot and only send 3 snaps (no mouth_right anymore)

This commit is contained in:
Ruben 2016-09-20 17:23:49 +01:00
parent e8b4a03c9d
commit 907e9005af
5 changed files with 49 additions and 27 deletions

View file

@ -37,7 +37,7 @@
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -406,27 +406,27 @@ public class ApiRestClient {
// RIGHT MOUTH CORNER
// Crop: http://stackoverflow.com/a/31698091
// reuse margin of brows to make a square image
left = (int) hit.points[24].x - margin;
right = (int) hit.points[24].x + 3 * margin;
top = (int) hit.points[24].y - 2 * margin;
bottom = (int) hit.points[24].y + 2 * margin;
Rect rect3 = new Rect(left, top, right, bottom);
// Be sure that there is at least 1px to slice.
if(!(rect3.left < rect3.right && rect3.top < rect3.bottom)) {
Log.e("API", "Error in point positions."+" left: " + rect3.left + " right: " + rect3.right + " top: " + rect3.top + " bottom: " + rect3.bottom );
continue; // strange bug... skip it and drop the file anyway
}
croppedBmp = Bitmap.createBitmap(rect3.right-rect3.left, rect3.bottom-rect3.top, Bitmap.Config.ARGB_8888);
// draw source bitmap into resulting image at given position:
new Canvas(croppedBmp).drawBitmap(img, -rect3.left, -rect3.top, null);
ByteArrayOutputStream stream3 = new ByteArrayOutputStream();
croppedBmp.compress(Bitmap.CompressFormat.JPEG, 90, stream3);
byte[] imageBytes3 = stream3.toByteArray();
params.put(hit.remoteId + ":mouth_right", new ByteArrayInputStream(imageBytes3), hit.remoteId + "-mouth_right.jpg", "image/jpeg");
Log.v("API", "add param: " + hit.remoteId + ":mouth_right - length:" + imageBytes.length );
// left = (int) hit.points[24].x - margin;
// right = (int) hit.points[24].x + 3 * margin;
// top = (int) hit.points[24].y - 2 * margin;
// bottom = (int) hit.points[24].y + 2 * margin;
// Rect rect3 = new Rect(left, top, right, bottom);
//// Be sure that there is at least 1px to slice.
// if(!(rect3.left < rect3.right && rect3.top < rect3.bottom)) {
// Log.e("API", "Error in point positions."+" left: " + rect3.left + " right: " + rect3.right + " top: " + rect3.top + " bottom: " + rect3.bottom );
// continue; // strange bug... skip it and drop the file anyway
// }
//
// croppedBmp = Bitmap.createBitmap(rect3.right-rect3.left, rect3.bottom-rect3.top, Bitmap.Config.ARGB_8888);
//// draw source bitmap into resulting image at given position:
// new Canvas(croppedBmp).drawBitmap(img, -rect3.left, -rect3.top, null);
//
// ByteArrayOutputStream stream3 = new ByteArrayOutputStream();
// croppedBmp.compress(Bitmap.CompressFormat.JPEG, 90, stream3);
// byte[] imageBytes3 = stream3.toByteArray();
//
// params.put(hit.remoteId + ":mouth_right", new ByteArrayInputStream(imageBytes3), hit.remoteId + "-mouth_right.jpg", "image/jpeg");
// Log.v("API", "add param: " + hit.remoteId + ":mouth_right - length:" + imageBytes.length );
// LEFT MOUTH CORNER (doing whole mouth :-)

View file

@ -273,6 +273,8 @@ public class GameOpenHelper extends SQLiteOpenHelper {
}
saveAchievementsForGame(game);
db.close();
}
public Game[] getGamesForLevel(int lvl_id) {

View file

@ -258,9 +258,8 @@ public class GamingActivity extends AppCompatActivity implements Detector.ImageL
} else {
hideText(); // hide textView as we want as few elements as possible.
Face face = list.get(0);
currentScenario.setCurrentFace(face);
currentScenario.setCurrentFaceAndFrame(face, (Frame.ByteArrayFrame) frame);
scenarioView.setCurrentAttributeScoresForFace(face);
currentScenario.currentFrame = (Frame.ByteArrayFrame) frame;
}
}

View file

@ -13,9 +13,14 @@ import com.affectiva.android.affdex.sdk.Frame;
import com.affectiva.android.affdex.sdk.detector.Face;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
@ -115,6 +120,12 @@ public class Scenario {
*/
protected boolean lostFace = false;
public static int MAX_SNAPSHOTS = 5;
/**
* Which targets to capture an image of
*/
List<Target> snapTargets;
/**
* The scorres in this moment, as to draw them on the screen.
* Indexes are Emotion ordinals
@ -165,6 +176,16 @@ public class Scenario {
rs = RenderScript.create(_activity);
squarePaint = new Paint();
squarePaint.setColor(Color.YELLOW);
// determine before start which targets will be stored and send
// only do it randomly so we don't need to do ALL and yet have spread across the level.
snapTargets = pickNRandom(targets, MAX_SNAPSHOTS);
}
public static List<Target> pickNRandom(List<Target> lst, int n) {
List<Target> copy = new LinkedList<Target>(lst);
Collections.shuffle(copy);
return copy.subList(0, n);
}
/**
@ -208,7 +229,7 @@ public class Scenario {
Bitmap outputBitmap = null;
if(currentFrame != null && bitmapCount < 5) {
if(currentFrame != null && snapTargets.contains(target) ) {
// convert NV21 byteArrayFrame from camera to RGB bitmap.
Frame.ByteArrayFrame byteArrayFrame = (Frame.ByteArrayFrame) currentFrame;
outputBitmap = Nv21Image.nv21ToBitmap(rs, byteArrayFrame.getByteArray(), byteArrayFrame.getWidth(), byteArrayFrame.getHeight());
@ -222,7 +243,6 @@ public class Scenario {
matrix.postRotate((int) rotation.toDouble());
// int width = rotation == Frame.ROTATE.BY_180 ? outputBitmap.getWidth() : outputBitmap.getHeight();
// int height = rotation == Frame.ROTATE.BY_180 ? outputBitmap.getHeight() : outputBitmap.getWidth();
// TODO: max 5 bitmaps
outputBitmap = Bitmap.createBitmap(outputBitmap , 0, 0, outputBitmap .getWidth(), outputBitmap .getHeight(), matrix, true);
}
@ -382,9 +402,10 @@ public class Scenario {
// TODO: create AttributeScoreCollection class, with this method.
public void setCurrentFace(Face face)
public synchronized void setCurrentFaceAndFrame(Face face, Frame.ByteArrayFrame frame)
{
currentFace = face;
currentFrame = frame;
}
public boolean isFinished()