Face++的官网:
http://www.faceplusplus.com.cn/
可以识别照片中的人脸位置,人物的年龄,性别,种族,是否微笑等信息。效果图:
首先创建应用,会分配给我们一个API Key和API Secret,然后下载“Java SDK(Android)”,导入Jar包和库文件,参考官方的Demo进行编写。
1.FaceDetectUtil帮助类:
package com.zms.carlauncher.util;
import java.io.ByteArrayOutputStream;
import org.json.JSONObject;
import com.facepp.error.FaceppParseException;
import com.facepp.http.HttpRequests;
import com.facepp.http.PostParameters;
import com.zms.carlauncher.Constant;
import android.graphics.Bitmap;
import android.graphics.Matrix;
public class FaceDetectUtil {
public interface FaceCallBack {
void success(JSONObject result);
void error(FaceppParseException exception);
}
public static void detect(final Bitmap bitmapDetect,
final FaceCallBack faceCallBack) {
new Thread(new Runnable() {
@Override
public void run() {
try {
// 请求
HttpRequests httpRequests = new HttpRequests(
Constant.FACE_API_KEY, Constant.FACE_API_SECRET,
true, true);
// Log.v(TAG, "image size : " + img.getWidth() + " " +
// img.getHeight());
ByteArrayOutputStream stream = new ByteArrayOutputStream();
float scale = Math.min(1, Math.min(
600f / bitmapDetect.getWidth(),
600f / bitmapDetect.getHeight()));
Matrix matrix = new Matrix();
matrix.postScale(scale, scale);
Bitmap imgSmall = Bitmap.createBitmap(bitmapDetect, 0, 0,
bitmapDetect.getWidth()