Tengine-Kit人脸检测及关键点

Tengine-Kit 人脸检测及关键点

Tengine-Kit是一个在Android上的一个算法集合。目前的算法有,人脸检测及关键点,虹膜关键点,身体检测及关键点,手的检测及关键点。

Tengine-Kit地址

1.build.gradle引入库

implementation 'com.tengine.tenginekit:core:0.0.1'
implementation 'com.tengine.tenginekit:face:0.0.1'

2.得到图像的byte数据

Bitmap bb = null;
try {
 	Drawable d = Drawable.createFromStream(getAssets().open("person.jpg"), null);
 	showImage.setImageDrawable(d);
 	bb = ((BitmapDrawable) d).getBitmap();
} catch (Exception e) {
    e.printStackTrace();
}

//bitmap转bytes[]数据
private byte[] bitmap2Bytes(Bitmap image) {
    // calculate how many bytes our image consists of
    int bytes = image.getByteCount();
    ByteBuffer buffer = ByteBuffer.allocate(bytes); // Create a new buffer
    image.copyPixelsToBuffer(buffer); // Move the byte data to the buffer
    byte[] temp = buffer.array(); // Get the underlying array containing the
    return temp;
}

3.初始化Tengine-Kit

KitCore.init(this,
      AndroidConfig
      .create() // 创建
      .setNormalMode() // 由于这次用的图片,所以用Normal模式
      .setDefaultFunc() // 设置默认功能,也就是检测&关键点
      .setInputImageFormat(AndroidConfig.ImageFormat.RGBA) // 输入图像格式
      .setInputImageSize(Image_w, Image_h) // 设置输入的图片大小
      .setOutputImageSize((int) Image_w, (int) Image_h) // 设置输出的图像大小
        );

4.函数调用人脸检测及关键点

Face.FaceDetect faceDetect = Face.detect(data);
List<FaceDetectInfo> faceDetectInfos = new ArrayList<>();
List<FaceLandmarkInfo> landmarkInfos = new ArrayList<>();
if (faceDetect.getFaceCount() > 0) {
    faceDetectInfos = faceDetect.getDetectInfos();
    landmarkInfos = faceDetect.landmark2d();
}
Log.d("#####", "Face Num: " + faceDetectInfos.size());
if (faceDetectInfos != null && faceDetectInfos.size() > 0) {
    List<List<TenginekitPoint>> face_landmarks = new ArrayList<>();
    for (int i = 0; i < faceDetectInfos.size(); i++) {
        Rect rect = new Rect();
        rect = faceDetectInfos.get(i).asRect();
        for (int j = 0; j < landmarkInfos.get(i).landmarks.size() ; j++) {
// x 为关键点X坐标, y为关键点Y坐标
            float x = landmarkInfos.get(i).landmarks.get(j).X;
            float y = landmarkInfos.get(i).landmarks.get(j).Y;

        }
    }
}

5.释放

KitCore.release();

最终效果图:
展示

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

湖中树

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值