@@ -1,5 +1,11 @@ | |||
package com.aispeech.nativedemo.entity; | |||
import static com.aispeech.nativedemo.entity.PositionEnum.POSITION_LEFT_TO_LEFT; | |||
import static com.aispeech.nativedemo.entity.PositionEnum.POSITION_LEFT_TO_RIGHT; | |||
import static com.aispeech.nativedemo.entity.PositionEnum.POSITION_ONCE; | |||
import static com.aispeech.nativedemo.entity.PositionEnum.POSITION_RIGHT_TO_LEFT; | |||
import static com.aispeech.nativedemo.entity.PositionEnum.POSITION_RIGHT_TO_RIGHT; | |||
import android.graphics.Bitmap; | |||
import android.util.Log; | |||
@@ -10,6 +16,10 @@ import org.json.JSONObject; | |||
public class PersonInfo { | |||
private static final long LEAVE_DURATION = 60 * 1000; | |||
private static final int DELTA_X = 20; | |||
private static final int RIGHT_MAX = 1700; | |||
private static final int MAX_LENGTH = 800; | |||
private static final int MAX_GREETING_DURATION = 1000; | |||
public String id; // eid | |||
public String name; //昵称 | |||
public String tag; //人物类别 | |||
@@ -41,7 +51,7 @@ public class PersonInfo { | |||
* 初始值 0:从未出现 | |||
* 方向 1:从左到屏幕中静止 左右 (包含折现) 2:从右走到屏幕中(包含折现) 右左 3:左右左 4. 右左右 | |||
* 最终判定值配合是否在屏幕中 1.1:从左到右走出屏幕 2.1:从右到左走出屏幕 3.1:左右左后走出屏幕4.1右左右走出屏幕 | |||
* 5.只出现一次 6.出现并静止 | |||
* 5.只出现一次 6.出现并静止 最左 142 517 最右1959 1887 | |||
*/ | |||
public PositionEnum position_type; // directionType | |||
public int face_x1; | |||
@@ -82,7 +92,7 @@ public class PersonInfo { | |||
this.last_in_time = startTime; | |||
this.is_in_view = 1; | |||
this.hasBeenGreeted = false; | |||
this.position_type = PositionEnum.POSITION_ONCE; | |||
this.position_type = POSITION_ONCE; | |||
if (att.hd_bd > 0) { | |||
this.startBodyPositionX = (result.bd_x1 + result.bd_x2) / 2; | |||
} | |||
@@ -126,8 +136,17 @@ public class PersonInfo { | |||
obj.put("bd_x", (result.bd_x1 + result.bd_x2) / 2); | |||
long time = System.currentTimeMillis(); | |||
obj.put("ts", time / 1000 + "." + time % 1000); | |||
obj.put("lastInTime", last_in_time); | |||
obj.put("lastInTime", last_in_time); // 进入屏幕的时间 | |||
obj.put("lastGreetTime", last_greet_time); // 打招呼的时间 | |||
obj.put("directionType", position_type.ordinal()); // 运动的方向 | |||
obj.put("currentBodyPositionX", currentBodyPositionX); // 运动的方向 | |||
obj.put("previewBodyPositionX", previewBodyPositionX); // 运动的方向 | |||
obj.put("startBodyPositionX", startBodyPositionX); // 运动的方向 | |||
obj.put("startFacePositionX", startFacePositionX); // 运动的方向 | |||
obj.put("previewFacePositionX", previewFacePositionX); // 运动的方向 | |||
obj.put("currentFacePositionX", currentFacePositionX); // 运动的方向 | |||
obj.put("hasBeenGreeted", hasBeenGreeted); | |||
obj.put("isInView", is_in_view); | |||
return obj.toString(); | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
@@ -147,6 +166,7 @@ public class PersonInfo { | |||
this.startBodyPositionX = -1; | |||
this.previewBodyPositionX = -1; | |||
this.currentBodyPositionX = -1; | |||
this.position_type = POSITION_ONCE; | |||
this.hasBeenGreeted = false; | |||
} else { | |||
this.previewFacePositionX = this.currentFacePositionX; | |||
@@ -185,10 +205,14 @@ public class PersonInfo { | |||
} | |||
if (att.hd_fa > 0) { | |||
this.currentFacePositionX = (face_x1 + face_x2) / 2; | |||
if (!hasDirection && startFacePositionX >= 0 && previewFacePositionX >= 0) { | |||
calculateDirection(startFacePositionX, previewFacePositionX, currentFacePositionX); | |||
} else if (!hasDirection && startBodyPositionX >= 0) { | |||
calculateDirection(currentFacePositionX, previewBodyPositionX, currentFacePositionX); | |||
if (startFacePositionX >= 0 && previewFacePositionX >= 0) { | |||
if (!hasDirection) { | |||
calculateDirection(startFacePositionX, previewFacePositionX, currentFacePositionX); | |||
} | |||
} else if (startFacePositionX >= 0) { | |||
if (!hasDirection) { | |||
calculateDirection(startFacePositionX, currentFacePositionX); | |||
} | |||
} else { | |||
startFacePositionX = currentFacePositionX; | |||
} | |||
@@ -199,32 +223,36 @@ public class PersonInfo { | |||
private void calculateDirection(int startBodyPositionX, int currentBodyPositionX) { | |||
int deltaX = currentBodyPositionX - startBodyPositionX; | |||
if (deltaX > 0) { | |||
if (deltaX >= DELTA_X) { | |||
position_type = PositionEnum.POSITION_LEFT_TO_RIGHT; | |||
} else if (deltaX == 0) { | |||
position_type = PositionEnum.POSITION_WAITING; | |||
} else { | |||
} else if (deltaX <= -DELTA_X) { | |||
position_type = PositionEnum.POSITION_RIGHT_TO_LEFT; | |||
} else { | |||
position_type = PositionEnum.POSITION_WAITING; | |||
} | |||
} | |||
private void calculateDirection(int startBodyPositionX, int previewBodyPositionX, int currentBodyPositionX) { | |||
int deltaCurrentX = currentBodyPositionX - previewBodyPositionX; | |||
int deltaX = previewBodyPositionX - startBodyPositionX; | |||
if (deltaCurrentX > 0) { | |||
if (deltaX > 0) { | |||
if (deltaCurrentX >= DELTA_X) { | |||
if (deltaX >= DELTA_X) { | |||
position_type = PositionEnum.POSITION_LEFT_TO_RIGHT; | |||
} else { | |||
} else if (deltaX <= -DELTA_X) { | |||
position_type = PositionEnum.POSITION_RIGHT_TO_RIGHT; | |||
} else { | |||
position_type = PositionEnum.POSITION_LEFT_TO_RIGHT; | |||
} | |||
} else if (deltaX < 0) { | |||
if (deltaX < 0) { | |||
} else if (deltaX <= -DELTA_X) { | |||
if (deltaX <= -DELTA_X) { | |||
position_type = PositionEnum.POSITION_RIGHT_TO_LEFT; | |||
} else { | |||
} else if (deltaX >= DELTA_X){ | |||
position_type = PositionEnum.POSITION_LEFT_TO_LEFT; | |||
} else { | |||
position_type = PositionEnum.POSITION_RIGHT_TO_LEFT; | |||
} | |||
} else { | |||
position_type = PositionEnum.POSITION_WAITING; | |||
calculateDirection(startBodyPositionX, previewBodyPositionX); | |||
} | |||
} | |||
@@ -243,4 +271,28 @@ public class PersonInfo { | |||
return 1; | |||
} | |||
public boolean hasDirection() { | |||
long time = System.currentTimeMillis(); | |||
if (position_type == POSITION_LEFT_TO_LEFT || position_type == POSITION_RIGHT_TO_LEFT) { | |||
return true; | |||
} | |||
if (position_type == POSITION_LEFT_TO_RIGHT || position_type == POSITION_RIGHT_TO_RIGHT) { | |||
if (startBodyPositionX > MAX_LENGTH && ((currentBodyPositionX - startBodyPositionX) > MAX_LENGTH)) { | |||
return true; | |||
} else if (startFacePositionX > MAX_LENGTH && ((currentFacePositionX - startFacePositionX) > MAX_LENGTH)) { | |||
return true; | |||
} else { | |||
return false; | |||
} | |||
} | |||
if (startBodyPositionX != -1 && currentBodyPositionX != -1 | |||
&& startBodyPositionX != currentBodyPositionX && ((time - last_in_time) > MAX_GREETING_DURATION)) { | |||
return true; | |||
} | |||
if (startFacePositionX != -1 && currentFacePositionX != -1 | |||
&& startFacePositionX != currentFacePositionX && ((time - last_in_time) > MAX_GREETING_DURATION)) { | |||
return true; | |||
} | |||
return false; | |||
} | |||
} |
@@ -55,6 +55,7 @@ public class FaceChatGreetingQueueMode implements ChatMode { | |||
private static final int FACE_DIFF = 70; | |||
private static final int CANDIDATE_STAY_TIME = 3000; | |||
private static final int DETECT_TIME = 200; | |||
private static final int UNKNOWN_GREETING_DURATION = 2000; | |||
private static final long PERSON_GREETING_DURATION = 30 * 60 * 1000; | |||
private static final long UNDETERMINED_GREETING_DURATION = 30 * 60 * 1000; | |||
private Map<String, PersonInfo> mPersons = new HashMap<>(); | |||
@@ -457,8 +458,7 @@ public class FaceChatGreetingQueueMode implements ChatMode { | |||
// Log.e("testtest", "sendMsgAndLog mSelectedPerson is null "); | |||
return; | |||
} | |||
// Log.e("testtest", "slected trackid " +mSelectPerson.trackId + "selectperson bd.x1 " + mSelectPerson.curResult.bd_x1+ " x2 " + mSelectPerson.curResult.bd_x2 | |||
// + " facex1 " + mSelectPerson.curResult.fa_x1 + " facex2 " + mSelectPerson.curResult.fa_x2 + " bitmap " + mSelectPerson.bitmap); | |||
Log.e("testtrack", " select people " + mSelectPerson); | |||
FaceManager.getInstance().updateRect(mSelectPerson.curResult); | |||
sendMsg(mSelectPerson); | |||
@@ -566,8 +566,9 @@ public class FaceChatGreetingQueueMode implements ChatMode { | |||
public void greeting() { | |||
for (PersonInfo value : mPersonsInScreen) { | |||
// 是否有脸 | |||
if (!value.hasBeenGreeted) { | |||
value.last_greet_time = System.currentTimeMillis(); | |||
long time = System.currentTimeMillis(); | |||
if (!value.hasBeenGreeted && value.hasDirection()) { | |||
value.last_greet_time = time; | |||
value.hasBeenGreeted = true; | |||
Log.e("testtrack", "greeting emp eid " + value); | |||
sendGreeting(value); | |||
@@ -576,17 +577,19 @@ public class FaceChatGreetingQueueMode implements ChatMode { | |||
} | |||
for (PersonInfo value : mUndeterminedPersonsInScreen) { | |||
// 是否有脸 | |||
if (!value.hasBeenGreeted) { | |||
value.last_greet_time = System.currentTimeMillis(); | |||
long time = System.currentTimeMillis(); | |||
if (!value.hasBeenGreeted && ((time - value.last_in_time) >= UNKNOWN_GREETING_DURATION) | |||
&& value.hasDirection()) { | |||
value.last_greet_time = time; | |||
value.hasBeenGreeted = true; | |||
Log.e("testtrack", "greeting trackId " + value.trackId + " old trackid" + value.oldTrackId + " fa.qulity " + value.face_quality + " greeting duration " + (System.currentTimeMillis() - value.last_greet_time)); | |||
Log.e("testtrack", "greeting trackId " + value.trackId + " old value " + value + " greeting duration " + (System.currentTimeMillis() - value.last_in_time)); | |||
sendGreeting(value); | |||
break; | |||
} else { | |||
// 陌生人打招呼超过两秒才打 | |||
if (System.currentTimeMillis() - value.last_greet_time < 2500) { | |||
//sendGreeting(value); | |||
Log.e("testtrack", "< 2500 " + value.trackId + " old trackid" + value.oldTrackId + " fa.qulity " + value.face_quality + " greeting duration " + (System.currentTimeMillis() - value.last_greet_time)); | |||
//Log.e("testtrack", "< 2500 " + value.trackId + " old trackid" + value.oldTrackId + " fa.qulity " + value.face_quality + " greeting duration " + (System.currentTimeMillis() - value.last_greet_time)); | |||
return; | |||
} | |||
@@ -611,7 +614,6 @@ public class FaceChatGreetingQueueMode implements ChatMode { | |||
person.put("lastGreetTime", message.last_greet_time); // 打招呼的时间 | |||
person.put("directionType", message.position_type.ordinal()); // 运动的方向 | |||
Skill skill = SkillDbHelper.getInstance().getByType(message.tag); | |||
Log.e("testtrack", "skill " + skill); | |||
if (skill != null) { | |||
person.put("skillStatus", skill.status); | |||
person.put("resp", skill.resp); | |||
@@ -90,7 +90,7 @@ public class FaceChatMode implements ChatMode{ | |||
origin.result = person.result; | |||
origin.faceWidth = person.faceWidth; | |||
origin.bitmap = person.bitmap; | |||
} else if(person.result.hd_fa > 0 && person.result.fa_quality > origin.result.fa_quality){ | |||
} else { | |||
origin.result = person.result; | |||
origin.faceWidth = person.faceWidth; | |||
origin.bitmap = person.bitmap; | |||
@@ -104,7 +104,8 @@ public class FaceChatMode implements ChatMode{ | |||
if(mPersons.containsKey(person.id)){ | |||
PersonInfo origin = mPersons.get(person.id); | |||
origin.updateTime = System.currentTimeMillis(); | |||
if(person.result.hd_fa > 0 && person.result.fa_quality > origin.result.fa_quality){ | |||
//if(person.result.hd_fa > 0 && person.result.fa_quality > origin.result.fa_quality) | |||
{ | |||
origin.result = person.result; | |||
origin.faceWidth = person.faceWidth; | |||
origin.bitmap = person.bitmap; | |||
@@ -274,7 +275,8 @@ public class FaceChatMode implements ChatMode{ | |||
PersonInfo value = entry.getValue(); | |||
if (att.track_id == value.trackId) { | |||
value.updateTime = System.currentTimeMillis(); | |||
if(att.hd_fa > 0 && att.fa_quality > value.result.fa_quality){ | |||
//if(att.hd_fa > 0 && att.fa_quality > value.result.fa_quality) | |||
{ | |||
value.faceWidth = att.fa_w; | |||
value.result = att; | |||
value.bitmap = textureBitmap; | |||
@@ -319,7 +321,8 @@ public class FaceChatMode implements ChatMode{ | |||
PersonInfo stranger = mUndeterminedPersons.get(att.track_id); | |||
if(stranger.id.equals("-2")){ | |||
stranger.updateTime = System.currentTimeMillis(); | |||
if(att.hd_fa > 0 && att.fa_quality > stranger.result.fa_quality){ | |||
//if(att.hd_fa > 0 && att.fa_quality > stranger.result.fa_quality) | |||
{ | |||
stranger.faceWidth = att.fa_w; | |||
stranger.result = att; | |||
stranger.bitmap = textureBitmap; | |||
@@ -343,7 +346,8 @@ public class FaceChatMode implements ChatMode{ | |||
} else{ | |||
PersonInfo message = mUndeterminedPersons.get(att.track_id); | |||
message.updateTime = System.currentTimeMillis(); | |||
if(att.hd_fa > 0 && att.fa_quality > message.result.fa_quality){ | |||
//if(att.hd_fa > 0 && att.fa_quality > message.result.fa_quality) | |||
{ | |||
message.faceWidth = att.fa_w; | |||
message.result = att; | |||
message.bitmap = textureBitmap; | |||
@@ -1120,14 +1124,14 @@ public class FaceChatMode implements ChatMode{ | |||
FaceChatMode.filterPersonForFeatExtract(results, textureBitmap); | |||
boolean isContinue = FaceChatMode.featExtract(results, textureBitmap); | |||
if(isContinue){ | |||
// if(isInitComplete){ | |||
// DDSManager.getInstance().wakeUpDDSDialog(); | |||
// } | |||
// FaceChatMode.confirmCurrentPerson(); | |||
// if(isInitComplete){ | |||
// DDSManager.getInstance().wakeUpDDSDialog(); | |||
// } | |||
FaceChatMode.confirmCurrentPerson(); | |||
} | |||
// if(!mFaceManager.hasPerson()){ | |||
// DDSManager.getInstance().stopDDSDialog(); | |||
// } | |||
// if(!mFaceManager.hasPerson()){ | |||
// DDSManager.getInstance().stopDDSDialog(); | |||
// } | |||
} | |||
if(System.currentTimeMillis() - FaceChatMode.mInterval > 500){ | |||
FaceChatMode.confirmCurrentPerson(); | |||