title: xutility file?
body: <p>I'm trying to use C code with opencv in face
  detection and counting, but I cannot build the source.
  I am trying to compile my project and I am
  having a lot of problems with a line in the xutility file. </p>
  
  <p>The error message shows that it is giving errors in the xutility file.</p>
  
  <p>Please help me solve this problem?</p>
  
  <h3>Code</h3>
  
  <pre><code>// Include header files
  #include "stdafx.h"
  #include "cv.h"
  #include "highgui.h"
  
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;math.h&gt;
  #include &lt;float.h&gt;
  #include &lt;limits.h&gt;
  #include &lt;time.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;vector&gt;
  
  using namespace std;
  
  
  #ifdef _EiC
  #define WIN32
  #endif
  
  int countfaces=0;
  int numFaces = 0;
  int k=0 ;
  int list=0;
  char filelist[512][512];
  
  int timeCount = 0;
  
  static CvMemStorage* storage = 0;
  static CvHaarClassifierCascade* cascade = 0;
  
  void detect_and_draw( IplImage* image );
  
  void WriteInDB();
  int found_face(IplImage* img,CvPoint pt1,CvPoint pt2);
  int load_DB(char * filename);
  
  
  const char* cascade_name = "C:\\Program Files\\OpenCV\\OpenCV2.1\\data\\haarcascades\\haarcascade_frontalface_alt_tree.xml"; 
  
  
  // BEGIN NEW CODE
  #define WRITEVIDEO
  char* outputVideo = "c:\\face_counting1_tracked.avi";
  //int faceCount = 0;
  int posBuffer = 100;
  int persistDuration = 10; //faces can drop out for 10 frames
  int timestamp = 0;
  float sameFaceDistThreshold = 30; //pixel distance
  CvPoint facePositions[100];
  int     facePositionsTimestamp[100];
  
  float distance( CvPoint a, CvPoint b ) {
      float dist = sqrt(float ( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) ) );
      return dist;
  }
  
  void expirePositions()
  {
      for (int i = 0; i &lt; posBuffer; i++)
      {
          if (facePositionsTimestamp[i] &lt;= (timestamp - persistDuration))    //if a tracked pos is older than three frames
          {
              facePositions[i] = cvPoint(999,999);
          }
      }
  }
  
  void updateCounter(CvPoint center) 
  {
      bool newFace = true;
      for(int i = 0; i &lt; posBuffer; i++) 
      {
          if (distance(center, facePositions[i]) &lt; sameFaceDistThreshold)
          {
              facePositions[i] = center;
              facePositionsTimestamp[i] = timestamp;
              newFace = false;
              break;
          }
      }
      if(newFace)
      {
          //push out oldest tracker
          for(int i = 1; i &lt; posBuffer; i++) 
          {
              facePositions[i] = facePositions[i - 1];
          }
          //put new tracked position on top of stack
          facePositions[0] = center;
          facePositionsTimestamp[0] = timestamp;
          countfaces++;
      }
  }
  
  void drawCounter(IplImage* image) {
      // Create Font
      char buffer[5];
      CvFont font;
      cvInitFont(&amp;font, CV_FONT_HERSHEY_SIMPLEX, .5, .5, 0, 1);
      cvPutText(image, "Faces:", cvPoint(20, 20), &amp;font, CV_RGB(0,255,0));
      cvPutText(image, itoa(countfaces, buffer, 10), cvPoint(80, 20), &amp;font, CV_RGB(0,255,0));
  }
  #ifdef WRITEVIDEO
  CvVideoWriter* videoWriter = cvCreateVideoWriter(outputVideo, -1, 30, cvSize(240, 180));
  #endif
  //END NEW CODE
  
  int main( int argc, char** argv )
  {
  
      CvCapture* capture = 0;
      IplImage *frame, *frame_copy = 0;
      int optlen = strlen("--cascade=");
      const char* input_name;
  
      if( argc &gt; 1 &amp;&amp; strncmp( argv[1], "--cascade=", optlen ) == 0 )
      {
          cascade_name = argv[1] + optlen;
          input_name = argc &gt; 2 ? argv[2] : 0;
      }
      else
      {
          cascade_name =  "C:\\Program Files\\OpenCV\\OpenCV2.1\\data\\haarcascades\\haarcascade_frontalface_alt_tree.xml"; 
  
          input_name = argc &gt; 1 ? argv[1] : 0;
      }
  
      cascade = (CvHaarClassifierCascade*)cvLoad( cascade_name, 0, 0, 0 );
  
      if( !cascade )
      {
          fprintf( stderr, "ERROR: Could not load classifier cascade\n" );
          fprintf( stderr,
          "Usage: facedetect --cascade=\"&lt;cascade_path&gt;\" [filename|camera_index]\n" );
          return -1;
      }
      storage = cvCreateMemStorage(0);
  
      //if( !input_name || (isdigit(input_name[0]) &amp;&amp; input_name[1] == '\0') )
      //    capture = cvCaptureFromCAM( !input_name ? 0 : input_name[0] - '0' );
      //else
  
      capture = cvCaptureFromAVI( "c:\\face_counting1.avi" ); 
  
      cvNamedWindow( "result", 1 );
  
      if( capture )
      {
          for(;;)
          {
              if( !cvGrabFrame( capture ))
                  break;
              frame = cvRetrieveFrame( capture );
              if( !frame )
                  break;
              if( !frame_copy )
                  frame_copy = cvCreateImage( cvSize(frame-&gt;width,frame-&gt;height),
                                              IPL_DEPTH_8U, frame-&gt;nChannels );
              if( frame-&gt;origin == IPL_ORIGIN_TL )
                  cvCopy( frame, frame_copy, 0 );
              else
                  cvFlip( frame, frame_copy, 0 );
  
              detect_and_draw( frame_copy );
  
              if( cvWaitKey( 30 ) &gt;= 0 )
                  break;
          }
  
          cvReleaseImage( &amp;frame_copy );
          cvReleaseCapture( &amp;capture );
      }
      else
      {
          if( !input_name || (isdigit(input_name[0]) &amp;&amp; input_name[1] == '\0'))
          cvNamedWindow( "result", 1 );
          const char* filename = input_name ? input_name : (char*)"lena.jpg";
          IplImage* image = cvLoadImage( filename, 1 );
  
          if( image )
          {
              detect_and_draw( image );
              cvWaitKey(0);
              cvReleaseImage( &amp;image );
          }
          else
          {
              /* assume it is a text file containing the
                 list of the image filenames to be processed - one per line */
              FILE* f = fopen( filename, "rt" );
              if( f )
              {
                  char buf[1000+1];
                  while( fgets( buf, 1000, f ) )
                  {
                      int len = (int)strlen(buf);
                      while( len &gt; 0 &amp;&amp; isspace(buf[len-1]) )
                          len--;
                      buf[len] = '\0';
                      image = cvLoadImage( buf, 1 );
                      if( image )
                      {
                          detect_and_draw( image );
                          cvWaitKey(0);
                          cvReleaseImage( &amp;image );
                      }
                  }
                  fclose(f);
              }
          }
  
      }
  
      cvDestroyWindow("result");
      #ifdef WRITEVIDEO
      cvReleaseVideoWriter(&amp;videoWriter); 
      #endif
      return 0;
  }
  
  void detect_and_draw( IplImage* img )
  {
      static CvScalar colors[] = 
      {
          {{0,0,255}},
          {{0,128,255}},
          {{0,255,255}},
          {{0,255,0}},
          {{255,128,0}},
          {{255,255,0}},
          {{255,0,0}},
          {{255,0,255}}
      };
  
           double scale = 1.3;
          IplImage* gray = cvCreateImage( cvSize(img-&gt;width,img-&gt;height), 8, 1 );
           IplImage* small_img = cvCreateImage( cvSize( cvRound (img-&gt;width/scale),
                           cvRound (img-&gt;height/scale)),
                       8, 1 );
          CvPoint pt1, pt2;
          int i;
  
          cvCvtColor( img, gray, CV_BGR2GRAY );
          cvResize( gray, small_img, CV_INTER_LINEAR );
           cvEqualizeHist( small_img, small_img );
          cvClearMemStorage( storage );
  
          if( cascade )
              {
              double t = (double)cvGetTickCount();
              CvSeq* faces = cvHaarDetectObjects( small_img, cascade, storage,
                                              1.1, 2, 0/*CV_HAAR_DO_CANNY_PRUNING*/,
                                              cvSize(30, 30) );
              t = (double)cvGetTickCount() - t;
              printf( "detection time = %gms\n", t/((double)cvGetTickFrequency()*1000.) );
  
              if (faces)
              {
              //To save the detected faces into separate images, here's a quick and dirty code:
              char filename[6];
  
              for( i = 0; i &lt; (faces ? faces-&gt;total : 0); i++ )
               {
                  /* CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
                  CvPoint center;
                  int radius;
                  center.x = cvRound((r-&gt;x + r-&gt;width*0.5)*scale);
                  center.y = cvRound((r-&gt;y + r-&gt;height*0.5)*scale); 
                  radius = cvRound((r-&gt;width + r-&gt;height)*0.25*scale);
                  cvCircle( img, center, radius, colors[i%8], 3, 8, 0 );*/
                  // Create a new rectangle for drawing the face
                  CvRect* r = (CvRect*)cvGetSeqElem( faces, i );
  
                  // Find the dimensions of the face,and scale it if necessary
                  pt1.x = r-&gt;x*scale;
                  pt2.x = (r-&gt;x+r-&gt;width)*scale;
                  pt1.y = r-&gt;y*scale;
                  pt2.y = (r-&gt;y+r-&gt;height)*scale;
  
                  // Draw the rectangle in the input image
                  cvRectangle( img, pt1, pt2, CV_RGB(255,0,0), 3, 8, 0 );
                  CvPoint center;
                  int radius;
                  center.x = cvRound((r-&gt;x + r-&gt;width*0.5)*scale);
                  center.y = cvRound((r-&gt;y + r-&gt;height*0.5)*scale); 
                  radius = cvRound((r-&gt;width + r-&gt;height)*0.25*scale);
                  cvCircle( img, center, radius, CV_RGB(255,0,0), 3, 8, 0 );
  
                  //update counter
                  updateCounter(center);
  
                  int y=found_face(img,pt1,pt2);
                  if(y==0)
                  countfaces++;
              }//end for
              printf("Number of detected faces: %d\t",countfaces);
  
      }//end if 
      //delete old track positions from facePositions array
      expirePositions();
      timestamp++;
  
      //draw counter
      drawCounter(img);
      #ifdef WRITEVIDEO
      cvWriteFrame(videoWriter, img);
      #endif
      cvShowImage( "result", img );
       cvDestroyWindow("Result");
      cvReleaseImage( &amp;gray );
      cvReleaseImage( &amp;small_img );
  }//end if
  } //end void
  
  
  int found_face(IplImage* img,CvPoint pt1,CvPoint pt2)
  {
          /*if (faces)
              {*/
          CvSeq* faces = cvHaarDetectObjects( img, cascade, storage,
                                              1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
                                              cvSize(40, 40) );
          int i=0;
          char filename[512];
           for( i = 0; i &lt; (faces ? faces-&gt;total : 0); i++ )
            {//int scale = 1, i=0;
              //i=iface;
              //char filename[512];
  
              /* extract the rectanlges only */
               //  CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i);
              CvRect face_rect = *(CvRect*)cvGetSeqElem( faces, i);
  
  
              //IplImage* gray_img = cvCreateImage( cvGetSize(img), IPL_DEPTH_8U, 1 );
              IplImage* clone = cvCreateImage (cvSize(img-&gt;width, img-&gt;height),
                                      IPL_DEPTH_8U, img-&gt;nChannels );
              IplImage* gray = cvCreateImage (cvSize(img-&gt;width, img-&gt;height),
                                      IPL_DEPTH_8U, 1 );
  
              cvCopy (img, clone, 0);
              cvNamedWindow ("ROI", CV_WINDOW_AUTOSIZE);
              cvCvtColor( clone, gray, CV_RGB2GRAY );
              face_rect.x = pt1.x;
              face_rect.y = pt1.y;
              face_rect.width = abs(pt1.x - pt2.x);
              face_rect.height = abs(pt1.y - pt2.y);
  
  
               cvSetImageROI ( gray, face_rect);
              ////    * rectangle  = cvGetImageROI ( clone );
              face_rect = cvGetImageROI ( gray );
              cvShowImage ("ROI", gray);
              k++;
              char *name=0;
               name=(char*) calloc(512, 1);
              sprintf(name, "Image%d.pgm", k);
              cvSaveImage(name, gray);
  
              ////////////////
              for(int j=0;j&lt;512;j++)
              filelist[list][j]=name[j];
              list++;
              WriteInDB();
              //int found=SIFT("result.txt",name);
              cvResetImageROI( gray );
              //return found;
              return 0;
          //  }//end if
  
          }//end for
  }//end void
  
  void WriteInDB()
  {
  ofstream myfile;
  myfile.open ("result.txt");
  for(int i=0;i&lt;512;i++)
  {
  if(strcmp(filelist[i],"")!=0)
  myfile &lt;&lt; filelist[i]&lt;&lt;"\n";
  }
  myfile.close();
  }
  </code></pre>
  
  <h3>Error messages</h3>
  
  <pre><code>Error   3   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   
  Error   8   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   
  Error   13  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files\microsoft visual studio 9.0\vc\include\xutility    766
  Error   18  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files\microsoft visual studio 9.0\vc\include\xutility    768
  Error   23  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\program files\microsoft visual studio 9.0\vc\include\xutility    769
  Error   10  error C2868: 'std::iterator_traits&lt;_Iter&gt;::value_type' : illegal syntax for using-declaration; expected qualified-name  c:\program files\microsoft visual studio 9.0\vc\include\xutility    765
  Error   25  error C2868: 'std::iterator_traits&lt;_Iter&gt;::reference' : illegal syntax for using-declaration; expected qualified-name   c:\program files\microsoft visual studio 9.0\vc\include\xutility    769
  Error   20  error C2868: 'std::iterator_traits&lt;_Iter&gt;::pointer' : illegal syntax for using-declaration; expected qualified-name c:\program files\microsoft visual studio 9.0\vc\include\xutility    768
  Error   5   error C2868: 'std::iterator_traits&lt;_Iter&gt;::iterator_category' : illegal syntax for using-declaration; expected qualified-name   c:\program files\microsoft visual studio 9.0\vc\include\xutility    764
  Error   15  error C2868: 'std::iterator_traits&lt;_Iter&gt;::difference_type' : illegal syntax for using-declaration; expected qualified-name c:\program files\microsoft visual studio 9.0\vc\include\xutility    766
  Error   9   error C2602: 'std::iterator_traits&lt;_Iter&gt;::value_type' is not a member of a base class of 'std::iterator_traits&lt;_Iter&gt;' c:\program files\microsoft visual studio 9.0\vc\include\xutility    765
  Error   24  error C2602: 'std::iterator_traits&lt;_Iter&gt;::reference' is not a member of a base class of 'std::iterator_traits&lt;_Iter&gt;'  c:\program files\microsoft visual studio 9.0\vc\include\xutility    769
  Error   19  error C2602: 'std::iterator_traits&lt;_Iter&gt;::pointer' is not a member of a base class of 'std::iterator_traits&lt;_Iter&gt;'    c:\program files\microsoft visual studio 9.0\vc\include\xutility    768
  Error   4   error C2602: 'std::iterator_traits&lt;_Iter&gt;::iterator_category' is not a member of a base class of 'std::iterator_traits&lt;_Iter&gt;'  c:\program files\microsoft visual studio 9.0\vc\include\xutility    764
  Error   14  error C2602: 'std::iterator_traits&lt;_Iter&gt;::difference_type' is not a member of a base class of 'std::iterator_traits&lt;_Iter&gt;'    c:\program files\microsoft visual studio 9.0\vc\include\xutility    766
  Error   7   error C2146: syntax error : missing ';' before identifier 'value_type'  c:\program files\microsoft visual studio 9.0\vc\include\xutility    765
  Error   22  error C2146: syntax error : missing ';' before identifier 'reference'   c:\program files\microsoft visual studio 9.0\vc\include\xutility    769
  Error   17  error C2146: syntax error : missing ';' before identifier 'pointer' c:\program files\microsoft visual studio 9.0\vc\include\xutility    768
  Error   2   error C2146: syntax error : missing ';' before identifier 'iterator_category'   c:\program files\microsoft visual studio 9.0\vc\include\xutility    764
  Error   12  error C2146: syntax error : missing ';' before identifier 'difference_type' c:\program files\microsoft visual studio 9.0\vc\include\xutility    766
  Error   6   error C2039: 'value_type' : is not a member of 'CvPoint'    c:\program files\microsoft visual studio 9.0\vc\include\xutility    765
  Error   21  error C2039: 'reference' : is not a member of 'CvPoint' c:\program files\microsoft visual studio 9.0\vc\include\xutility    769
  Error   16  error C2039: 'pointer' : is not a member of 'CvPoint'   c:\program files\microsoft visual studio 9.0\vc\include\xutility    768
  Error   1   error C2039: 'iterator_category' : is not a member of 'CvPoint' c:\program files\microsoft visual studio 9.0\vc\include\xutility    764
  Error   11  error C2039: 'difference_type' : is not a member of 'CvPoint'   c:\program files\microsoft visual studio 9.0\vc\include\xutility    766
  </code></pre>