diff --git a/src/pointbase.cpp b/src/pointbase.cpp index b9e90f9..b7fc26f 100644 --- a/src/pointbase.cpp +++ b/src/pointbase.cpp @@ -5,6 +5,7 @@ #include "opencv2/stitching.hpp" #include #include +#include "opencv2/calib3d/calib3d.hpp" #include #include #include @@ -526,7 +527,7 @@ class PointBase { cv::Ptr siftPtr = SIFT::create(); - std::vector keypointsROI, keypointsImg; + std::vector keypointsROI, keypointsImg; cv::Ptr siftExtrPtr; cv::Mat descriptorsROI, descriptorsImg; siftPtr->detect(roi, keypointsROI); @@ -541,16 +542,15 @@ class PointBase { imshow("sift_result.jpg", output); waitKey(0);*/ - cout<<" SIZE \n"<compute(roi, keypointsROI, descriptorsROI); - /*siftExtrPtr->compute(imgSmall, + siftPtr->compute(imgSmall, keypointsImg, - descriptorsImg);*/ + descriptorsImg); - - cv::BFMatcher matcher(cv::NORM_L2,true); + cv::FlannBasedMatcher matcher; std::vector matches; matcher.match(descriptorsROI,descriptorsImg,matches); @@ -561,6 +561,60 @@ class PointBase { cv::imshow("matches",imageMatches); cv::waitKey(0); + + + + + + double max_dist = 0; double min_dist = 100; + cout<<"ROWS DESC:"< max_dist ) max_dist = dist; + } + printf("-- Max dist : %f \n", max_dist ); + printf("-- Min dist : %f \n", min_dist ); + + std::vector< DMatch > good_matches; + + for( int i = 0; i < descriptorsImg.rows; i++ ) + { if( matches[i].distance < 3*min_dist ) + { good_matches.push_back( matches[i]); } + + } + std::vector< Point2d > obj; + std::vector< Point2d > scene; + + for( int i = 0; i < good_matches.size(); i++ ) + { + //-- Get the keypoints from the good matches + obj.push_back( static_cast( keypointsImg[ good_matches[i].queryIdx ].pt )); + scene.push_back( static_cast(keypointsROI[ good_matches[i].trainIdx ].pt )); + } + + /*cv::Mat imageMatches2; + drawMatches(roi,keypointsROI,imgSmall,keypointsImg,good_matches,imageMatches2); + cv::namedWindow("good_matches"); + cv::imshow("good_matches",imageMatches2); + cv::waitKey(0);*/ + + + //Mat H = findHomography( Mat(obj), Mat(scene), RANSAC ); + Mat H = estimateAffinePartial2D( Mat(obj), Mat(scene), noArray(),RANSAC ); + + cv::Mat result; + //warpPerspective(imgSmall,roi,H,cv::Size(roi.cols,roi.rows)); + warpAffine(imgSmall,result,H,cv::Size(roi.cols,roi.rows)); + /*cv::Mat half(result,cv::Rect(0,0,imgSmall.cols,imgSmall.rows)); + result.copyTo(roi);*/ + imshow("imgSmall", imgSmall); + imshow( "Result", result ); + imshow("roi", roi); + cv::waitKey(0); //cout<