Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

FaceDetection is not happening over the proper region in an ImageViewer

I am trying to do a FaceDetection over an Image displayed over Android ImageView. I have made the ImageView as fulls screen mode, then I loaded the Image from storage as-

IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);

Then I ran the classifiers and then tried to draw the rectangle but its coming some other region-

canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

Following is the code sample-

public void process(String strImageFilePath) {


        ClassifierLoader classifierLoader = ClassifierLoader.getInstance(getContext());
        classifier = classifierLoader.getClassifier_face();
        classifier_mouth = classifierLoader.getClassifier_mouth();
        IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);
        cvClearMemStorage(storage);
        Log.i("imageimage ", ""+image.height()+" Width "+image.width());


        cvClearMemStorage(storage);
        faces = cvHaarDetectObjects(image, classifier, storage, 1.1, 4,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);
        mouth = cvHaarDetectObjects(image, classifier_mouth, storage, 1.1, 3,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);

        invalidate();

        Log.i("AYA ", "IMAGE AAYA " + image+" FAC "+faces.total()+" mouth "+mouth.total()+ " THIS "+this.getWidth() );

    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(20);
        paint.setStrokeWidth(8);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(20, 40, 5, paint);
        if(faces != null){
        if (faces.total() > 0) {

            String s = "Processed Face";
            float textWidth = paint.measureText(s);
            canvas.drawText(s, (getWidth() - textWidth) / 2, 20, paint);
            CvRect r = new CvRect(cvGetSeqElem(faces, 0));
            int x = r.x(), y = r.y(), w = r.width(), h = r.height();
            Log.i("IMAGE VIEW DRAW ", "x "+x+" y "+y+" w "+w+" h "+h);
            canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

            if(mouth.total() > 0){
                CvRect rct = new CvRect(cvGetSeqElem(mouth, 0));
                canvas.drawRect(new Rect(rct.x(),rct.y(),rct.x()+rct.width(),rct.y()+rct.height()), paint);
            }

        }
    }
    }

I believe I need to do something with the height of IplImage but since I am directly loading the same from storage , it might be the issue. I actually wanted to load the image from image viewer but I couldn;t get it :( http://answers.opencv.org/question/22636/how-to-load-an-iplimage-from-android-imageview/?comment=22662#comment-22662

This is how algorithm is currently drawing the rectangle-

image description

FaceDetection is not happening over the proper region in an ImageViewer

I am trying to do a FaceDetection over an Image displayed over Android ImageView. I have made the ImageView as fulls screen mode, then I loaded the Image from storage as-

IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);

Then I ran the classifiers and then tried to draw the rectangle but its coming some other region-

canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

Following is the code sample-

public void process(String strImageFilePath) {


        ClassifierLoader classifierLoader = ClassifierLoader.getInstance(getContext());
        classifier = classifierLoader.getClassifier_face();
        classifier_mouth = classifierLoader.getClassifier_mouth();
        IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);
        cvClearMemStorage(storage);
        Log.i("imageimage ", ""+image.height()+" Width "+image.width());


        cvClearMemStorage(storage);
        faces = cvHaarDetectObjects(image, classifier, storage, 1.1, 4,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);
        mouth = cvHaarDetectObjects(image, classifier_mouth, storage, 1.1, 3,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);

        invalidate();

        Log.i("AYA ", "IMAGE AAYA " + image+" FAC "+faces.total()+" mouth "+mouth.total()+ " THIS "+this.getWidth() );

    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(20);
        paint.setStrokeWidth(8);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(20, 40, 5, paint);
        if(faces != null){
        if (faces.total() > 0) {

            String s = "Processed Face";
            float textWidth = paint.measureText(s);
            canvas.drawText(s, (getWidth() - textWidth) / 2, 20, paint);
            CvRect r = new CvRect(cvGetSeqElem(faces, 0));
            int x = r.x(), y = r.y(), w = r.width(), h = r.height();
            Log.i("IMAGE VIEW DRAW ", "x "+x+" y "+y+" w "+w+" h "+h);
            canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

            if(mouth.total() > 0){
                CvRect rct = new CvRect(cvGetSeqElem(mouth, 0));
                canvas.drawRect(new Rect(rct.x(),rct.y(),rct.x()+rct.width(),rct.y()+rct.height()), paint);
            }

        }
    }
    }

I believe I need to do something with the height of IplImage but since I am directly loading the same from storage , it might be the issue. I actually wanted to load the image from image viewer but I couldn;t get it :( http://answers.opencv.org/question/22636/how-to-load-an-iplimage-from-android-imageview/?comment=22662#comment-22662

This is how algorithm is currently drawing the rectangle-

image description

on Using drawing rectangle as-

 canvas.drawRect(new Rect(x, y, w, y ), paint);

the Mouth rectange is not at all visible.

image description

click to hide/show revision 3
retagged

updated 2013-10-18 04:22:47 -0600

berak gravatar image

FaceDetection is not happening over the proper region in an ImageViewer

I am trying to do a FaceDetection over an Image displayed over Android ImageView. I have made the ImageView as fulls screen mode, then I loaded the Image from storage as-

IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);

Then I ran the classifiers and then tried to draw the rectangle but its coming some other region-

canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

Following is the code sample-

public void process(String strImageFilePath) {


        ClassifierLoader classifierLoader = ClassifierLoader.getInstance(getContext());
        classifier = classifierLoader.getClassifier_face();
        classifier_mouth = classifierLoader.getClassifier_mouth();
        IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);
        cvClearMemStorage(storage);
        Log.i("imageimage ", ""+image.height()+" Width "+image.width());


        cvClearMemStorage(storage);
        faces = cvHaarDetectObjects(image, classifier, storage, 1.1, 4,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);
        mouth = cvHaarDetectObjects(image, classifier_mouth, storage, 1.1, 3,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);

        invalidate();

        Log.i("AYA ", "IMAGE AAYA " + image+" FAC "+faces.total()+" mouth "+mouth.total()+ " THIS "+this.getWidth() );

    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(20);
        paint.setStrokeWidth(8);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(20, 40, 5, paint);
        if(faces != null){
        if (faces.total() > 0) {

            String s = "Processed Face";
            float textWidth = paint.measureText(s);
            canvas.drawText(s, (getWidth() - textWidth) / 2, 20, paint);
            CvRect r = new CvRect(cvGetSeqElem(faces, 0));
            int x = r.x(), y = r.y(), w = r.width(), h = r.height();
            Log.i("IMAGE VIEW DRAW ", "x "+x+" y "+y+" w "+w+" h "+h);
            canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

            if(mouth.total() > 0){
                CvRect rct = new CvRect(cvGetSeqElem(mouth, 0));
                canvas.drawRect(new Rect(rct.x(),rct.y(),rct.x()+rct.width(),rct.y()+rct.height()), paint);
            }

        }
    }
    }

I believe I need to do something with the height of IplImage but since I am directly loading the same from storage , it might be the issue. I actually wanted to load the image from image viewer but I couldn;t get it :( http://answers.opencv.org/question/22636/how-to-load-an-iplimage-from-android-imageview/?comment=22662#comment-22662

This is how algorithm is currently drawing the rectangle-

image description

on Using drawing rectangle as-

 canvas.drawRect(new Rect(x, y, w, y ), paint);

the Mouth rectange is not at all visible.

image description

FaceDetection is not happening over the proper region in an ImageViewer

I am trying to do a FaceDetection over an Image displayed over Android ImageView. I have made the ImageView as fulls screen mode, then I loaded the Image from storage as-

IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);

Then I ran the classifiers and then tried to draw the rectangle but its coming some other region-

canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

Following is the code sample-

public void process(String strImageFilePath) {


        ClassifierLoader classifierLoader = ClassifierLoader.getInstance(getContext());
        classifier = classifierLoader.getClassifier_face();
        classifier_mouth = classifierLoader.getClassifier_mouth();
        IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);
        cvClearMemStorage(storage);
        Log.i("imageimage ", ""+image.height()+" Width "+image.width());


        cvClearMemStorage(storage);
        faces = cvHaarDetectObjects(image, classifier, storage, 1.1, 4,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);
        mouth = cvHaarDetectObjects(image, classifier_mouth, storage, 1.1, 3,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);

        invalidate();

        Log.i("AYA ", "IMAGE AAYA " + image+" FAC "+faces.total()+" mouth "+mouth.total()+ " THIS "+this.getWidth() );

    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(20);
        paint.setStrokeWidth(8);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(20, 40, 5, paint);
        if(faces != null){
        if (faces.total() > 0) {

            String s = "Processed Face";
            float textWidth = paint.measureText(s);
            canvas.drawText(s, (getWidth() - textWidth) / 2, 20, paint);
            CvRect r = new CvRect(cvGetSeqElem(faces, 0));
            int x = r.x(), y = r.y(), w = r.width(), h = r.height();
            Log.i("IMAGE VIEW DRAW ", "x "+x+" y "+y+" w "+w+" h "+h);
            canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

            if(mouth.total() > 0){
                CvRect rct = new CvRect(cvGetSeqElem(mouth, 0));
                canvas.drawRect(new Rect(rct.x(),rct.y(),rct.x()+rct.width(),rct.y()+rct.height()), paint);
            }

        }
    }
    }

