L'API Mobile Vision ne prend pas directement en charge la détection d'ouverture/fermeture de bouche. Mais ce code peut vous aider. J'ai testé et travaillé le charme sur mon appareil.
@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 ");
}
}
}
Et voici une autre méthode.
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 - Ce code trouverez de trouver le point centre cordinates de la bouche à gauche et à droite et trouver la différence entre la bouche et fond cordinates points centraux cordinates.
alors quelle est la solution alternative? – Shadow