Skip to content
Snippets Groups Projects
Commit 54dafbb1 authored by Angel Santamaria-Navarro's avatar Angel Santamaria-Navarro
Browse files

after merge

parents 97588d3e f0c1f686
No related branches found
No related tags found
No related merge requests found
...@@ -153,6 +153,11 @@ int main(int argc, char** argv) ...@@ -153,6 +153,11 @@ int main(int argc, char** argv)
KeyPointVector keypoints_1 = det_ptr->detect(image_buffer.back()); KeyPointVector keypoints_1 = det_ptr->detect(image_buffer.back());
cv::Mat descriptors_1 = des_ptr->getDescriptor( image_buffer.back(), keypoints_1); cv::Mat descriptors_1 = des_ptr->getDescriptor( image_buffer.back(), keypoints_1);
clock_t tStart, tDet, tDesc, tMatch, tFilter, tFund;
double t_det(0), t_desc(0), t_match(0), t_filter(0), t_fund(0);
const int CLOCKS_PER_MSEC = (CLOCKS_PER_SEC/1000);
int n_iter = 0;
while(1) while(1)
{ {
capture >> img; capture >> img;
...@@ -167,15 +172,22 @@ int main(int argc, char** argv) ...@@ -167,15 +172,22 @@ int main(int argc, char** argv)
DMatchVector good_matches, inlier_matches; DMatchVector good_matches, inlier_matches;
PointVector inliers_1, inliers_2; PointVector inliers_1, inliers_2;
tStart = clock();
// detect and describe in new image // detect and describe in new image
KeyPointVector keypoints_2 = det_ptr->detect(img); KeyPointVector keypoints_2 = det_ptr->detect(img);
tDet = clock();
if (keypoints_2.size()>0) if (keypoints_2.size()>0)
{ {
image_buffer.add(img); image_buffer.add(img);
cv::Mat descriptors_2 = des_ptr->getDescriptor( image_buffer.back(), keypoints_2); cv::Mat descriptors_2 = des_ptr->getDescriptor( image_buffer.back(), keypoints_2);
tDesc = clock();
unsigned int max_dist = 0; unsigned int max_dist = 0;
unsigned int min_dist = 512; unsigned int min_dist = 512;
...@@ -185,6 +197,8 @@ int main(int argc, char** argv) ...@@ -185,6 +197,8 @@ int main(int argc, char** argv)
//-- Step 3: Matching descriptor vectors using FLANN matcher //-- Step 3: Matching descriptor vectors using FLANN matcher
mat_ptr->match(descriptors_1,descriptors_2,des_ptr->getSize(),matches); mat_ptr->match(descriptors_1,descriptors_2,des_ptr->getSize(),matches);
tMatch = clock();
//-- Quick calculation of max and min distances between keypoints //-- Quick calculation of max and min distances between keypoints
for (int ii = 0; ii < descriptors_1.rows; ii++) for (int ii = 0; ii < descriptors_1.rows; ii++)
{ {
...@@ -192,7 +206,7 @@ int main(int argc, char** argv) ...@@ -192,7 +206,7 @@ int main(int argc, char** argv)
if (dist < min_dist) if (dist < min_dist)
min_dist = dist; min_dist = dist;
if (dist > max_dist) if (dist > max_dist)
max_dist = dist; max_dist = dist;
} }
} }
else else
...@@ -215,13 +229,17 @@ int main(int argc, char** argv) ...@@ -215,13 +229,17 @@ int main(int argc, char** argv)
} }
} }
tFilter = clock();
// Compute the Fundamental matrix F and discard outliers through ransac in one go // Compute the Fundamental matrix F and discard outliers through ransac in one go
if (good_matches.size() > 20) // Minimum is 8 points, but we need more for robustness if (good_matches.size() > 20) // Minimum is 8 points, but we need more for robustness
{ {
// find fundamental matrix using RANSAC, return set of inliers as bool vector // find fundamental matrix using RANSAC, return set of inliers as bool vector
cv::Mat F = findFundamentalMat(matched_1, matched_2, cv::FM_RANSAC, 3.0, 0.98, inliers_bool); cv::Mat F = findFundamentalMat(matched_1, matched_2, cv::FM_RANSAC, 2.0, 0.98, inliers_bool);
std::cout << "F = " << F << std::endl; std::cout << "F = " << F << std::endl;
// Recover the inlier matches // Recover the inlier matches
for (unsigned int ii = 0; ii < good_matches.size(); ii++) for (unsigned int ii = 0; ii < good_matches.size(); ii++)
...@@ -229,16 +247,34 @@ int main(int argc, char** argv) ...@@ -229,16 +247,34 @@ int main(int argc, char** argv)
inlier_matches.push_back(good_matches[ii]); inlier_matches.push_back(good_matches[ii]);
} }
std::cout << "Matches: initial " << matches.size() << " | good " << good_matches.size() << " | inliers " tFund = clock();
std::cout << "Matches: initial " << matches.size() << " | good " << good_matches.size() << " | inliers "
<< inlier_matches.size() << std::endl; << inlier_matches.size() << std::endl;
std::cout << "kp1: " << keypoints_1.size() << " kp2: " << keypoints_2.size() << " inliers:" << inlier_matches.size() << std::endl; std::cout << "kp1: " << keypoints_1.size() << " kp2: " << keypoints_2.size() << " inliers:" << inlier_matches.size() << std::endl;
n_iter ++;
t_det += double( tDet - tStart )/CLOCKS_PER_MSEC;
t_desc += double( tDesc - tDet )/CLOCKS_PER_MSEC;
t_match += double( tMatch - tDesc )/CLOCKS_PER_MSEC;
t_filter += double(tFilter - tMatch )/CLOCKS_PER_MSEC;
t_fund += double( tFund - tFilter)/CLOCKS_PER_MSEC;
std::cout << "det: " << t_det/n_iter << "ms - desc: " << t_desc/n_iter << "ms - match: " << t_match/n_iter << "ms - filter: " << t_filter/n_iter << "ms - fund: " << t_fund/n_iter << "ms" << std::endl;
std::cout << "+++++++++++++++" << std::endl; std::cout << "+++++++++++++++" << std::endl;
// Draw RANSAC inliers // Draw RANSAC inliers
cv::drawMatches(image_buffer[image_buffer.size()-2], keypoints_1, image_buffer.back(), keypoints_2, inlier_matches, img_matches, cv::drawMatches(image_buffer[image_buffer.size()-2], // before the last img
cv::Scalar::all(-1), cv::Scalar::all(-1), std::vector<char>(), 0); //cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS ); keypoints_1,
image_buffer.back(), // last img
keypoints_2,
inlier_matches,
img_matches,
cv::Scalar::all(-1),
cv::Scalar::all(-1),
std::vector<char>(), 0); //cv::DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
// Show detected matches // Show detected matches
imshow("Feature tracker", img_matches); imshow("Feature tracker", img_matches);
......
detector: detector:
type: "AGAST" type: "AGAST"
threshold: 9 threshold: 8
nonmaxSuppression: true nonmaxSuppression: true
detection type: 0 # AGAST_5_8=0, AGAST_7_12d=1, AGAST_7_12s=2, OAST_9_16=3, THRESHOLD=10000, NONMAX_SUPPRESSION=10001 detection type: 0 # AGAST_5_8=0, AGAST_7_12d=1, AGAST_7_12s=2, OAST_9_16=3, THRESHOLD=10000, NONMAX_SUPPRESSION=10001
descriptor: descriptor:
type: "BRIEF" type: "BRIEF"
bytes: 32 bytes: 16
use_orientation: true use_orientation: false
matcher: matcher:
type: "FLANNBASED" # BRUTEFORCE, BRUTEFORCE_HAMMING, BRUTEFORCE_HAMMING_2, BRUTEFORCE_L1, FLANNBASED type: "FLANNBASED" # BRUTEFORCE, BRUTEFORCE_HAMMING, BRUTEFORCE_HAMMING_2, BRUTEFORCE_L1, FLANNBASED
......
...@@ -212,7 +212,7 @@ struct FeatureIdxMap_GreaterThan// : public std::binary_function<Scalar, Scalar, ...@@ -212,7 +212,7 @@ struct FeatureIdxMap_GreaterThan// : public std::binary_function<Scalar, Scalar,
}; };
typedef std::multimap<Scalar, size_t, FeatureIdxMap_GreaterThan> FeatureIdxMap; typedef std::multimap<Scalar, size_t, FeatureIdxMap_GreaterThan> FeatureIdxMap;
VU_STRUCT_PTR_TYPEDEFS(FeatureIdxGrid); VU_PTR_TYPEDEFS(FeatureIdxGrid);
class FeatureIdxGrid { class FeatureIdxGrid {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment