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

  • SEARCH
  • Home
  • 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 7507435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:29:12+00:00 2026-05-29T22:29:12+00:00

I am trying to detect the face in the image and trying to save

  • 0

I am trying to detect the face in the image and trying to save the detected face as an image in OpenCV.

Having some problems in the detectfaces function below.

#include "stdafx.h"

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

CvHaarClassifierCascade *cascade;
CvMemStorage            *storage;

void detectFaces( IplImage *img );

int _tmain(int argc, _TCHAR* argv[])
{
  //CvCapture *capture;
  IplImage  *img;//*out;
  int       key = 0;
  char      *filename = "C:/OpenCV2.1/data/haarcascades/haarcascade_frontalface_alt.xml";

  cascade = ( CvHaarClassifierCascade* )cvLoad( filename, 0, 0, 0 );
  storage = cvCreateMemStorage( 0 );
  img     = cvLoadImage("Yurico.png");

  assert( cascade && storage && img );

  cvNamedWindow( "video:", 1 );
  //cvNamedWindow( "video1:", 1 );
  //out = detectFaces( img );
  detectFaces( img );
  cvWaitKey( 0 );
  //cvShowImage( "video", out );
  cvDestroyWindow( "video:" );
  //cvDestroyWindow( "video1:" );
  cvReleaseImage( &img );
  cvReleaseHaarClassifierCascade( &cascade );
  cvReleaseMemStorage( &storage );

  return 0;
}

void detectFaces( IplImage *img )
{
    int i;
     CvRect *r;
    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 );
    cvSetImageROI(img, CvRect *r);

    IplImage *img2 = cvCreateImage(cvGetSize(img), 
                              img->depth, 
                               img->nChannels);

    cvSaveImage("Lakshmen.jpg",img2); 
}

Have a error saying this :

 Error  1   error C2664: 'cvSetImageROI' : cannot convert parameter 2 from 'CvRect *' to 'CvRect'   c:\users\hp\documents\visual studio 2010\projects\facedetect\facedetect\facedetect.cpp  67  1   facedetect

Want to save the region of interest into another image. Any corrections or improvements do tell me..

  • 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-29T22:29:14+00:00Added an answer on May 29, 2026 at 10:29 pm

    you need to pass a CvRect and not a CvRect*, so you do not need the pointer (*) before r.
    and since it is already a cvRect you should just write:

     cvSetImageROI(img, &r);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to detect line segments in an image. From what I gather, the
I an trying to create a program that will detect a face in a
I'm trying to detect internet explorer version on remote machine. After some search with
I'm trying to upload an image to the Face.com API. It either takes a
I'm trying to develop a software where can detect face recognition using Kinect. Until
Trying to detect left click vs right click (without using jQuery!) and I have
I'm trying to detect the size of the screen I'm starting emacs on, and
I am trying to detect which web in sharepoint that the user is looking
I'm trying to detect when the onresize event ends in a browser. If I
I'm trying to detect Use after free() bugs, otherwise known as Dangling pointers. I

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.