Mobile Vision APIでは、口の開閉の検出を直接サポートしていません。しかし、このコードはあなたを助けるかもしれません。私は私の装置で魅力を試して、働いています。
@Override
public void draw(Canvas canvas) {
Face face = mFace;
if (face == null) {
return;
}
if ((contains(face.getLandmarks(), 11) != 99)
&& (contains(face.getLandmarks(), 5) != 99)
&& (contains(face.getLandmarks(), 6) != 99)
) {
Log.i(TAG, "draw: Mouth Open >> found all the points");
/**
* for bottom mouth
*/
int cBottomMouthX;
int cBottomMouthY;
if (FaceTrackerActivity.mIsFrontFacing) {
cBottomMouthX = (int) translateX(face.getLandmarks().get(contains(face.getLandmarks(), 0)).getPosition().x);
cBottomMouthY = (int) translateY(face.getLandmarks().get(contains(face.getLandmarks(), 0)).getPosition().y);
Log.i(TAG, "draw: Condition Bottom mouth >> cBottomMouthX >> " + cBottomMouthX + " cBottomMouthY >> " + cBottomMouthY);
} else {
cBottomMouthX = (int) translateX(face.getLandmarks().get(contains(face.getLandmarks(), 0)).getPosition().x);
cBottomMouthY = (int) translateY(face.getLandmarks().get(contains(face.getLandmarks(), 0)).getPosition().y);
}
canvas.drawCircle(cBottomMouthX, cBottomMouthY, 10, mPaint);
/**
* for left mouth
*/
int cLeftMouthX;
int cLeftMouthY;
if (FaceTrackerActivity.mIsFrontFacing) {
cLeftMouthX = (int) translateX(face.getLandmarks().get(contains(face.getLandmarks(), 5)).getPosition().x);
cLeftMouthY = (int) translateY(face.getLandmarks().get(contains(face.getLandmarks(), 5)).getPosition().y);
Log.i(TAG, "draw: Condition LEft mouth >> cLeftMouthX >> " + cLeftMouthX + " cLeftMouthY >> " + cLeftMouthY);
} else {
cLeftMouthX = (int) translateX(face.getLandmarks().get(contains(face.getLandmarks(), 5)).getPosition().x);
cLeftMouthY = (int) translateY(face.getLandmarks().get(contains(face.getLandmarks(), 5)).getPosition().y);
}
canvas.drawCircle(cLeftMouthX, cLeftMouthY, 10, mPaint);
/**
* for Right mouth
*/
int cRightMouthX;
int cRightMouthY;
if (FaceTrackerActivity.mIsFrontFacing) {
cRightMouthX = (int) translateX(face.getLandmarks().get(contains(face.getLandmarks(), 11)).getPosition().x);
cRightMouthY = (int) translateY(face.getLandmarks().get(contains(face.getLandmarks(), 11)).getPosition().y);
Log.i(TAG, "draw: Condition Right mouth >> cRightMouthX >> " + cRightMouthX + " cRightMouthY >> " + cRightMouthY);
} else {
cRightMouthX = (int) translateX(face.getLandmarks().get(contains(face.getLandmarks(), 11)).getPosition().x);
cRightMouthY = (int) translateY(face.getLandmarks().get(contains(face.getLandmarks(), 11)).getPosition().y);
}
canvas.drawCircle(cRightMouthX, cRightMouthY, 10, mPaint);
float centerPointX = (cLeftMouthX + cRightMouthX)/2;
float centerPointY = ((cLeftMouthY + cRightMouthY)/2) - 20;
canvas.drawCircle(centerPointX, centerPointY, 10, mPaint);
float differenceX = centerPointX - cBottomMouthX;
float differenceY = centerPointY - cBottomMouthY;
Log.i(TAG, "draw: difference X >> " + differenceX + " Y >> " + differenceY);
if (differenceY < (-60)) {
Log.i(TAG, "draw: difference - Mouth is OPENED ");
} else {
Log.i(TAG, "draw: difference - Mouth is CLOSED ");
}
}
}
そして別の方法があります。
int contains(List<Landmark> list, int name) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getType() == name) {
return i;
}
}
return 99;
}
P.S - このコードは、左右の口の中央ポイントcordinatesを見つける見つけ、ボトム口のcordinatesと中心との差がcordinatesを指しています。
代替ソリューションは何ですか? – Shadow