2017-04-24 1 views
2

Comment optimiser la détection des points de repère dlib? Bitmap 160x120 a été traité 7 secondes. Je veux 50 ou 100ms. Mon code:Comment optimiser la détection des points de repère dlib?

public Mat onCameraFrame(CvCameraViewFrame inputFrame) { 
    mRgba = inputFrame.rgba(); 

    ArrayList<android.graphics.Point> points = new ArrayList(); 
    try { 
     long startTime = System.currentTimeMillis(); 
     points = LandmarkDetection.getLandmark(matToBitmap(mRgba), this, landmarkPath); 
     long endTime = System.currentTimeMillis(); 
     Log.i(TAG +"Time cost: ", String.valueOf((endTime - startTime)/1000f) + " sec"); 
     //drawPoint(points); 
     Log.i(TAG, "size = " + String.valueOf(points.size())); 
    }catch (Exception e) { 
     Log.i(TAG, "bitmap error! " + e.getMessage()); 
    } 
    return mRgba; 
} 

private Bitmap matToBitmap(@NonNull Mat mat) { 
    Bitmap bmp; 
    try { 
     Mat resized = new Mat(); 
     Imgproc.resize(mat, resized, new Size(160, 120)); 
     bmp = Bitmap.createBitmap(resized.cols(), resized.rows(), Bitmap.Config.ARGB_8888); 
     Utils.matToBitmap(resized, bmp); 
    }catch(Exception e) { 
     Log.e(TAG + ":matToBitmap", e.getMessage()); 
     return null; 
    } 
    return bmp; 
} 

et classe LandmarkDetection (Cette méthode prend tout le temps):

public static ArrayList<Point> getLandmark(@NonNull Bitmap bmp, Context context, String landmarkPath) { 
    mFaceDet = new FaceDet(landmarkPath); 
    Log.i(AndroidLauncher.TAG, String.valueOf(new File(context.getExternalCacheDir() + "/shape_predictor_68_face_landmarks.dat").exists())); 
    Log.i(AndroidLauncher.TAG, "Ширина: " + String.valueOf(bmp.getWidth()) + "\nВысота: " + String.valueOf(bmp.getHeight())); 
    results = mFaceDet.detect(bmp); 
    if (results != null) { 
     for (final VisionDetRet ret : results) { 
      landmarks = ret.getFaceLandmarks(); 
     } 
    } 
    return landmarks; 
} 

Quel est le problème avec mon code?

Répondre

1

Beaucoup de choses peuvent optimiser votre code:

  1. ne construisent pas face_detector et shape_predictor pour chaque détection de visage. Cela peut prendre plusieurs secondes. vous pouvez utiliser un shape_predictor pour tous vos threads, mais face_detector doit en avoir un par thread
  2. Le code mFaceDet n'est pas clair. peut être vous redimensionnez l'image là ou faire d'autres opérations
  3. http://dlib.net/faq.html#Whyisdlibslow