Closed Invictus-Munish closed 3 years ago
Hi according to javadoc getContour might return null, please handle the null yourself or use getAllContours instead
Hey thanks i will try it out, but i m checking for null condition in the start
if ((face != null) && (face.getContour(FaceContour.LOWER_LIP_TOP).getPoints() != null) && (face.getContour(FaceContour.UPPER_LIP_BOTTOM).getPoints() != null))
in your case you should also check face.getContour(FaceContour.LOW_LIP_TOP) != null
I will try it out. Also can u help me with getAllContours() as there in no reference mentioned in the mlkit.
List<FaceContour> contourPoints = face.getAllContours(); encodedFace.putMap("contours", contourPoints);
i dnt know how to proceed further
ps: I am bad with java :)
in your case you should also check
face.getContour(FaceContour.LOW_LIP_TOP) != null
This helped me. Thanks a lot bro :))
Android app gets crashed while using face contour after sometime (few minutes or seconds)
`
package org.reactnative.facedetector;
import android.graphics.PointF; import android.graphics.Rect;
import static java.lang.Math.ceil;
import com.facebook.react.bridge.Arguments; import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableNativeArray; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.bridge.WritableArray; import com.facebook.react.bridge.ReadableArray;
import com.google.mlkit.vision.face.Face; import com.google.mlkit.vision.face.FaceLandmark; import com.google.mlkit.vision.face.FaceContour;
import java.util.List;
public class FaceDetectorUtils { private static final String[] landmarkNames = { "bottomMouthPosition", "leftCheekPosition", "leftEarPosition", "leftEyePosition", "leftMouthPosition", "noseBasePosition", "rightCheekPosition", "rightEarPosition", "rightEyePosition", "rightMouthPosition" };
private static final String[] contourNames = { "lowerLipTop", "upperLipBottom" };
private static final int[] contourTypes = { // FaceContour.FACE, // FaceContour.LEFT_EYE, // FaceContour.LEFT_EYEBROW_BOTTOM, // FaceContour.LEFT_EYEBROW_TOP, // FaceContour.LOWER_LIP_BOTTOM, FaceContour.LOWER_LIP_TOP, // FaceContour.NOSE_BOTTOM, // FaceContour.NOSE_BRIDGE, // FaceContour.RIGHT_EYE, // FaceContour.RIGHT_EYEBROW_BOTTOM, // FaceContour.RIGHT_EYEBROW_TOP, FaceContour.UPPER_LIP_BOTTOM, // FaceContour.UPPER_LIP_TOP, };
public static WritableMap serializeFace(Face face) { return serializeFace(face, 1, 1, 0, 0, 0, 0); }
public static WritableMap serializeFace(Face face, double scaleX, double scaleY, int width, int height, int paddingLeft, int paddingTop) { WritableMap encodedFace = Arguments.createMap();
}
public static WritableMap rotateFaceX(WritableMap face, int sourceWidth, double scaleX) { ReadableMap faceBounds = face.getMap("bounds");
}
public static WritableMap changeAnglesDirection(WritableMap face) { face.putDouble("rollAngle", (-face.getDouble("rollAngle") + 360) % 360); face.putDouble("yawAngle", (-face.getDouble("yawAngle") + 360) % 360); return face; }
public static WritableMap mapFromPoint(PointF point, double scaleX, double scaleY, int width, int height, int paddingLeft, int paddingTop) { WritableMap map = Arguments.createMap(); Float x = point.x; Float y = point.y; if (point.x < width / 2) { x = (x + paddingLeft / 2); } else if (point.x > width / 2) { x = (x - paddingLeft / 2); }
}
public static WritableMap positionTranslatedHorizontally(ReadableMap position, double translateX) { WritableMap newPosition = Arguments.createMap(); newPosition.merge(position); newPosition.putDouble("x", position.getDouble("x") + translateX); return newPosition; }
public static WritableMap positionMirroredHorizontally(ReadableMap position, int containerWidth, double scaleX) { WritableMap newPosition = Arguments.createMap(); newPosition.merge(position); newPosition.putDouble("x", valueMirroredHorizontally(position.getDouble("x"), containerWidth, scaleX)); return newPosition; }
public static double valueMirroredHorizontally(double elementX, int containerWidth, double scaleX) { double originalX = elementX / scaleX; double mirroredX = containerWidth - originalX; return mirroredX * scaleX; } } `