added extraction of ROI and calc of homography/affine transf. Both transf. not good enough

main
Pavol Debnar 2 years ago
parent f19d05d62d
commit 95d86b6a9b

@ -5,6 +5,7 @@
#include "opencv2/stitching.hpp"
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/features2d.hpp>
#include "opencv2/calib3d/calib3d.hpp"
#include <fstream>
#include <iostream>
#include <json/json.h>
@ -526,7 +527,7 @@ class PointBase {
cv::Ptr<SIFT> siftPtr = SIFT::create();
std::vector<cv::KeyPoint> keypointsROI, keypointsImg;
std::vector<KeyPoint> keypointsROI, keypointsImg;
cv::Ptr<SiftDescriptorExtractor> 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"<<roi.size() <<" \n";
cout<<" SIZE \n"<<cv::typeToString(roi.type()) <<" \n";
siftPtr->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<cv::DMatch> matches;
matcher.match(descriptorsROI,descriptorsImg,matches);
@ -562,6 +562,60 @@ class PointBase {
cv::waitKey(0);
double max_dist = 0; double min_dist = 100;
cout<<"ROWS DESC:"<<descriptorsImg.rows<<"\n";
cout<<"SIZE DESC:"<<descriptorsImg.size()<<"\n";
//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptorsImg.rows; i++ )
{ double dist = matches[i].distance;
cout<<"DIST:"<<dist<<"\n";
if( dist < min_dist ) min_dist = dist;
if( dist > 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<cv::Point2i>( keypointsImg[ good_matches[i].queryIdx ].pt ));
scene.push_back( static_cast<cv::Point2i>(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<<CV_VERSION;
}
//if(qIdx==2) break;

Loading…
Cancel
Save