Compare commits
144 Commits
Author | SHA1 | Date |
---|---|---|
|
82f8176b06 | 6 years ago |
|
a03b7575ba | 6 years ago |
|
8bae39ce8a | 6 years ago |
|
aa89881321 | 6 years ago |
|
30b01a2d29 | 6 years ago |
|
dc328451eb | 6 years ago |
|
a49600cb24 | 6 years ago |
|
0157ff0bc3 | 6 years ago |
|
7e71666a0b | 6 years ago |
|
7b677bb017 | 6 years ago |
|
9b954de175 | 6 years ago |
|
7f3af2b2d9 | 6 years ago |
|
fd63c60418 | 7 years ago |
|
1c34941537 | 7 years ago |
|
b0f0194595 | 7 years ago |
|
8484c8af7c | 7 years ago |
|
51cfa51924 | 7 years ago |
|
f1c5d8364f | 7 years ago |
|
19f4c4403a | 7 years ago |
|
e89405d48f | 7 years ago |
|
eaf0b04530 | 7 years ago |
|
cbae431752 | 7 years ago |
|
0239c195d8 | 7 years ago |
|
a32aec5ba6 | 7 years ago |
|
dd131219b2 | 7 years ago |
|
2cf58febf8 | 7 years ago |
|
99091a6246 | 7 years ago |
|
0354d01e79 | 7 years ago |
|
45d3aac730 | 7 years ago |
|
318ac6b8c9 | 7 years ago |
|
7d332100a4 | 7 years ago |
|
56072c4406 | 7 years ago |
|
cd64b504b8 | 7 years ago |
|
443059e371 | 7 years ago |
|
8f9c4d23e0 | 7 years ago |
|
8b90db3f25 | 7 years ago |
|
ec16307632 | 7 years ago |
|
fdefc4b09d | 7 years ago |
|
61d8292652 | 7 years ago |
|
43f1b72e92 | 7 years ago |
|
1f4b8c2785 | 7 years ago |
|
97eae6b546 | 7 years ago |
|
572d6d795d | 7 years ago |
|
7459388dd9 | 7 years ago |
|
249edb2c99 | 7 years ago |
|
00cc4aa230 | 7 years ago |
|
7c0193bb75 | 7 years ago |
|
97507e42a1 | 7 years ago |
|
91fe01beca | 7 years ago |
|
591a08721e | 7 years ago |
|
a28733148e | 7 years ago |
|
e10e628036 | 7 years ago |
|
738b388a64 | 7 years ago |
|
9802024f71 | 7 years ago |
|
1659e96766 | 7 years ago |
|
c1dea8465e | 7 years ago |
|
678d383f26 | 7 years ago |
|
e15a56d142 | 8 years ago |
|
c46521ad65 | 8 years ago |
|
d0f3468477 | 8 years ago |
|
3224b0a75a | 8 years ago |
|
7d8110772a | 8 years ago |
|
fb4c2ba64d | 8 years ago |
|
e53f1b2532 | 8 years ago |
|
621a1d3b09 | 8 years ago |
|
14b686cdc7 | 8 years ago |
|
0202e52747 | 8 years ago |
|
7997e7aee9 | 8 years ago |
|
b43e5e2d21 | 8 years ago |
|
c92ecc7f96 | 8 years ago |
|
ae52d94ceb | 8 years ago |
|
37d4e24806 | 8 years ago |
|
7b861cac9f | 8 years ago |
|
da9395b592 | 8 years ago |
|
df1a026329 | 8 years ago |
|
dd9bf1ba1d | 8 years ago |
|
30f7576029 | 8 years ago |
|
f548d660ba | 8 years ago |
|
8a2bbc57e4 | 8 years ago |
|
e575b5ff9a | 8 years ago |
|
355553b0a6 | 8 years ago |
|
d25b04149a | 8 years ago |
|
268d17e086 | 8 years ago |
|
d567a79581 | 8 years ago |
|
3ba7c16670 | 8 years ago |
|
f7d99f3f6a | 8 years ago |
|
126de0cd95 | 8 years ago |
|
72d29259ca | 8 years ago |
|
c9488c661f | 8 years ago |
|
4852f017fa | 8 years ago |
|
b398b572cc | 8 years ago |
|
a0520bef42 | 8 years ago |
|
7dceebbc4e | 8 years ago |
|
0312df4812 | 8 years ago |
|
d19147bc78 | 8 years ago |
|
fc2a71dbab | 8 years ago |
|
6bafc2c598 | 8 years ago |
|
777a0080cb | 8 years ago |
|
572c86176a | 8 years ago |
|
8736ece97d | 8 years ago |
|
ebd961585e | 8 years ago |
|
2e343ef631 | 8 years ago |
|
af3c544483 | 8 years ago |
|
3dedd62f54 | 8 years ago |
|
07b7c03efc | 8 years ago |
|
aae7621243 | 8 years ago |
|
fa36e769cf | 8 years ago |
|
f71bf21aaf | 8 years ago |
|
70489b1e22 | 8 years ago |
|
e397794ae2 | 8 years ago |
|
3d4e1bd641 | 8 years ago |
|
3649ee3cd3 | 8 years ago |
|
d0f3a14456 | 8 years ago |
|
01e34b6a91 | 8 years ago |
|
df5c090f2e | 8 years ago |
|
27213a845f | 8 years ago |
|
91a6940930 | 8 years ago |
|
7577f1420d | 8 years ago |
|
c72a191145 | 8 years ago |
|
34d7b96bfc | 8 years ago |
|
160f26192c | 8 years ago |
|
9e76ba5ccd | 8 years ago |
|
ec784331fb | 8 years ago |
|
61936eb1a4 | 8 years ago |
|
d856604a4a | 8 years ago |
|
ab806b63a7 | 8 years ago |
|
0051744fa0 | 8 years ago |
|
b8d99e1ffb | 8 years ago |
|
54f65a4672 | 8 years ago |
|
d103c116db | 8 years ago |
|
e304795622 | 8 years ago |
|
ebae963884 | 8 years ago |
|
19e4c7727b | 8 years ago |
|
f2a59b3d94 | 8 years ago |
|
88bc0f7838 | 8 years ago |
|
2346ba7ea2 | 8 years ago |
|
f5db748312 | 8 years ago |
|
3e66654963 | 8 years ago |
|
f108795e2c | 8 years ago |
|
6ed571b3c6 | 8 years ago |
|
9d45f15627 | 8 years ago |
|
d7504ecaed | 8 years ago |
|
d23190dc3e | 8 years ago |
|
e3070ed553 | 9 years ago |
103 changed files with 2555 additions and 700 deletions
@ -1,9 +1,10 @@ |
||||
# ignore dot files/directories |
||||
.* |
||||
!.gitignore |
||||
|
||||
*.autosave |
||||
*.pyc |
||||
*.user |
||||
*~ |
||||
.*.swp |
||||
.DS_Store |
||||
.sw[a-z] |
||||
tags |
||||
tegra/ |
||||
|
@ -0,0 +1,272 @@ |
||||
#include <iostream> |
||||
#include <vector> |
||||
#include <sstream> |
||||
|
||||
#include "opencv2/core/core.hpp" |
||||
#include "cvconfig.h" |
||||
|
||||
#ifdef HAVE_TBB |
||||
#include <tbb/parallel_for_each.h> |
||||
#include <tbb/task_scheduler_init.h> |
||||
|
||||
#include "opencv2/imgproc/imgproc.hpp" |
||||
#include "opencv2/highgui/highgui.hpp" |
||||
#include "opencv2/video/video.hpp" |
||||
#include "opencv2/gpu/gpu.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
using namespace cv::gpu; |
||||
|
||||
static void download(const GpuMat& d_mat, vector<Point2f>& vec) |
||||
{ |
||||
vec.resize(d_mat.cols); |
||||
Mat mat(1, d_mat.cols, CV_32FC2, (void*)&vec[0]); |
||||
d_mat.download(mat); |
||||
} |
||||
|
||||
static void download(const GpuMat& d_mat, vector<uchar>& vec) |
||||
{ |
||||
vec.resize(d_mat.cols); |
||||
Mat mat(1, d_mat.cols, CV_8UC1, (void*)&vec[0]); |
||||
d_mat.download(mat); |
||||
} |
||||
|
||||
static void drawArrows(Mat& frame, const vector<Point2f>& prevPts, const vector<Point2f>& nextPts, const vector<uchar>& status, Scalar line_color = Scalar(0, 0, 255)) |
||||
{ |
||||
for (size_t i = 0; i < prevPts.size(); ++i) |
||||
{ |
||||
if (status[i]) |
||||
{ |
||||
int line_thickness = 1; |
||||
|
||||
Point p = prevPts[i]; |
||||
Point q = nextPts[i]; |
||||
|
||||
double angle = atan2((double) p.y - q.y, (double) p.x - q.x); |
||||
|
||||
double hypotenuse = sqrt( (double)(p.y - q.y)*(p.y - q.y) + (double)(p.x - q.x)*(p.x - q.x) ); |
||||
|
||||
if (hypotenuse < 1.0) |
||||
continue; |
||||
|
||||
// Here we lengthen the arrow by a factor of three.
|
||||
q.x = (int) (p.x - 3 * hypotenuse * cos(angle)); |
||||
q.y = (int) (p.y - 3 * hypotenuse * sin(angle)); |
||||
|
||||
// Now we draw the main line of the arrow.
|
||||
line(frame, p, q, line_color, line_thickness); |
||||
|
||||
// Now draw the tips of the arrow. I do some scaling so that the
|
||||
// tips look proportional to the main line of the arrow.
|
||||
|
||||
p.x = (int) (q.x + 9 * cos(angle + CV_PI / 4)); |
||||
p.y = (int) (q.y + 9 * sin(angle + CV_PI / 4)); |
||||
line(frame, p, q, line_color, line_thickness); |
||||
|
||||
p.x = (int) (q.x + 9 * cos(angle - CV_PI / 4)); |
||||
p.y = (int) (q.y + 9 * sin(angle - CV_PI / 4)); |
||||
line(frame, p, q, line_color, line_thickness); |
||||
} |
||||
} |
||||
} |
||||
|
||||
template <typename T> inline T clamp (T x, T a, T b) |
||||
{ |
||||
return ((x) > (a) ? ((x) < (b) ? (x) : (b)) : (a)); |
||||
} |
||||
|
||||
template <typename T> inline T mapValue(T x, T a, T b, T c, T d) |
||||
{ |
||||
x = clamp(x, a, b); |
||||
return c + (d - c) * (x - a) / (b - a); |
||||
} |
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
struct S_Thread_data |
||||
{ |
||||
Size winSize; |
||||
int maxLevel; |
||||
int iters; |
||||
|
||||
Stream stream; |
||||
Mat frame0; |
||||
Mat frame1; |
||||
Mat frame1Gray; |
||||
|
||||
GpuMat d_frame0Gray; |
||||
GpuMat d_prevPts; |
||||
bool useGray; |
||||
}; |
||||
|
||||
struct pyrLK_task |
||||
{ |
||||
pyrLK_task(size_t n): |
||||
_n(n), |
||||
_thread_data(NULL){} |
||||
|
||||
void operator()() |
||||
{ |
||||
// Sparse
|
||||
|
||||
PyrLKOpticalFlow d_pyrLK; |
||||
|
||||
d_pyrLK.winSize.width = _thread_data->winSize.width; |
||||
d_pyrLK.winSize.height = _thread_data->winSize.height; |
||||
d_pyrLK.maxLevel = _thread_data->maxLevel; |
||||
d_pyrLK.iters = _thread_data->iters; |
||||
|
||||
GpuMat d_frame0(_thread_data->frame0); |
||||
GpuMat d_frame1(_thread_data->frame1); |
||||
GpuMat d_frame1Gray(_thread_data->frame1Gray); |
||||
GpuMat d_nextPts; |
||||
GpuMat d_status; |
||||
|
||||
bool useGray = _thread_data->useGray; |
||||
|
||||
d_pyrLK.sparse_multi(useGray ? _thread_data->d_frame0Gray : d_frame0, |
||||
useGray ? d_frame1Gray : d_frame1, |
||||
_thread_data->d_prevPts, d_nextPts, |
||||
d_status, _thread_data->stream, NULL); |
||||
|
||||
// Draw arrows
|
||||
|
||||
vector<Point2f> prevPts(_thread_data->d_prevPts.cols); |
||||
download(_thread_data->d_prevPts, prevPts); |
||||
|
||||
vector<Point2f> nextPts(d_nextPts.cols); |
||||
download(d_nextPts, nextPts); |
||||
|
||||
vector<uchar> status(d_status.cols); |
||||
download(d_status, status); |
||||
|
||||
drawArrows(_thread_data->frame0, prevPts, nextPts, status, Scalar(255, 0, 0)); |
||||
} |
||||
|
||||
size_t _n; |
||||
struct S_Thread_data* _thread_data; |
||||
}; |
||||
|
||||
template <typename T> struct invoker { |
||||
void operator()(T& it) const {it();} |
||||
}; |
||||
|
||||
#define THREADS_NB 12 |
||||
|
||||
int main(int argc, const char* argv[]) |
||||
{ |
||||
const char* keys = |
||||
"{ h | help | false | print help message }" |
||||
"{ l | left | | specify left image }" |
||||
"{ r | right | | specify right image }" |
||||
"{ gray | gray | false | use grayscale sources [PyrLK Sparse] }" |
||||
"{ win_size | win_size | 21 | specify windows size [PyrLK] }" |
||||
"{ max_level | max_level | 3 | specify max level [PyrLK] }" |
||||
"{ iters | iters | 30 | specify iterations count [PyrLK] }" |
||||
"{ points | points | 4000 | specify points count [GoodFeatureToTrack] }" |
||||
"{ min_dist | min_dist | 0 | specify minimal distance between points [GoodFeatureToTrack] }"; |
||||
|
||||
CommandLineParser cmd(argc, argv, keys); |
||||
|
||||
if (cmd.get<bool>("help")) |
||||
{ |
||||
cout << "Usage: pyrlk_optical_flow_multithreading [options]" << endl; |
||||
cout << "Avaible options:" << endl; |
||||
cmd.printParams(); |
||||
return 0; |
||||
} |
||||
|
||||
string fname0 = cmd.get<string>("left"); |
||||
string fname1 = cmd.get<string>("right"); |
||||
|
||||
if (fname0.empty() || fname1.empty()) |
||||
{ |
||||
cerr << "Missing input file names" << endl; |
||||
return -1; |
||||
} |
||||
|
||||
bool useGray = cmd.get<bool>("gray"); |
||||
int winSize = cmd.get<int>("win_size"); |
||||
int maxLevel = cmd.get<int>("max_level"); |
||||
int iters = cmd.get<int>("iters"); |
||||
int points = cmd.get<int>("points"); |
||||
double minDist = cmd.get<double>("min_dist"); |
||||
|
||||
Mat frame0 = imread(fname0); |
||||
Mat frame1 = imread(fname1); |
||||
|
||||
if (frame0.empty() || frame1.empty()) |
||||
{ |
||||
cout << "Can't load input images" << endl; |
||||
return -1; |
||||
} |
||||
|
||||
cout << "Image size : " << frame0.cols << " x " << frame0.rows << endl; |
||||
cout << "Points count : " << points << endl; |
||||
|
||||
cout << endl; |
||||
|
||||
Mat frame0Gray; |
||||
cvtColor(frame0, frame0Gray, COLOR_BGR2GRAY); |
||||
Mat frame1Gray; |
||||
cvtColor(frame1, frame1Gray, COLOR_BGR2GRAY); |
||||
|
||||
// goodFeaturesToTrack
|
||||
|
||||
GoodFeaturesToTrackDetector_GPU detector(points, 0.01, minDist); |
||||
|
||||
GpuMat d_frame0Gray(frame0Gray); |
||||
GpuMat d_prevPts; |
||||
|
||||
detector(d_frame0Gray, d_prevPts); |
||||
|
||||
// Sparse
|
||||
|
||||
tbb::task_scheduler_init init(THREADS_NB); |
||||
|
||||
std::vector<pyrLK_task> tasks; |
||||
|
||||
S_Thread_data s_thread_data[THREADS_NB]; |
||||
|
||||
for (unsigned int uiI = 0; uiI < THREADS_NB; ++uiI) |
||||
{ |
||||
s_thread_data[uiI].stream = Stream(); |
||||
s_thread_data[uiI].frame0 = frame0.clone(); |
||||
s_thread_data[uiI].frame1 = frame1.clone(); |
||||
s_thread_data[uiI].frame1Gray = frame0Gray.clone(); |
||||
|
||||
s_thread_data[uiI].iters = iters; |
||||
s_thread_data[uiI].useGray = useGray; |
||||
s_thread_data[uiI].maxLevel = maxLevel; |
||||
s_thread_data[uiI].winSize.height = winSize; |
||||
s_thread_data[uiI].winSize.width = winSize; |
||||
s_thread_data[uiI].d_frame0Gray = d_frame0Gray.clone(); |
||||
s_thread_data[uiI].d_prevPts = d_prevPts.clone(); |
||||
|
||||
tasks.push_back(pyrLK_task(uiI)); |
||||
tasks.back()._thread_data = &(s_thread_data[uiI]); |
||||
} |
||||
|
||||
tbb::parallel_for_each(tasks.begin(),tasks.end(),invoker<pyrLK_task>()); |
||||
|
||||
for (unsigned int uiI = 0; uiI < THREADS_NB; ++uiI) |
||||
{ |
||||
stringstream ss; |
||||
ss << "PyrLK MultiThreading [Sparse] " << uiI; |
||||
|
||||
imshow(ss.str(), s_thread_data[uiI].frame0); |
||||
ss.str(""); |
||||
} |
||||
|
||||
waitKey(); |
||||
|
||||
return 0; |
||||
} |
||||
#else |
||||
int main(int , const char* []) |
||||
{ |
||||
std::cout << "This example pyrlk_optical_flow_multithreading must be compiled with TBB Option" << std::endl; |
||||
return 0; |
||||
} |
||||
#endif // HAVE_TBB
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue