Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:46:38+00:00 2026-05-29T20:46:38+00:00

I am using the code available in this website: http://nashruddin.com/OpenCV_Face_Detection to do face detection.

  • 0

I am using the code available in this website: http://nashruddin.com/OpenCV_Face_Detection to do face detection.

I would like to increase the size of the detected face region. I am not sure how to do it. Need some help on it..

The code i am using is this:
//

#include "stdafx.h"

#include <stdio.h>
#include <cv.h>
#include <highgui.h>

CvHaarClassifierCascade *cascade;
CvMemStorage            *storage;

void detectFaces( IplImage *img );

int main( int argc, char** argv )
{
    CvCapture *capture;
    IplImage  *frame;
    int       key;
    char      *filename = "C:/OpenCV2.1/data/haarcascades/haarcascade_frontalface_alt.xml";

    cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );
    storage = cvCreateMemStorage( 0 );
    capture = cvCaptureFromCAM( 0 );

    assert( cascade && storage && capture );

    cvNamedWindow( "video", 1 );

    while( key != 'q' ) {
        frame = cvQueryFrame( capture );

        if( !frame ) {
            fprintf( stderr, "Cannot query frame!\n" );
            break;
        }

        cvFlip( frame, frame, -1 );
        frame->origin = 0;

        detectFaces( frame );

        key = cvWaitKey( 10 );
    }

    cvReleaseCapture( &capture );
    cvDestroyWindow( "video" );
    cvReleaseHaarClassifierCascade( &cascade );
    cvReleaseMemStorage( &storage );

    return 0;
}

void detectFaces( IplImage *img )
{
    int i;

    CvSeq *faces = cvHaarDetectObjects(
            img,
            cascade,
            storage,
            1.1,
            3,
            0 /*CV_HAAR_DO_CANNY_PRUNNING*/,
            cvSize( 40, 40 ) );

    for( i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ ) {
        CvRect *r = ( CvRect* )cvGetSeqElem( faces, i );
        cvRectangle( img,
                     cvPoint( r->x, r->y ),
                     cvPoint( r->x + r->width, r->y + r->height ),
                     CV_RGB( 255, 0, 0 ), 1, 8, 0 );
    }

    cvShowImage( "video", img );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:46:38+00:00Added an answer on May 29, 2026 at 8:46 pm

    This increases the size of the rectangle around the face. If you meant increasing the haar detector’s window size, please update your question.

    int padding_width = 30; // pixels
    int padding_height = 30; // pixels
    
    for( i = 0 ; i < ( faces ? faces->total : 0 ) ; i++ ) {
        CvRect *r = ( CvRect* )cvGetSeqElem( faces, i );
    
        // Yes yes, all of this could be written much more compactly.
        // It was written like this for clarity.
    
        int topleft_x = r->x - (padding_width / 2);
        int topleft_y = r->y - (padding_height / 2);
        if (topleft_x < 0)
            topleft_x = 0;
        if (topleft_y < 0)
            topleft_y = 0;
    
        int bottomright_x = r->x + r->width + (padding_width / 2);
        int bottomright_y = r->y + r->height + (padding_height / 2);
        if (bottomright_x >= img->width)
            bottomright_x = img->width - 1;
        if (bottomright_y >= img->height)
            bottomright_y = img->height - 1;
    
        cvRectangle( img,
                     cvPoint(topleft_x, topleft_y),
                     cvPoint(bottomright_x, bottomright_y),
                     CV_RGB( 255, 0, 0 ), 1, 8, 0 );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the jQuery tooltip available on this website http://flowplayer.org/tools/tooltip and it's working fine
I'm using code that I found on the CodeProject.com for a low-level keyboard hook
I have been using code similar to this MessageDlg('', mtWarning, [mbOK], 0); throughout my
I am currently using code similar to this: try { // IE ONLY var
My website is available at http://visualise.ca/ and when you load a post by clicking
I would like to provide my Python GAE website in the user's own language,
I am using the following code in my website, for thumbnail creation: string furl
I'm writing a website using JSP. I want to have the website available in
using this example on dynamic list https://github.com/sandeepleo11/Dynamic-Select-Menus-in-Rails-3 I managed to get dynamic select in
I generate the jQuery cookie using this code: $.cookie('queueView', 'value', { path: '/' });

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.