tzutalin / dlib-android-app

:dragon: Android app to demo dlib-android(https://github.com/tzutalin/dlib-android). Use the prebuilt shared-lib built from dlib-android
Apache License 2.0
683 stars 246 forks source link

Cannot find local variable 'point' and cannot detect landmark points #21

Open clementf2b opened 7 years ago

clementf2b commented 7 years ago

If I use z3 compact to detect it, I can get the 68 points.

However, I get 0 point in other devices like nexus 5x, z5 or one plus two.

The following is the code that I use to detect the face landmark point.

private Runnable landmarkDetection = new Runnable() {

    public void run() {
        // TODO Auto-generated method stu
        try {
            Canvas canvas = new Canvas(temp);
            canvas.drawBitmap(temp, new Matrix(), null);
            if (mFaceDet == null) {
                mFaceDet = new FaceDet(Constants.getFaceShapeModelPath());
            }
            List<VisionDetRet> faceList = mFaceDet.detect(path);
            if (faceList.size() > 0) {
                for (VisionDetRet ret : faceList) {
                    float width = 1080;
                    // By ratio scale
                    float aspectRatio = originalImg.getWidth() / (float) originalImg.getHeight();
                    float resizeRatio = 1;
                    final int MAX_SIZE = 1;
                    newWidth = 1080;
                    newHeight = 1380;
                    newHeight = Math.round(newWidth / aspectRatio);

                    if (originalImg.getWidth() > MAX_SIZE && originalImg.getHeight() > MAX_SIZE) {
                        originalImg = getResizedBitmap(originalImg, newWidth, newHeight);
                        resizeRatio = (float) originalImg.getWidth() / (float) width;
                        Log.d("resizeRatio ", resizeRatio + "");
                    }

                    ArrayList<Point> landmarks = ret.getFaceLandmarks();
                    int count = 0;
                    for (Point point : landmarks) {
                        float pointX = (point.x * resizeRatio);
                        float pointY = (point.y * resizeRatio);
                            landmark_pt_x.add(pointX);
                            landmark_pt_y.add(pointY);
                        Log.d(TAG, count + " " + pointX + " : " + pointY);
                        count++;

                        drawpoint(pointX, pointY, temp, canvas);
                    }
                    Log.d(TAG + " added landmark", count + "");
                }
            } else {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getApplicationContext(), "No face", Toast.LENGTH_SHORT).show();
                    }
                });
            }
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    imageView.setImageBitmap(originalImg);
                    progressDialog.dismiss();
                }
            });
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
    }
};

I use debug mode in one plus two. It got the following error when it is running

   ArrayList<Point> landmarks = ret.getFaceLandmarks();

screen shot 2017-03-27 at 2 17 36 pm

Please give me some helps. Thank you very much.

nburn42 commented 7 years ago

I also do not get any points when I ask for landmark locations.

Your final point about a missing variable is completely expected and perhaps means you don't understand debugging or the code fully.

In the section below point gets defined in the beginning of the for loop and will only exist in the for loop. You need your debugger to be running a line in the loop for point to be defined. and because landmarks is length zero it never enters the loop. So you would never expect your point.x to work in debugger if you are not getting landmark locations.

            for (Point point : landmarks) {
                    float pointX = (point.x * resizeRatio);
                    float pointY = (point.y * resizeRatio);
                        landmark_pt_x.add(pointX);
                        landmark_pt_y.add(pointY);
                    Log.d(TAG, count + " " + pointX + " : " + pointY);
                    count++;

                    drawpoint(pointX, pointY, temp, canvas);
                }
clementf2b commented 7 years ago

yes. Because the above code is assuming that I can get the 68 points. About the problem, do you have any suggestion?