Mercurial Hosting > traffic-intelligence
annotate c/cvutils.cpp @ 15:3ead4bcd001c
cleaned optical flow
author | Nicolas Saunier <nico@confins.net> |
---|---|
date | Sun, 15 Nov 2009 01:04:10 -0500 |
parents | ff5403319cec |
children | 336926453b28 |
rev | line source |
---|---|
9 | 1 #include "cvutils.hpp" |
2 | |
3 #include "opencv/cv.h" | |
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
4 #include "opencv/highgui.h" |
9 | 5 |
6 #include <iostream> | |
7 | |
8 using namespace std; | |
9 | |
10 IplImage* allocateImage(const int& width, const int& height, const int& depth, const int& channels) { return ::allocateImage(cvSize(width, height), depth, channels);} | |
11 | |
12 IplImage* allocateImage(const CvSize& size, const int& depth, const int& channels) { | |
13 IplImage* image = cvCreateImage(size, depth, channels); | |
14 | |
15 if (!image) { | |
16 cerr << "Error: Couldn't allocate image. Out of memory?\n" << endl; | |
17 exit(-1); | |
18 } | |
19 | |
20 return image; | |
21 } | |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
22 |
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
23 int goToFrameNum(CvCapture* inputVideo, const int& currentFrameNum, const int& targetFrameNum) { |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
24 int frameNum = currentFrameNum; |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
25 if (currentFrameNum > targetFrameNum) { |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
26 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
|
27 } else if (currentFrameNum < targetFrameNum) { |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
28 IplImage* frame = cvQueryFrame(inputVideo); |
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
29 frameNum++; |
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
30 while (frame && frameNum<targetFrameNum) { |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
31 frame = cvQueryFrame(inputVideo); |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
32 frameNum++; |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
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 |
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
36 return frameNum; |
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
37 } |