Example #1
0
int main( int argc, char** argv)
{
  if ( argc != 2 )
  {
    cout << "Usage :" << argv[0] << " <video/image filename or camera device>" << endl;
    exit(0);
  }

  cout << "Opening " << argv[1] << endl;
  capture = new Capture( argv[1]);

  char type[32];
  strcpy( type, capture->getType());
  cout << "Type :" << type << endl;

  float fps = 100;

  cvNamedWindow( "Video", 1);

  if ( !strncmp( type, "VIDEO", 5))
  {
    delete capture;
    capture = new VideoCapture( argv[1]);

    VideoCapture* temp = (VideoCapture*) capture;

    //cout << "Width : " <<  temp->getWidth() << endl;
    //cout << "Height : " <<  temp->getHeight() << endl;
    //cout << "Duration : " << temp->getDuration() << endl;
    //cout << "FPS : " << temp->getFPS() << endl;

    fps = 25;
  }
  else
  {
    fprintf( stderr, "Couldn't Not Detect Type of Source");
    fprintf( stderr, " or No Handeller Available\n");
    exit(0);
  }

  if ( !(strncmp( capture->getType(), "VIDEO", 5)))
  {
    VideoCapture* temp = (VideoCapture*) capture;
    temp->play();
    cout << capture->getStatus();
  }

  IplImage* image = NULL;

  if (( capture->getWidth() > 0) && (capture->getHeight() > 0))
  {
    image = cvCreateImageHeader( cvSize(capture->getWidth(),
          capture->getHeight()), IPL_DEPTH_8U, 3);
  }
  else
  {
    cout << capture->getStatus();
    return 0;
  }
  //Assuming height 1100 and width 2000
  vecDetections =  new vector<Detection>* [1100];
  for( int i=0; i<1100; i++)
    vecDetections[i] = new vector<Detection>[2000];


  char key=' ';
  for( int i = 0; ;)
  {
    image->imageData = (char*) capture->getNextFrame();
    processFrameFastHog(image);

    if ( image->imageData == NULL) break;

    cvShowImage( "Video", image);

    key = cvWaitKey((int) 1000.0 / fps);
    if (( key == '\n') && ( i == 0))
    {
      i = 1;
      if ( !(strncmp( capture->getType(), "VIDEO", 5)))
      {
        VideoCapture* temp = (VideoCapture*) capture;
        temp->pause();
      }
    }
    else if( key == 27) break;
  }

  fstream outfile;
  outfile.open("dump.txt", ios_base::out);

  for(int i=0; i<capture->getHeight(); i++)
    for(int j=0; j<capture->getWidth(); j++)
    {
      vector<Detection> detVec = vecDetections[i][j];
      for(int k=0; k<detVec.size(); k++)
      {
        outfile << detVec[k].y << " " << detVec[k].x << " " << detVec[k].width;
        outfile << " " << detVec[k].height << " " << detVec[k].scale << " " << detVec[k].score << endl;
      }
    }

  outfile.close();

  HOGEngine::Instance()->FinalizeHOG();
  delete capture;
  return 0;
}