view c/cvutils.cpp @ 120:46b166523bf8

added CMakeLists.txt for feature-based-tracking
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 15 Aug 2011 11:56:34 -0400
parents ff5403319cec
children 336926453b28
line wrap: on
line source

#include "cvutils.hpp"

#include "opencv/cv.h"
#include "opencv/highgui.h"

#include <iostream>

using namespace std;

IplImage* allocateImage(const int& width, const int& height, const int& depth, const int& channels) { return ::allocateImage(cvSize(width, height), depth, channels);}

IplImage* allocateImage(const CvSize& size, const int& depth, const int& channels) {
  IplImage* image = cvCreateImage(size, depth, channels);

  if (!image) {
    cerr << "Error: Couldn't allocate image.  Out of memory?\n" << endl;
    exit(-1);
  }

  return image;
}

int goToFrameNum(CvCapture* inputVideo, const int& currentFrameNum, const int& targetFrameNum) {
  int frameNum = currentFrameNum;
  if (currentFrameNum > targetFrameNum) {
    cerr << "Current frame number " << currentFrameNum << " is after the target frame number " << targetFrameNum << "." << endl;
  } else if (currentFrameNum < targetFrameNum) {
    IplImage* frame = cvQueryFrame(inputVideo);
    frameNum++;
    while (frame && frameNum<targetFrameNum) {
      frame = cvQueryFrame(inputVideo);
      frameNum++;
    }
  }
  
  return frameNum;
}