Mercurial Hosting > traffic-intelligence
annotate c/cvutils.cpp @ 127:d19d6e63dd77
simple feature tracking and drawing working
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 17 Aug 2011 01:25:13 -0400 |
parents | 336926453b28 |
children | 536510f60854 |
rev | line source |
---|---|
9 | 1 #include "cvutils.hpp" |
2 | |
126
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
3 //#include "opencv/cv.h" |
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 |
127
d19d6e63dd77
simple feature tracking and drawing working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
126
diff
changeset
|
13 void keyPoints2Points(const vector<KeyPoint>& kpts, vector<Point2f>& pts) { |
d19d6e63dd77
simple feature tracking and drawing working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
126
diff
changeset
|
14 pts.clear(); |
d19d6e63dd77
simple feature tracking and drawing working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
126
diff
changeset
|
15 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
|
16 |
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
17 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
|
18 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
|
19 } |
9 | 20 |
21 IplImage* allocateImage(const int& width, const int& height, const int& depth, const int& channels) { return ::allocateImage(cvSize(width, height), depth, channels);} | |
22 | |
23 IplImage* allocateImage(const CvSize& size, const int& depth, const int& channels) { | |
24 IplImage* image = cvCreateImage(size, depth, channels); | |
25 | |
26 if (!image) { | |
27 cerr << "Error: Couldn't allocate image. Out of memory?\n" << endl; | |
28 exit(-1); | |
29 } | |
30 | |
31 return image; | |
32 } | |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
33 |
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
34 int goToFrameNum(CvCapture* inputVideo, const int& currentFrameNum, const int& targetFrameNum) { |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
35 int frameNum = currentFrameNum; |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
36 if (currentFrameNum > targetFrameNum) { |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
37 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
|
38 } else if (currentFrameNum < targetFrameNum) { |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
39 IplImage* frame = cvQueryFrame(inputVideo); |
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
40 frameNum++; |
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
41 while (frame && frameNum<targetFrameNum) { |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
42 frame = cvQueryFrame(inputVideo); |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
43 frameNum++; |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
44 } |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
45 } |
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
46 |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
47 return frameNum; |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
48 } |