FacePlusPlus / MegviiFacepp-Android-SDK

An android wrapper of MegviiFacepp SDK (the mobile SDK).
Apache License 2.0
234 stars 75 forks source link

detect里传入图片时检测不到人脸? #45

Open JYLongKong opened 6 years ago

JYLongKong commented 6 years ago

稍微修改了一下demo,尝试用图片bitmap转YUV格式后作为detect的第一个参数,但是没有发现检测到的人脸

JYLongKong commented 6 years ago

问了旷视客服,给出了解决方案

    `//初始化
    long handle1 = NativeFaceppAPI.nativeInit(getApplicationContext(), 
    ConUtil.getFileContent(getApplicationContext(), R.raw.megviifacepp_0_5_2_model), 0);

    //picture是图片的路径,对图片进行转化,这里是转成灰度图
    byte[] imageData = FileImageUtils.bitmap2Gray(picture);
    int width = FileImageUtils.getSize(picture)[0];
    int height = FileImageUtils.getSize(picture)[1];

    //这里是设置了默认的参数,有参数变动可以这里修改
    float[] configs = NativeFaceppAPI.nativeGetFaceppConfig(handle1);
    Assert.assertNotNull(configs);
    Facepp.FaceppConfig faceppConfig = new Facepp.FaceppConfig();
    faceppConfig.minFaceSize = (int) configs[0];
    faceppConfig.rotation = 0;
    faceppConfig.interval = (int) configs[2];
    faceppConfig.detectionMode = (int) configs[3];
    faceppConfig.roi_left = (int) configs[4];
    faceppConfig.roi_top = (int) configs[5];
    faceppConfig.roi_right = (int) configs[6];
    faceppConfig.roi_bottom = (int) configs[7];
    faceppConfig.face_confidence_filter=configs[8];
    faceppConfig.one_face_tracking = (int) configs[9];
    faceppConfig.one_face_tracking = 0;

    faceppConfig.detectionMode = Facepp.FaceppConfig.DETECTION_MODE_NORMAL;
    NativeFaceppAPI.nativeSetFaceppConfig(handle1, faceppConfig.minFaceSize, faceppConfig.rotation,
            faceppConfig.interval, faceppConfig.detectionMode, faceppConfig.roi_left,
            faceppConfig.roi_top, faceppConfig.roi_right, faceppConfig.roi_bottom,faceppConfig.face_confidence_filter, faceppConfig.one_face_tracking);

    int faceSize = NativeFaceppAPI.nativeDetect(handle1,imageData, width,height,Facepp.IMAGEMODE_GRAY);

    if (faceSize <= 0) {
        //未被标记出来的人脸
        Log.d("facepp","未检出人脸");
    }else{
        Facepp.Face[] faces = new Facepp.Face[faceSize];
        for (int i = 0; i < faceSize; i++) {
            Facepp.Face face = new Facepp.Face();
            face.points = new PointF[81];
            float[] landmark = NativeFaceppAPI.nativeLandMark(handle1, i, Facepp.FPP_GET_LANDMARK81);
            float[] points = NativeFaceppAPI.nativeFaceInfo(handle1, i);
            for (int j = 0; j < 81; j++) {
                PointF point = new PointF();
                point.x = (int) landmark[2 * j];
                point.y = (int) landmark[2 * j + 1];
                face.points[j] = point;
            }
            faces[i] = face;
            face.confidence = points[2];
        }
        for(int i = 0; i < faces.length; i++){
            String detectResult =" face_index: "+i+" confidence=="+faces[i].confidence+" index--"+i;
            Log.d("facepp","每个人脸检出结果:"+detectResult);
        }

        //检测后,画关键点,并保存
        Bitmap bitmap2 = Utils.drawPoint(faces, picture);
        if (bitmap2 != null) {
            Utils.saveMyBitmap("sdcard/"+"detect_face","landmark_img.png", bitmap2);
        }

    }

}`