如何动态地将眼镜可绘制图像放置在眼睛上?

时间:2019-05-03 07:35:23

标签: java android

我正在应用程序上进行虚拟试戴,我已经从图像中检测到人脸,现在我想动态地将眼镜框放在眼睛上。请帮助我将眼镜放在检测到的脸上。

 FaceDetector faceDetector = new FaceDetector.Builder(getApplicationContext())
                .setTrackingEnabled(false)
                .setLandmarkType(FaceDetector.ALL_LANDMARKS)
                .setMode(FaceDetector.FAST_MODE)
                .build();
        if(!faceDetector.isOperational()){
            Toast.makeText(try_on.this, "Ops, FaceDetector couldn't be set up on your device", Toast.LENGTH_SHORT).show();
            return;
        }
Frame frame = new Frame.Builder().setBitmap(b).build();
        SparseArray<Face> sparseArray = faceDetector.detect(frame);
        if(sparseArray.size() != 0){

            for ( int i = 0 ;i <sparseArray.size();i++){

                com.google.android.gms.vision.face.Face face = sparseArray.valueAt(i);
                float x1 = face.getPosition().x;
                float y1 = face.getPosition().y;
                float x2 = x1+face.getWidth();
                float y2 = y1+face.getHeight();
                RectF rectF = new RectF(x1,y1,x2,y2);
                canvas.drawRoundRect(rectF,2,2,rectpaint);
                imgg.setImageDrawable(new BitmapDrawable(getResources(),tempbitmap));

                float lefteye = face.getIsLeftEyeOpenProbability();
                view.setImageBitmap(mIcon1);
                view.setX(lefteye);

            }

上面的代码从图像中检测到脸部。如何从图像中检测到眼睛上戴眼镜?

0 个答案:

没有答案