Mercurial > hg > nsaunier > traffic-intelligence
annotate c/cvutils.cpp @ 135:32d2722d4028
added constraint on minimum displacement
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 18 Aug 2011 01:03:38 -0400 |
| parents | 3a11dba30655 |
| children | b32947b002da |
| rev | line source |
|---|---|
| 9 | 1 #include "cvutils.hpp" |
| 2 | |
| 131 | 3 #include "opencv2/core/core.hpp" |
|
126
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
4 #include "opencv2/highgui/highgui.hpp" |
|
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
5 #include "opencv2/features2d/features2d.hpp" |
| 9 | 6 |
| 7 #include <iostream> | |
|
126
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
8 #include <vector> |
| 9 | 9 |
| 10 using namespace std; | |
|
126
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
11 using namespace cv; |
|
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
12 |
|
128
536510f60854
new features generated as needed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
127
diff
changeset
|
13 void keyPoints2Points(const vector<KeyPoint>& kpts, vector<Point2f>& pts, const bool& clearPts /* = true */) { |
|
536510f60854
new features generated as needed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
127
diff
changeset
|
14 if (clearPts) |
|
536510f60854
new features generated as needed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
127
diff
changeset
|
15 pts.clear(); |
|
127
d19d6e63dd77
simple feature tracking and drawing working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
126
diff
changeset
|
16 pts.reserve(kpts.size()); |
|
126
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
17 |
|
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
18 for (unsigned int i=0; i<kpts.size(); i++) |
|
127
d19d6e63dd77
simple feature tracking and drawing working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
126
diff
changeset
|
19 pts.push_back(kpts[i].pt); |
|
126
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
20 } |
| 9 | 21 |
| 22 IplImage* allocateImage(const int& width, const int& height, const int& depth, const int& channels) { return ::allocateImage(cvSize(width, height), depth, channels);} | |
| 23 | |
| 24 IplImage* allocateImage(const CvSize& size, const int& depth, const int& channels) { | |
| 25 IplImage* image = cvCreateImage(size, depth, channels); | |
| 26 | |
| 27 if (!image) { | |
| 28 cerr << "Error: Couldn't allocate image. Out of memory?\n" << endl; | |
| 29 exit(-1); | |
| 30 } | |
| 31 | |
| 32 return image; | |
| 33 } | |
|
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
34 |
|
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
35 int goToFrameNum(CvCapture* inputVideo, const int& currentFrameNum, const int& targetFrameNum) { |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
36 int frameNum = currentFrameNum; |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
37 if (currentFrameNum > targetFrameNum) { |
|
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
38 cerr << "Current frame number " << currentFrameNum << " is after the target frame number " << targetFrameNum << "." << endl; |
|
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
39 } else if (currentFrameNum < targetFrameNum) { |
|
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
40 IplImage* frame = cvQueryFrame(inputVideo); |
|
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
41 frameNum++; |
|
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
42 while (frame && frameNum<targetFrameNum) { |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
43 frame = cvQueryFrame(inputVideo); |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
44 frameNum++; |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
45 } |
|
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
46 } |
|
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
47 |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
48 return frameNum; |
|
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
49 } |
| 131 | 50 |
| 51 const Scalar Colors::color[] = {Colors::red(), | |
| 52 Colors::green(), | |
| 53 Colors::blue(), | |
| 54 Colors::cyan(), | |
| 55 Colors::magenta(), | |
| 56 Colors::yellow(), | |
| 57 Colors::white(), | |
| 58 Colors::black()}; | |
| 59 | |
| 60 Scalar Colors::black(void) { return Scalar(0,0,0);} | |
| 61 Scalar Colors::red(void) { return Scalar(255,0,0);} | |
| 62 Scalar Colors::green(void) { return Scalar(0,255,0);} | |
| 63 Scalar Colors::blue(void) { return Scalar(0,0,255);} | |
| 64 Scalar Colors::white(void) { return Scalar(255,255,255);} | |
| 65 Scalar Colors::magenta(void) { return Scalar(255,0,255);} | |
| 66 Scalar Colors::cyan(void) { return Scalar(0,255,255);} | |
| 67 Scalar Colors::yellow(void) { return Scalar(255,255,0);} | |
| 68 | |
| 69 Scalar Colors::color3(const int& num) { return Colors::color[num%3];} | |
| 70 Scalar Colors::color8(const int& num) { return Colors::color[num%Colors::nColors];} |
