Mercurial > hg > nsaunier > traffic-intelligence
annotate include/cvutils.hpp @ 804:17e54690af8a dev
work in progress, not fully functional yet
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 01 Jun 2016 17:57:49 -0400 |
| parents | b6ad86ee7033 |
| children |
| rev | line source |
|---|---|
| 9 | 1 #ifndef CVUTILS_HPP |
| 2 #define CVUTILS_HPP | |
| 3 | |
|
126
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
70
diff
changeset
|
4 #include "opencv2/core/core.hpp" |
|
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
70
diff
changeset
|
5 #include "opencv2/features2d/features2d.hpp" |
| 9 | 6 |
|
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
7 class CvCapture; |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
8 |
|
147
0089fb29cd26
added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
144
diff
changeset
|
9 /** Projects a point with the homography matrix |
|
0089fb29cd26
added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
144
diff
changeset
|
10 use perspectiveTransform for arrays of points. */ |
|
804
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
11 //cv::Point2f project(const cv::Point2f& p, const cv::Mat& homography); |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
12 template<typename T> |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
13 inline cv::Point_<T> project(const cv::Point_<T>& p, const cv::Mat_<T>& homography) { |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
14 if (homography.empty()) |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
15 return p; |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
16 else { |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
17 T x, y; |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
18 T w = homography.template at<T>(2,0)*p.x+homography.template at<T>(2,1)*p.y+homography.template at<T>(2,2); |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
19 if (w != 0.) { |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
20 x = (homography.template at<T>(0,0)*p.x+homography.template at<T>(0,1)*p.y+homography.template at<T>(0,2))/w; |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
21 y = (homography.template at<T>(1,0)*p.x+homography.template at<T>(1,1)*p.y+homography.template at<T>(1,2))/w; |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
22 } else { |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
23 x = 0.; |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
24 y = 0.; |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
25 } |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
26 return cv::Point_<T>(x, y); |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
27 } |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
28 } |
|
147
0089fb29cd26
added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
144
diff
changeset
|
29 |
|
144
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
139
diff
changeset
|
30 /** Loads a cv mat from a text file where the numbers are saved line by line separated by separator */ |
|
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
139
diff
changeset
|
31 cv::Mat loadMat(const std::string& filename, const std::string& separator); |
|
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
139
diff
changeset
|
32 |
|
804
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
33 inline bool inImage(const cv::Point2f& p, const cv::Size s) { return (p.x >= 0) && (p.x <= s.width) && (p.y >= 0) && (p.y <= s.height); } |
|
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
481
diff
changeset
|
34 |
|
481
b6ad86ee7033
implemented smoothing (requires latest trajectory management library version)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
407
diff
changeset
|
35 //template<typename T> |
|
b6ad86ee7033
implemented smoothing (requires latest trajectory management library version)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
407
diff
changeset
|
36 //float scalarProduct(const cv::Point_<T>& v1, const cv::Point_<T>& v2) { return v1.x*v2.x+v1.y*v2.y;} |
|
139
47329bd16cc0
cleaned code, added condition on smooth displacement
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
37 |
|
128
536510f60854
new features generated as needed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
127
diff
changeset
|
38 void keyPoints2Points(const std::vector<cv::KeyPoint>& kpts, std::vector<cv::Point2f>& pts, const bool& clearPts = true); |
|
126
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
70
diff
changeset
|
39 |
|
12
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
40 /** Goes to the target frame number, by querying frame, |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
41 supposing the video input is currently at current frame number. |
|
ff5403319cec
optical flow demo working
Nicolas Saunier <nico@confins.net>
parents:
11
diff
changeset
|
42 Returns the frame number that was reached.*/ |
|
407
5eeb3b9fb568
commented problem code (opencv 2.4.6)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
147
diff
changeset
|
43 // int goToFrameNum(CvCapture* inputVideo, const int& currentFrameNum, const int& targetFrameNum); |
|
11
e77e2fd69b02
modularized code (not compiling)
Nicolas Saunier <nico@confins.net>
parents:
9
diff
changeset
|
44 |
| 131 | 45 /// Pre-defined colors |
| 46 class Colors { | |
| 47 public: | |
| 48 static const int nColors = 8; | |
| 49 static const cv::Scalar color[]; | |
| 50 | |
| 51 static cv::Scalar black(void); | |
| 52 static cv::Scalar red(void); | |
| 53 static cv::Scalar green(void); | |
| 54 static cv::Scalar blue(void); | |
| 55 static cv::Scalar white(void); | |
| 56 static cv::Scalar magenta(void); | |
| 57 static cv::Scalar cyan(void); | |
| 58 static cv::Scalar yellow(void); | |
| 59 | |
| 60 /** Maps integers to primary colors. */ | |
| 61 static cv::Scalar color3(const int& num); | |
| 62 static cv::Scalar color8(const int& num); | |
| 63 }; | |
| 64 | |
| 9 | 65 #endif |
