Mercurial Hosting > traffic-intelligence
view c/cvutils.cpp @ 128:536510f60854
new features generated as needed
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 17 Aug 2011 02:44:28 -0400 |
parents | d19d6e63dd77 |
children | 3a11dba30655 |
line wrap: on
line source
#include "cvutils.hpp" //#include "opencv/cv.h" #include "opencv2/highgui/highgui.hpp" #include "opencv2/features2d/features2d.hpp" #include <iostream> #include <vector> using namespace std; using namespace cv; void keyPoints2Points(const vector<KeyPoint>& kpts, vector<Point2f>& pts, const bool& clearPts /* = true */) { if (clearPts) pts.clear(); pts.reserve(kpts.size()); for (unsigned int i=0; i<kpts.size(); i++) pts.push_back(kpts[i].pt); } 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; }