Mercurial Hosting > traffic-intelligence
annotate c/cvutils.cpp @ 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 | f7cf43b5ad3b |
children |
rev | line source |
---|---|
9 | 1 #include "cvutils.hpp" |
144
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
2 #include "utils.hpp" |
9 | 3 |
131 | 4 #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
|
5 #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
|
6 #include "opencv2/features2d/features2d.hpp" |
9 | 7 |
8 #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
|
9 #include <vector> |
9 | 10 |
11 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
|
12 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
|
13 |
804
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
14 // Point2f project(const Point2f& p, const Mat& homography) { |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
15 // float x, y; |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
16 // float w = homography.at<float>(2,0)*p.x+homography.at<float>(2,1)*p.y+homography.at<float>(2,2); |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
17 // if (w != 0) { |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
18 // x = (homography.at<float>(0,0)*p.x+homography.at<float>(0,1)*p.y+homography.at<float>(0,2))/w; |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
19 // y = (homography.at<float>(1,0)*p.x+homography.at<float>(1,1)*p.y+homography.at<float>(1,2))/w; |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
20 // } else { |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
21 // x = 0; |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
22 // y = 0; |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
23 // } |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
24 // return Point2f(x, y); |
17e54690af8a
work in progress, not fully functional yet
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
803
diff
changeset
|
25 // } |
147
0089fb29cd26
added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
144
diff
changeset
|
26 |
0089fb29cd26
added projection of points and reprojection for display
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
144
diff
changeset
|
27 Mat loadMat(const string& filename, const string& separator) { |
144
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
28 vector<vector<float> > numbers = ::loadNumbers(filename, separator); |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
29 |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
30 Mat mat; |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
31 |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
32 if (!numbers.empty()) { |
803
f7cf43b5ad3b
work in progress on stabilization
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
802
diff
changeset
|
33 mat = Mat(numbers.size(),numbers[0].size(), CV_64FC1); |
144
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
34 for (unsigned int i=0; i<numbers.size(); i++) |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
35 for (unsigned int j=0; j<numbers[0].size(); j++) |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
36 mat.at<float>(i,j) = numbers[i][j]; |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
37 } |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
38 |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
39 return mat; |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
40 } |
b32947b002da
added the code to read matrices from text files
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
131
diff
changeset
|
41 |
128
536510f60854
new features generated as needed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
127
diff
changeset
|
42 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
|
43 if (clearPts) |
536510f60854
new features generated as needed
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
127
diff
changeset
|
44 pts.clear(); |
127
d19d6e63dd77
simple feature tracking and drawing working
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
126
diff
changeset
|
45 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
|
46 |
336926453b28
added conversion function from keypoint vector to point vector and cleaned headers
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
12
diff
changeset
|
47 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
|
48 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
|
49 } |
9 | 50 |
131 | 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 | |
427
1e3c7fe21a38
changed colors to 3.0 version
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
407
diff
changeset
|
60 // Blue, Green, Red |
131 | 61 Scalar Colors::black(void) { return Scalar(0,0,0);} |
427
1e3c7fe21a38
changed colors to 3.0 version
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
407
diff
changeset
|
62 Scalar Colors::blue(void) { return Scalar(255,0,0);} |
131 | 63 Scalar Colors::green(void) { return Scalar(0,255,0);} |
427
1e3c7fe21a38
changed colors to 3.0 version
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
407
diff
changeset
|
64 Scalar Colors::red(void) { return Scalar(0,0,255);} |
131 | 65 Scalar Colors::white(void) { return Scalar(255,255,255);} |
66 Scalar Colors::magenta(void) { return Scalar(255,0,255);} | |
427
1e3c7fe21a38
changed colors to 3.0 version
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
407
diff
changeset
|
67 Scalar Colors::yellow(void) { return Scalar(0,255,255);} |
1e3c7fe21a38
changed colors to 3.0 version
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
407
diff
changeset
|
68 Scalar Colors::cyan(void) { return Scalar(255,255,0);} |
131 | 69 |
70 Scalar Colors::color3(const int& num) { return Colors::color[num%3];} | |
71 Scalar Colors::color8(const int& num) { return Colors::color[num%Colors::nColors];} |