Ask Your Question
1

why facedetection not happening in Portrait mode in Android , using javaCV cvHaarDetectObjects method

asked 2013-10-08 11:54:12 -0600

bunta gravatar image

updated 2013-10-08 12:38:51 -0600

berak gravatar image

I tried to modify the FacePreview.java sample provided for Android and since that code always open your camera in landscape mode, I added orientation logic in Preview.java, once we opens the camera:

mCamera.setDisplayOrientation(90);

When I ran the program I found always the Object detection i.e. cvHaarDetectObjects only works if the phone is in landscape mode, in other modes mainly in portrait, it's not at all detecting any face. What is the reason behind this?

faces = cvHaarDetectObjects(
    grayImage,
    classifier,
    storage,
    1.1,
    3,
    CV_HAAR_FEATURE_MAX
      | CV_HAAR_SCALE_IMAGE 
      | CV_HAAR_FIND_BIGGEST_OBJECT
      | CV_HAAR_DO_ROUGH_SEARCH
      | CV_HAAR_DO_CANNY_PRUNING);

faces.total always returns 0 when the phone is in portrait mode or orientation is different that landscape.

I tried modifying places but didn't find the expected.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-10-09 05:08:46 -0600

All Haar and LBP cascades were trained in single face orientation, so they works with the same orientation only. You need to rotate image or, better for performance, use different cascades for different camera orientation.

edit flag offensive delete link more

Comments

i tried following piece of code under onPreviewFrame overriden method but no luck-

IplImage my_image = (IplImage) grayImage; CvMat mat = my_image.asCvMat();

    int cols = mat.cols();
    int rows = mat.rows();
    IplImage DstImage = cvCreateImage(cvSize(rows, cols), IPL_DEPTH_8U, 1);


   int angle = ((180 / 90) % 4) * 90;

    //0 : flip vertical; 1 flip horizontal
    int flip_horizontal_or_vertical = angle > 0 ? 1 : 0;
    int  number = Math.abs(angle / 90);
    for(int i = 0; i != number; ++i){
        cvTranspose(grayImage, DstImage);        
        cvFlip(grayImage,DstImage,flip_horizontal_or_vertical);
    }
bunta gravatar imagebunta ( 2013-10-09 13:25:44 -0600 )edit

Question Tools

Stats

Asked: 2013-10-08 11:54:12 -0600

Seen: 1,045 times

Last updated: Oct 09 '13