-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 209 cpu timer #5
base: master
Are you sure you want to change the base?
Changes from all commits
5701da5
f687a3d
52b776d
cbb6e64
ef52974
b2421de
41f631b
533178e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ Build | |
.idea | ||
doxgen_generated | ||
*.so | ||
common |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,39 +143,57 @@ void TrackKLT::feed_stereo(double timestamp, cv::Mat &img_leftin, cv::Mat &img_r | |
std::unique_lock<std::mutex> lck2(mtx_feeds.at(cam_id_right)); | ||
|
||
cv::Mat img_left, img_right; | ||
std::vector<cv::Mat> imgpyr_left, imgpyr_right; | ||
|
||
#ifdef ILLIXR_INTEGRATION | ||
// Histogram equalize | ||
std::thread t_lhe = timed_thread("slam2 hist l", cv::equalizeHist, cv::_InputArray(img_leftin ), cv::_OutputArray(img_left )); | ||
std::thread t_rhe = timed_thread("slam2 hist r", cv::equalizeHist, cv::_InputArray(img_rightin), cv::_OutputArray(img_right)); | ||
parallel_for_(cv::Range(0, 2), [&](const cv::Range& range){ | ||
for (int i = range.start; i < range.end; i++) { | ||
CPU_TIMER_TIME_BLOCK("hist_and_optical_flow") | ||
|
||
// Histogram equalize | ||
cv::equalizeHist( | ||
cv::_InputArray (i == 0 ? img_leftin : img_rightin), | ||
i == 0 ? img_left : img_right | ||
); | ||
|
||
// Extract image pyramids (boost seems to require us to put all the arguments even if there are defaults....) | ||
cv::buildOpticalFlowPyramid( | ||
i == 0 ? img_left : img_right, | ||
cv::_OutputArray(i == 0 ? imgpyr_left : imgpyr_right), | ||
win_size, | ||
pyr_levels, | ||
false, | ||
cv::BORDER_REFLECT_101, | ||
cv::BORDER_CONSTANT, | ||
true | ||
); | ||
} | ||
}); | ||
#else /// ILLIXR_INTEGRATION | ||
// Histogram equalize | ||
boost::thread t_lhe = boost::thread(cv::equalizeHist, boost::cref(img_leftin), boost::ref(img_left)); | ||
boost::thread t_rhe = boost::thread(cv::equalizeHist, boost::cref(img_rightin), boost::ref(img_right)); | ||
#endif /// ILLIXR_INTEGRATION | ||
|
||
t_lhe.join(); | ||
t_rhe.join(); | ||
|
||
// Extract image pyramids (boost seems to require us to put all the arguments even if there are defaults....) | ||
std::vector<cv::Mat> imgpyr_left, imgpyr_right; | ||
#ifdef ILLIXR_INTEGRATION | ||
std::thread t_lp = timed_thread("slam2 pyramid l", &cv::buildOpticalFlowPyramid, cv::_InputArray(img_left), | ||
cv::_OutputArray(imgpyr_left), win_size, pyr_levels, false, | ||
cv::BORDER_REFLECT_101, cv::BORDER_CONSTANT, true); | ||
std::thread t_rp = timed_thread("slam2 pyramid r", &cv::buildOpticalFlowPyramid, cv::_InputArray(img_right), | ||
cv::_OutputArray(imgpyr_right), win_size, pyr_levels, | ||
false, cv::BORDER_REFLECT_101, cv::BORDER_CONSTANT, true); | ||
#else /// ILLIXR_INTEGRATION | ||
boost::thread t_lp = boost::thread(cv::buildOpticalFlowPyramid, boost::cref(img_left), | ||
boost::ref(imgpyr_left), boost::ref(win_size), boost::ref(pyr_levels), false, | ||
cv::BORDER_REFLECT_101, cv::BORDER_CONSTANT, true); | ||
boost::thread t_rp = boost::thread(cv::buildOpticalFlowPyramid, boost::cref(img_right), | ||
boost::ref(imgpyr_right), boost::ref(win_size), boost::ref(pyr_levels), | ||
false, cv::BORDER_REFLECT_101, cv::BORDER_CONSTANT, true); | ||
#endif /// ILLIXR_INTEGRATION | ||
|
||
t_lp.join(); | ||
t_rp.join(); | ||
|
||
#endif /// ILLIXR_INTEGRATION | ||
rT2 = boost::posix_time::microsec_clock::local_time(); | ||
|
||
{ | ||
#ifdef ILLIXR_INTEGRATION | ||
CPU_TIMER_TIME_BLOCK("preform_detection"); | ||
#endif /// ILLIXR_INTEGRATION | ||
// If we didn't have any successful tracks last time, just extract this time | ||
// This also handles, the tracking initalization on the first call to this extractor | ||
if(pts_last[cam_id_left].empty() || pts_last[cam_id_right].empty()) { | ||
|
@@ -195,6 +213,7 @@ void TrackKLT::feed_stereo(double timestamp, cv::Mat &img_leftin, cv::Mat &img_r | |
pts_last[cam_id_left], pts_last[cam_id_right], | ||
ids_last[cam_id_left], ids_last[cam_id_right]); | ||
rT3 = boost::posix_time::microsec_clock::local_time(); | ||
} | ||
|
||
|
||
//=================================================================================== | ||
|
@@ -207,20 +226,30 @@ void TrackKLT::feed_stereo(double timestamp, cv::Mat &img_leftin, cv::Mat &img_r | |
|
||
// Lets track temporally | ||
#ifdef ILLIXR_INTEGRATION | ||
std::thread t_ll = timed_thread("slam2 matching l", &TrackKLT::perform_matching, this, boost::cref(img_pyramid_last[cam_id_left]), boost::cref(imgpyr_left), | ||
boost::ref(pts_last[cam_id_left]), boost::ref(pts_left_new), cam_id_left, cam_id_left, boost::ref(mask_ll)); | ||
std::thread t_rr = timed_thread("slam2 matching r", &TrackKLT::perform_matching, this, boost::cref(img_pyramid_last[cam_id_right]), boost::cref(imgpyr_right), | ||
boost::ref(pts_last[cam_id_right]), boost::ref(pts_right_new), cam_id_right, cam_id_right, boost::ref(mask_rr)); | ||
parallel_for_(cv::Range(0, 2), [&](const cv::Range& range){ | ||
for (int i = range.start; i < range.end; i++) { | ||
Comment on lines
+229
to
+230
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, does this spawn 2 threads, or 3 threads (where the 3rd thread fails the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
CPU_TIMER_TIME_BLOCK("perform_matching"); | ||
perform_matching( | ||
img_pyramid_last[i == 0 ? cam_id_left : cam_id_right], | ||
i == 0 ? imgpyr_left : imgpyr_right, | ||
pts_last[i == 0 ? cam_id_left : cam_id_right], | ||
i == 0 ? pts_left_new : pts_right_new, | ||
i == 0 ? cam_id_left : cam_id_right, | ||
i == 0 ? cam_id_left : cam_id_right, | ||
i == 0 ? mask_ll : mask_rr | ||
); | ||
} | ||
}); | ||
#else /// ILLIXR_INTEGRATION | ||
boost::thread t_ll = boost::thread(&TrackKLT::perform_matching, this, boost::cref(img_pyramid_last[cam_id_left]), boost::cref(imgpyr_left), | ||
boost::ref(pts_last[cam_id_left]), boost::ref(pts_left_new), cam_id_left, cam_id_left, boost::ref(mask_ll)); | ||
boost::thread t_rr = boost::thread(&TrackKLT::perform_matching, this, boost::cref(img_pyramid_last[cam_id_right]), boost::cref(imgpyr_right), | ||
boost::ref(pts_last[cam_id_right]), boost::ref(pts_right_new), cam_id_right, cam_id_right, boost::ref(mask_rr)); | ||
#endif /// ILLIXR_INTEGRATION | ||
|
||
// Wait till both threads finish | ||
t_ll.join(); | ||
t_rr.join(); | ||
#endif /// ILLIXR_INTEGRATION | ||
|
||
rT4 = boost::posix_time::microsec_clock::local_time(); | ||
|
||
|
@@ -240,7 +269,15 @@ void TrackKLT::feed_stereo(double timestamp, cv::Mat &img_leftin, cv::Mat &img_r | |
//=================================================================================== | ||
//=================================================================================== | ||
|
||
// Get our "good tracks" | ||
std::vector<cv::KeyPoint> good_left, good_right; | ||
std::vector<size_t> good_ids_left, good_ids_right; | ||
|
||
// If any of our masks are empty, that means we didn't have enough to do ransac, so just return | ||
{ | ||
#ifdef ILLIXR_INTEGRATION | ||
CPU_TIMER_TIME_BLOCK("find_points"); | ||
#endif /// ILLIXR_INTEGRATION | ||
if(mask_ll.empty() || mask_rr.empty()) { | ||
img_last[cam_id_left] = img_left.clone(); | ||
img_last[cam_id_right] = img_right.clone(); | ||
|
@@ -254,10 +291,6 @@ void TrackKLT::feed_stereo(double timestamp, cv::Mat &img_leftin, cv::Mat &img_r | |
return; | ||
} | ||
|
||
// Get our "good tracks" | ||
std::vector<cv::KeyPoint> good_left, good_right; | ||
std::vector<size_t> good_ids_left, good_ids_right; | ||
|
||
// Loop through all left points | ||
for(size_t i=0; i<pts_left_new.size(); i++) { | ||
// Ensure we do not have any bad KLT tracks (i.e., points are negative) | ||
|
@@ -305,10 +338,15 @@ void TrackKLT::feed_stereo(double timestamp, cv::Mat &img_leftin, cv::Mat &img_r | |
//std::cout << "adding to right - " << ids_last[cam_id_right].at(i) << std::endl; | ||
} | ||
} | ||
} | ||
|
||
//=================================================================================== | ||
//=================================================================================== | ||
|
||
{ | ||
#ifdef ILLIXR_INTEGRATION | ||
CPU_TIMER_TIME_BLOCK("database->update_feature"); | ||
#endif /// ILLIXR_INTEGRATION | ||
// Update our feature database, with theses new observations | ||
for(size_t i=0; i<good_left.size(); i++) { | ||
cv::Point2f npt_l = undistort_point(good_left.at(i).pt, cam_id_left); | ||
|
@@ -333,6 +371,7 @@ void TrackKLT::feed_stereo(double timestamp, cv::Mat &img_leftin, cv::Mat &img_r | |
ids_last[cam_id_left] = good_ids_left; | ||
ids_last[cam_id_right] = good_ids_right; | ||
rT6 = boost::posix_time::microsec_clock::local_time(); | ||
} | ||
|
||
#ifndef NDEBUG | ||
// Timing information | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perform