I believe I need to do something with the height of IplImage but since I am directly loading the same from storage , it might be the issue. I actually wanted to load the image from image viewer but I couldn;t get it :( http://answers.opencv.org/question/22636/how-to-load-an-iplimage-from-android-imageview/?comment=22662#comment-22662

This is how algorithm is currently drawing the rectangle-

image description

on Using drawing rectangle as-

 canvas.drawRect(new Rect(x, y, w, y ), paint);

the Mouth rectange is not at all visible.

image description

One observation I found is that the rectangle it draw is not for the face size, but it will match if I open the same window in portrait mode, so It may be something doing for portrait mode, and I need to somewhere invert the image. I am here directly just opening the Image in landscape mode

FaceDetection is not happening over the proper region in an ImageViewer

I am trying to do a FaceDetection over an Image displayed over Android ImageView. I have made the ImageView as fulls screen mode, then I loaded the Image from storage as-

IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);

Then I ran the classifiers and then tried to draw the rectangle but its coming some other region-

canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

Following is the code sample-

public void process(String strImageFilePath) {


        ClassifierLoader classifierLoader = ClassifierLoader.getInstance(getContext());
        classifier = classifierLoader.getClassifier_face();
        classifier_mouth = classifierLoader.getClassifier_mouth();
        IplImage image = cvLoadImage(strImageFilePath, // filename
                CV_LOAD_IMAGE_GRAYSCALE);
        cvClearMemStorage(storage);
        Log.i("imageimage ", ""+image.height()+" Width "+image.width());


        cvClearMemStorage(storage);
        faces = cvHaarDetectObjects(image, classifier, storage, 1.1, 4,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);
        mouth = cvHaarDetectObjects(image, classifier_mouth, storage, 1.1, 3,
                CV_HAAR_FIND_BIGGEST_OBJECT | CV_HAAR_DO_ROUGH_SEARCH);

        invalidate();

        Log.i("AYA ", "IMAGE AAYA " + image+" FAC "+faces.total()+" mouth "+mouth.total()+ " THIS "+this.getWidth() );

    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setTextSize(20);
        paint.setStrokeWidth(8);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(20, 40, 5, paint);
        if(faces != null){
        if (faces.total() > 0) {

            String s = "Processed Face";
            float textWidth = paint.measureText(s);
            canvas.drawText(s, (getWidth() - textWidth) / 2, 20, paint);
            CvRect r = new CvRect(cvGetSeqElem(faces, 0));
            int x = r.x(), y = r.y(), w = r.width(), h = r.height();
            Log.i("IMAGE VIEW DRAW ", "x "+x+" y "+y+" w "+w+" h "+h);
            canvas.drawRect(new Rect(x, y, x + w, y + h), paint);

            if(mouth.total() > 0){
                CvRect rct = new CvRect(cvGetSeqElem(mouth, 0));
                canvas.drawRect(new Rect(rct.x(),rct.y(),rct.x()+rct.width(),rct.y()+rct.height()), paint);
            }

        }
    }
    }

I believe I need to do something with the height of IplImage but since I am directly loading the same from storage , it might be the issue. I actually wanted to load the image from image viewer but I couldn;t get it :( http://answers.opencv.org/question/22636/how-to-load-an-iplimage-from-android-imageview/?comment=22662#comment-22662

This is how algorithm is currently drawing the rectangle-

image description

on Using drawing rectangle as-

 canvas.drawRect(new Rect(x, y, w, y ), paint);

the Mouth rectange is not at all visible.

image description

One observation I found is that the rectangle it draw is not for the face size, but it will match if I open the same window in portrait mode, so It may be something doing for portrait mode, and I need to somewhere invert the image. I am here directly just opening the Image in landscape mode

and If I don;t use full screen mode, then things are quite better like -

image description

But still not the perfect, using canvas.drawRect(new Rect(x, y, x + w, y + h), paint); Other case doesn;t even show the rectangle