本文整理汇总了Java中com.google.android.gms.vision.face.Landmark.getPosition方法的典型用法代码示例。如果您正苦于以下问题:Java Landmark.getPosition方法的具体用法?Java Landmark.getPosition怎么用?Java Landmark.getPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.gms.vision.face.Landmark
的用法示例。
在下文中一共展示了Landmark.getPosition方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: drawFaceAnnotations
import com.google.android.gms.vision.face.Landmark; //导入方法依赖的package包/类
/**
* Draws a small circle for each detected landmark, centered at the detected landmark position.
* <p>
*
* Note that eye landmarks are defined to be the midpoint between the detected eye corner
* positions, which tends to place the eye landmarks at the lower eyelid rather than at the
* pupil position.
*/
private void drawFaceAnnotations(Canvas canvas, double scale) {
Paint paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(5);
for (int i = 0; i < mFaces.size(); ++i) {
Face face = mFaces.valueAt(i);
for (Landmark landmark : face.getLandmarks()) {
int cx = (int) (landmark.getPosition().x * scale);
int cy = (int) (landmark.getPosition().y * scale);
canvas.drawCircle(cx, cy, 10, paint);
}
}
}
示例2: getLandmarkPosition
import com.google.android.gms.vision.face.Landmark; //导入方法依赖的package包/类
/**
* Finds a specific landmark position, or approximates the position based on past observations
* if it is not present.
*/
private PointF getLandmarkPosition(Face face, int landmarkId) {
for (Landmark landmark : face.getLandmarks()) {
if (landmark.getType() == landmarkId) {
return landmark.getPosition();
}
}
PointF prop = mPreviousProportions.get(landmarkId);
if (prop == null) {
return null;
}
float x = face.getPosition().x + (prop.x * face.getWidth());
float y = face.getPosition().y + (prop.y * face.getHeight());
return new PointF(x, y);
}
示例3: updateFace
import com.google.android.gms.vision.face.Landmark; //导入方法依赖的package包/类
@Override public void updateFace(Face face) {
for (Landmark landmark : face.getLandmarks()) {
switch (landmark.getType()) {
case Landmark.LEFT_EYE:
leftEye = landmark.getPosition();
break;
case Landmark.RIGHT_EYE:
rightEye = landmark.getPosition();
break;
}
}
this.face = face;
}
示例4: updatePreviousProportions
import com.google.android.gms.vision.face.Landmark; //导入方法依赖的package包/类
private void updatePreviousProportions(Face face) {
for (Landmark landmark : face.getLandmarks()) {
PointF position = landmark.getPosition();
float xProp = (position.x - face.getPosition().x) / face.getWidth();
float yProp = (position.y - face.getPosition().y) / face.getHeight();
mPreviousProportions.put(landmark.getType(), new PointF(xProp, yProp));
}
}
示例5: PhotoFace
import com.google.android.gms.vision.face.Landmark; //导入方法依赖的package包/类
public PhotoFace(Face face, Bitmap sourceBitmap, Size targetSize, boolean sideward) {
List<Landmark> landmarks = face.getLandmarks();
Point leftEyePoint = null;
Point rightEyePoint = null;
Point leftMouthPoint = null;
Point rightMouthPoint = null;
for (Landmark landmark : landmarks) {
PointF point = landmark.getPosition();
switch (landmark.getType()) {
case Landmark.LEFT_EYE: {
leftEyePoint = transposePoint(point, sourceBitmap, targetSize, sideward);
}
break;
case Landmark.RIGHT_EYE: {
rightEyePoint = transposePoint(point, sourceBitmap, targetSize, sideward);
}
break;
case Landmark.LEFT_MOUTH: {
leftMouthPoint = transposePoint(point, sourceBitmap, targetSize, sideward);
}
break;
case Landmark.RIGHT_MOUTH: {
rightMouthPoint = transposePoint(point, sourceBitmap, targetSize, sideward);
}
break;
}
}
if (leftEyePoint != null && rightEyePoint != null) {
eyesCenterPoint = new Point(0.5f * leftEyePoint.x + 0.5f * rightEyePoint.x,
0.5f * leftEyePoint.y + 0.5f * rightEyePoint.y);
eyesDistance = (float)Math.hypot(rightEyePoint.x - leftEyePoint.x, rightEyePoint.y - leftEyePoint.y);
angle = (float)Math.toDegrees(Math.PI + Math.atan2(rightEyePoint.y - leftEyePoint.y, rightEyePoint.x - leftEyePoint.x));
width = eyesDistance * 2.35f;
float foreheadHeight = 0.8f * eyesDistance;
float upAngle = (float)Math.toRadians(angle - 90);
foreheadPoint = new Point(eyesCenterPoint.x + foreheadHeight * (float)Math.cos(upAngle),
eyesCenterPoint.y + foreheadHeight * (float)Math.sin(upAngle));
}
if (leftMouthPoint != null && rightMouthPoint != null) {
mouthPoint = new Point(0.5f * leftMouthPoint.x + 0.5f * rightMouthPoint.x,
0.5f * leftMouthPoint.y + 0.5f * rightMouthPoint.y);
float chinDepth = 0.7f * eyesDistance;
float downAngle = (float)Math.toRadians(angle + 90);
chinPoint = new Point(mouthPoint.x + chinDepth * (float)Math.cos(downAngle),
mouthPoint.y + chinDepth * (float)Math.sin(downAngle));
}
}
示例6: scanFaces
import com.google.android.gms.vision.face.Landmark; //导入方法依赖的package包/类
private void scanFaces() throws Exception {
Bitmap bitmap = decodeBitmapUri(this, imageUri);
if (detector.isOperational() && bitmap != null) {
editedBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap
.getHeight(), bitmap.getConfig());
float scale = getResources().getDisplayMetrics().density;
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.rgb(255, 61, 61));
paint.setTextSize((int) (14 * scale));
paint.setShadowLayer(1f, 0f, 1f, Color.WHITE);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(3f);
Canvas canvas = new Canvas(editedBitmap);
canvas.drawBitmap(bitmap, 0, 0, paint);
Frame frame = new Frame.Builder().setBitmap(editedBitmap).build();
SparseArray<Face> faces = detector.detect(frame);
scanResults.setText(null);
for (int index = 0; index < faces.size(); ++index) {
Face face = faces.valueAt(index);
canvas.drawRect(
face.getPosition().x,
face.getPosition().y,
face.getPosition().x + face.getWidth(),
face.getPosition().y + face.getHeight(), paint);
scanResults.setText(scanResults.getText() + "Face " + (index + 1) + "\n");
scanResults.setText(scanResults.getText() + "Smile probability:" + "\n");
scanResults.setText(scanResults.getText() + String.valueOf(face.getIsSmilingProbability()) + "\n");
scanResults.setText(scanResults.getText() + "Left Eye Open Probability: " + "\n");
scanResults.setText(scanResults.getText() + String.valueOf(face.getIsLeftEyeOpenProbability()) + "\n");
scanResults.setText(scanResults.getText() + "Right Eye Open Probability: " + "\n");
scanResults.setText(scanResults.getText() + String.valueOf(face.getIsRightEyeOpenProbability()) + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
for (Landmark landmark : face.getLandmarks()) {
int cx = (int) (landmark.getPosition().x);
int cy = (int) (landmark.getPosition().y);
canvas.drawCircle(cx, cy, 5, paint);
}
}
if (faces.size() == 0) {
scanResults.setText("Scan Failed: Found nothing to scan");
} else {
imageView.setImageBitmap(editedBitmap);
scanResults.setText(scanResults.getText() + "No of Faces Detected: " + "\n");
scanResults.setText(scanResults.getText() + String.valueOf(faces.size()) + "\n");
scanResults.setText(scanResults.getText() + "---------" + "\n");
}
} else {
scanResults.setText("Could not set up the detector!");
}
}
示例7: detect
import com.google.android.gms.vision.face.Landmark; //导入方法依赖的package包/类
@Override
public void detect(
SharedBufferHandle frameData, int width, int height, DetectResponse callback) {
// The vision library will be downloaded the first time the API is used
// on the device; this happens "fast", but it might have not completed,
// bail in this case.
if (!mFaceDetector.isOperational()) {
Log.e(TAG, "FaceDetector is not operational");
// Fallback to Android's FaceDetectionImpl.
FaceDetectorOptions options = new FaceDetectorOptions();
options.fastMode = mFastMode;
options.maxDetectedFaces = mMaxFaces;
FaceDetectionImpl detector = new FaceDetectionImpl(options);
detector.detect(frameData, width, height, callback);
return;
}
Frame frame = SharedBufferUtils.convertToFrame(frameData, width, height);
if (frame == null) {
Log.e(TAG, "Error converting SharedMemory to Frame");
callback.call(new FaceDetectionResult[0]);
return;
}
final SparseArray<Face> faces = mFaceDetector.detect(frame);
FaceDetectionResult[] faceArray = new FaceDetectionResult[faces.size()];
for (int i = 0; i < faces.size(); i++) {
faceArray[i] = new FaceDetectionResult();
final Face face = faces.valueAt(i);
final PointF corner = face.getPosition();
faceArray[i].boundingBox = new RectF();
faceArray[i].boundingBox.x = corner.x;
faceArray[i].boundingBox.y = corner.y;
faceArray[i].boundingBox.width = face.getWidth();
faceArray[i].boundingBox.height = face.getHeight();
final List<Landmark> landmarks = face.getLandmarks();
ArrayList<org.chromium.shape_detection.mojom.Landmark> mojoLandmarks =
new ArrayList<org.chromium.shape_detection.mojom.Landmark>(landmarks.size());
for (int j = 0; j < landmarks.size(); j++) {
final Landmark landmark = landmarks.get(j);
final int landmarkType = landmark.getType();
if (landmarkType == Landmark.LEFT_EYE || landmarkType == Landmark.RIGHT_EYE
|| landmarkType == Landmark.BOTTOM_MOUTH) {
org.chromium.shape_detection.mojom.Landmark mojoLandmark =
new org.chromium.shape_detection.mojom.Landmark();
mojoLandmark.location = new org.chromium.gfx.mojom.PointF();
mojoLandmark.location.x = landmark.getPosition().x;
mojoLandmark.location.y = landmark.getPosition().y;
mojoLandmark.type = landmarkType == Landmark.BOTTOM_MOUTH ? LandmarkType.MOUTH
: LandmarkType.EYE;
mojoLandmarks.add(mojoLandmark);
}
}
faceArray[i].landmarks = mojoLandmarks.toArray(
new org.chromium.shape_detection.mojom.Landmark[mojoLandmarks.size()]);
}
callback.call(faceArray);
}