From d535d24082ddfdb2ca7c7fd6316f9122f5a678e3 Mon Sep 17 00:00:00 2001 From: Pavol Debnar Date: Sat, 18 Mar 2023 21:41:37 +0100 Subject: [PATCH] matching now uses knnMatching for better accuracy --- src/pointbase.cpp | 67 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 14 deletions(-) diff --git a/src/pointbase.cpp b/src/pointbase.cpp index a462a22..af3de4b 100644 --- a/src/pointbase.cpp +++ b/src/pointbase.cpp @@ -547,9 +547,15 @@ class PointBase { //match the descriptors cv::FlannBasedMatcher matcher; - std::vector matches; + + //matcher.match part1 + /*std::vector matches; - matcher.match(descriptorsROI,descriptorsImg,matches); + matcher.match(descriptorsROI,descriptorsImg,matches);*/ + + //trying out knnmatch + std::vector> matches; + matcher.knnMatch(descriptorsROI, descriptorsImg, matches, 2); // Find 2 nearest matches cv::Mat imageMatches; drawMatches(roi,keypointsROI,imgSmall,keypointsImg,matches,imageMatches); @@ -560,8 +566,8 @@ class PointBase { - - + //matcher.match part2 + /* double max_dist = 0; double min_dist = 100; //cout<<"ROWS DESC:"< good_matches; + //float ratio = 0.4; // As in Lowe's paper; can be tuned + for (float ratio = 0.4; good_matches.size()<2; ratio+=0.05) + { + good_matches.clear(); + cout << "RATIO: " < obj; @@ -597,11 +629,7 @@ class PointBase { scene.push_back( static_cast(keypointsROI[ good_matches[i].queryIdx ].pt )); } - /*cv::Mat imageMatches2; - drawMatches(roi,keypointsROI,imgSmall,keypointsImg,good_matches,imageMatches2); - cv::namedWindow("good_matches"); - cv::imshow("good_matches",imageMatches2); - cv::waitKey(0);*/ + //find a transformation based on good matches //we do not need a Homography, since we deal with affine transformations (no viewport transf. are expected) @@ -649,8 +677,16 @@ class PointBase { Mat roiOverlapAlpha, imgOverlapAlpha, resultRoi; //blended images of ROI and img, now we need to only add them together + /* + cv::divide(roiMask,(roiMask+imgWarpedMask)/255.0,roiOverlapAlpha); + cv::divide(imgWarpedMask,(roiMask+imgWarpedMask)/255.0,imgOverlapAlpha); + */ cv::divide(roiDT,(roiDT+imgDT),roiOverlapAlpha); cv::divide(imgDT,(roiDT+imgDT),imgOverlapAlpha); + normalize(imgOverlapAlpha, imgOverlapAlpha, 0.0, 255.0, NORM_MINMAX); + normalize(roiOverlapAlpha, roiOverlapAlpha, 0.0, 255.0, NORM_MINMAX); + imshow("roiMask", roiMask); + imshow("roiMask+imgWarpedMask", roiMask+imgWarpedMask); //imshow("roiMask", roiMask); @@ -658,14 +694,17 @@ class PointBase { roi.convertTo(roi,CV_32FC1); resultWarp.convertTo(resultWarp,CV_32FC1); + roiOverlapAlpha.convertTo(roiOverlapAlpha,CV_32FC1); + imgOverlapAlpha.convertTo(imgOverlapAlpha,CV_32FC1); cout<