本文整理汇总了Java中com.google.android.gms.vision.face.Face类的典型用法代码示例。如果您正苦于以下问题:Java Face类的具体用法?Java Face怎么用?Java Face使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Face类属于com.google.android.gms.vision.face包,在下文中一共展示了Face类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onUpdate
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Update the position/characteristics of the face within the overlay.
*/
@Override
public void onUpdate(FaceDetector.Detections<Face> detectionResults, Face face) {
mOverlay.add(mFaceGraphic);
boolean isSmiling = face.getIsSmilingProbability() > SMILING_THRESHOLD;
if (isSmiling) {
float leftEye = face.getIsLeftEyeOpenProbability();
float rightEye = face.getIsRightEyeOpenProbability();
if (Math.abs(leftEye - rightEye) >= WINK_THRESHOLD) {
takeShot();
}
}
mFaceGraphic.setIsReady(isSmiling);
mFaceGraphic.updateFace(face);
}
示例2: draw
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Draws the face annotations for position on the supplied canvas.
*/
@Override
public void draw(Canvas canvas) {
Face face = mFace;
if (face == null) {
return;
}
// Draws a circle at the position of the detected face, with the face's track id below.
float x = translateX(face.getPosition().x + face.getWidth() / 2);
float y = translateY(face.getPosition().y + face.getHeight() / 2);
float xOffset = scaleX(face.getWidth() / 2.0f);
float yOffset = scaleY(face.getHeight() / 2.0f);
float left = x - xOffset;
float top = y - yOffset;
float right = x + xOffset;
float bottom = y + yOffset;
canvas.drawRect(left, top, right, bottom, mBoxPaint);
canvas.drawBitmap(op, left, top, new Paint());
}
示例3: draw
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Draws the face annotations for position, size, and ID on the supplied canvas.
*/
@Override
public void draw(Canvas canvas) {
Face face = mFace;
if (face == null) {
return;
}
float cx = translateX(face.getPosition().x + face.getWidth() / 2);
if (cx > Constants.OFFSET_HEAD) {
documentIdentifier.setFaceSide(Constants.FACE_RIGHT);
Log.e("FACE ", "toRight");
} else {
documentIdentifier.setFaceSide(Constants.FACE_LEFT);
Log.e("FACE ", "toLeft");
}
}
示例4: draw
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Draws the face annotations for position on the supplied canvas.
*/
@Override
public void draw(Canvas canvas) {
Face face = mFace;
if (face == null) {
return;
}
// Draws a circle at the position of the detected face, with the face's track id below.
float x = translateX(face.getPosition().x + face.getWidth() / 2);
float y = translateY(face.getPosition().y + face.getHeight() / 2);
canvas.drawCircle(x, y, FACE_POSITION_RADIUS, mFacePositionPaint);
canvas.drawText("id: " + mFaceId, x + ID_X_OFFSET, y + ID_Y_OFFSET, mIdPaint);
canvas.drawText("happiness: " + String.format("%.2f", face.getIsSmilingProbability()), x - ID_X_OFFSET, y - ID_Y_OFFSET, mIdPaint);
canvas.drawText("right eye: " + String.format("%.2f", face.getIsRightEyeOpenProbability()), x + ID_X_OFFSET * 2, y + ID_Y_OFFSET * 2, mIdPaint);
canvas.drawText("left eye: " + String.format("%.2f", face.getIsLeftEyeOpenProbability()), x - ID_X_OFFSET*2, y - ID_Y_OFFSET*2, mIdPaint);
// Draws a bounding box around the face.
float xOffset = scaleX(face.getWidth() / 2.0f);
float yOffset = scaleY(face.getHeight() / 2.0f);
float left = x - xOffset;
float top = y - yOffset;
float right = x + xOffset;
float bottom = y + yOffset;
canvas.drawRect(left, top, right, bottom, mBoxPaint);
}
示例5: drawFaceBox
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* drawFaceBox(Canvas canvas, double scale)方法会更有趣,被检测到人脸数据以位置信息的方式存储到mFaces中,
* 这个方法将基于这些位置数据中的宽、高在检测到的人脸位置画一个绿色的矩形框。
你需要定义自己的绘画对象,然后从你的SparseArray数组中循环的找出位置、高度和宽度信息,再利用这些信息在画布上画出矩形。
*/
private void drawFaceBox(Canvas canvas, double scale){
//新建画笔
Paint paint =new Paint();
paint.setColor(Color.BLUE);
paint.setStrokeWidth(5);
paint.setStyle(Paint.Style.STROKE);
float left =0;
float top=0;
float right=0;
float bottom=0;
for(int i=0;i<mFaces.size();i++){
Face face =mFaces.get(i);
left = (float)scale*face.getPosition().x;
top =(float)scale*face.getPosition().y;
right = (float) scale * ( face.getPosition().x + face.getWidth() );
bottom = (float) scale * ( face.getPosition().y + face.getHeight() );
canvas.drawRect( left, top, right, bottom, paint );
}
}
示例6: drawOnFace
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Method to drawing on faces
*/
private Bitmap drawOnFace(SparseArray<Face> faceArray, Bitmap photo, int stroke, int color){
Bitmap outBitmap = Bitmap.createBitmap(photo.getWidth(), photo.getHeight(), Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(outBitmap);
canvas.drawBitmap(photo, 0, 0, null);
for(int i=0; i < faceArray.size(); i++){
int key = faceArray.keyAt(i);
// get the object by the key.
Face face = faceArray.get(key);
//Drawing rectangle on each face
drawRectangle(canvas, face.getPosition(), face.getWidth(), face.getHeight(),stroke,color);
this.faceRecognitionInformation.setListLandMarkPhoto(face.getLandmarks());
}
return outBitmap;
}
示例7: setDetector
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
public void setDetector(){
FaceDetector detector = new FaceDetector.Builder(this)
.setTrackingEnabled(true)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setMode(FaceDetector.ACCURATE_MODE)
.build();
Detector<Face> safeDetector = new SafeFaceDetector(detector);
if (!safeDetector.isOperational()) {
Toast.makeText(this, "Detector are having issues", Toast.LENGTH_LONG).show();
} else {
Frame frame = new Frame.Builder().setBitmap(mbitmap).build();
mFaces = safeDetector.detect(frame);
safeDetector.release();
}
}
示例8: drawFaceAnnotations
import com.google.android.gms.vision.face.Face; //导入依赖的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);
}
}
}
示例9: draw
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Draws the face annotations for position, size, and ID on the supplied canvas.
*/
@Override
public void draw(Canvas canvas) {
Face face = mFace;
if (face == null) {
return;
}
// Draws a circle at the position of the detected face, with the face's track id below.
float cx = translateX(face.getPosition().x + face.getWidth() / 2);
float cy = translateY(face.getPosition().y + face.getHeight() / 2);
canvas.drawCircle(cx, cy, FACE_POSITION_RADIUS, mFacePositionPaint);
canvas.drawText("id: " + getId(), cx + ID_X_OFFSET, cy + ID_Y_OFFSET, mIdPaint);
// Draws an oval around the face.
float xOffset = scaleX(face.getWidth() / 2.0f);
float yOffset = scaleY(face.getHeight() / 2.0f);
float left = cx - xOffset;
float top = cy - yOffset;
float right = cx + xOffset;
float bottom = cy + yOffset;
canvas.drawOval(left, top, right, bottom, mBoxPaint);
}
示例10: draw
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Draws the face annotations for position on the supplied canvas.
*/
@Override
public void draw(Canvas canvas) {
Face face = mFace;
if (face == null) {
return;
}
// Draws a circle at the position of the detected face, with the face's track id below.
float x = translateX(face.getPosition().x + face.getWidth() / 2);
float y = translateY(face.getPosition().y + face.getHeight() / 2);
// Draws a bounding box around the face.
float xOffset = scaleX(face.getWidth() / 2.0f);
float yOffset = scaleY(face.getHeight() / 2.0f);
float left = x - xOffset;
float top = y - yOffset;
float right = x + xOffset;
float bottom = y + yOffset;
canvas.drawText(mIsReady ? mReadyMessage : mNotReadyMessage, left, top - LABEL_Y_OFFSET, mPaint);
canvas.drawRect(left, top, right, bottom, mPaint);
}
示例11: draw
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Draws the face annotations for position on the supplied canvas.
*/
@Override
public void draw(Canvas canvas) {
Face face = mFace;
if (face == null) {
return;
}
// Draws a circle at the position of the detected face, with the face's track id below.
float x = translateX(face.getPosition().x + face.getWidth() / 2);
float y = translateY(face.getPosition().y + face.getHeight() / 2);
canvas.drawCircle(x, y, FACE_POSITION_RADIUS, mFacePositionPaint);
canvas.drawText("id: " + mFaceId, x + ID_X_OFFSET, y + ID_Y_OFFSET, mIdPaint);
// Draws a bounding box around the face.
float xOffset = scaleX(face.getWidth() / 2.0f);
float yOffset = scaleY(face.getHeight() / 2.0f);
float left = x - xOffset;
float top = y - yOffset;
float right = x + xOffset;
float bottom = y + yOffset;
canvas.drawRect(left, top, right, bottom, mBoxPaint);
}
示例12: getLandmarkPosition
import com.google.android.gms.vision.face.Face; //导入依赖的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);
}
示例13: findLargestFace
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
private Optional<Face> findLargestFace(Bitmap inputImage) {
final FaceDetector detector = createDetector();
final SparseArray<Face> faces = detector.detect(new Frame.Builder().setBitmap(inputImage).build());
Face largestFace = null;
float largestSize = 0f;
Timber.d("found " + faces.size() + " faces in photo");
for (int i = 0; i < faces.size(); ++i) {
final Face face = faces.valueAt(i);
final float faceSize = face.getHeight() * face.getWidth();
if (faceSize > largestSize) {
largestFace = face;
largestSize = faceSize;
}
}
detector.release();
return Optional.fromNullable(largestFace);
}
示例14: updateFace
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
/**
* Updates the face instance from the detection of the most recent frame. Invalidates the
* relevant portions of the overlay to trigger a redraw.
*/
void updateFace(Face face) {
mFace = face;
op = Bitmap.createScaledBitmap(bitmap, (int) scaleX(face.getWidth()),
(int) scaleY(((bitmap.getHeight() * face.getWidth()) / bitmap.getWidth())), false);
postInvalidate();
}
示例15: getFaceCount
import com.google.android.gms.vision.face.Face; //导入依赖的package包/类
private int getFaceCount(@NonNull Bitmap img) {
Frame frame = new Frame.Builder()
.setBitmap(img)
.build();
SparseArray<Face> faces = detector.detect(frame);
log.d("%d faces detected within image %s", faces.size(), img);
return faces.size();
}