0

I have detect the left eye,right eye,nose,mouth from the human face.But i want to detect the head from the face.But the head is not detect from the face.Any one give the solution to detect head.I have tried the something like this`

public void processImage(View view) {

        BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
        bitmapOptions.inMutable = true;

        initializeBitmap(bitmapOptions);
        createRectanglePaint();

        canvas = new Canvas(temporaryBitmap);
        canvas.drawBitmap(defaultBitmap, 0, 0, null);


        FaceDetector faceDetector = new FaceDetector.Builder(this)
                .setTrackingEnabled(false)
                .setLandmarkType(FaceDetector.ALL_LANDMARKS)
                .build();

        if (!faceDetector.isOperational()) {
            new AlertDialog.Builder(this)
                    .setMessage("Face Detector could not be set up on your device :(")
                    .show();
        } else {
            Frame frame = new Frame.Builder().setBitmap(defaultBitmap).build();
            SparseArray<Face> sparseArray = faceDetector.detect(frame);

            detectFaces(sparseArray);

            imageView.setImageDrawable(new BitmapDrawable(getResources(), temporaryBitmap));

            faceDetector.release();
        }
    }

    private void initializeBitmap(BitmapFactory.Options bitmapOptions) {
        defaultBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.modellook44,
                bitmapOptions);


        temporaryBitmap = Bitmap.createBitmap(defaultBitmap.getWidth(), defaultBitmap
                .getHeight(), Bitmap.Config.RGB_565);
      /*  eyePatchBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.fs1,
                bitmapOptions);*/


    }

    private void createRectanglePaint() {
        rectPaint = new Paint();
        rectPaint.setStrokeWidth(5);

        rectPaint.setColor(Color.CYAN);
        rectPaint.setStyle(Paint.Style.STROKE);
    }

    private void detectFaces(SparseArray<Face> sparseArray) {

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

            float left = (face.getPosition().x);
            float top = (face.getPosition().y);
            float right = left + face.getWidth();
            float bottom = right + face.getHeight();
            float cornerRadius = 2.0f;

            RectF rectF = new RectF(left, top, right, bottom);
           canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, rectPaint);
           // canvas.drawBitmap(eyePatchBitmap, left , top , null);
            detectLandmarks(face);
        }
    }

    private void detectLandmarks(Face face) {
        for (Landmark landmark : face.getLandmarks()) {

            int cx = (int) (landmark.getPosition().x);
            int cy = (int) (landmark.getPosition().y);





          drawLandmarkType(landmark.getType(), cx, cy);
            Log.d("landmark.getType()----",""+landmark.getType());

        }
    }

    private void drawLandmarkType(int landmarkType, float cx, float cy) {
        String type = String.valueOf(landmarkType);
        rectPaint.setTextSize(50);
        canvas.drawText(type, cx, cy, rectPaint);
    }

`

Beloo
  • 9,723
  • 7
  • 40
  • 71
sri
  • 105
  • 9
  • 1
    Welcome to SO. Please *proof read before posting* - See http://stackoverflow.com/help/how-to-ask. You have a MAJOR flaw in your title. You want to DETECT a head not DEDUCT a head. That's what the Queen of Hearts in Alice of Wonderland wanted to do... – micstr Oct 19 '16 at 09:11
  • ok thanks @micstr did you know that answer – sri Oct 19 '16 at 09:46

0 Answers0