上第一段代码:void find_two_image_correspondences(vector<Mat> inputImages, vector<vector<Point2f>>& imgMatches, string outputImagePath, bool writeOutput)
{
// Extract features from each picture with your favorite detector.
//ORB detector (2000);
Ptr<ORB> orb = ORB::create(500,1.2f,8,31,0,2,ORB::HARRIS_SCORE,31,20);
vector<Mat> descriptors(inputImages.size());
vector<vector<KeyPoint>> keypoints(inputImages.size());
BFMatcher matcher (NORM_HAMMING, false);
if (inputImages.size() < 2) exit(-1);
orb->detectAndCompute(inputImages[0], Mat(), keypoints[0],descriptors[0]);
//detector(inputImages[0], Mat(), keypoints[0],descriptors[0]);
for(int i = 1; i < inputImages.size(); i++) {
//detector(inputImages[i], Mat(), keypoints[i],descriptors[i]);
orb->detectAndCompute(inputImages[i], Mat(), keypoints[i],descriptors[i]);
// Match the features.
vector<DMatch> matches;
matcher.match(descriptors[i], descriptors[i-1], matches);
// Prune 'bad' matches based on some metric.
// you can do it by using DMatch.distance() and choose the one with the best distance to get the best results.
// huristic: any distance taht is < 3x the min, we consider good and
// getting around 10-15 matches is enough
// Find the point correspondences.
float minMatchDistance = 1e9;
for (auto &match : matches) {
if (match.distance < minMatchDistance)
minMatchDistance = match.distance;
}
for (auto &match : matches) {
if (match.distance < 3 * minMatchDistance) {
imgMatches[i-1].push_back(keypoints[i-1][match.trainIdx].pt);
imgMatches[i].push_back(keypoints[i][match.queryIdx].pt);
}
}
}
/* Visualize and report your 'good_matches' (if enabled). */
if(writeOutput)
{
Mat intermediateImage;
// Draw your matches here
imwrite(outputImagePath, intermediateImage);
}
}
第二段
void homography(vector<Mat>& inputImages, vector<vector<Point2f>>& matches, vector<Mat> &warpedImages)
{
/* **************************************************************
* If you got this far, congrats!! You are half way there. Now for the second portion.
* *************************************************************** */
// Re-comment out the drawMatches block.
// Compute the homography via RANSAC.
cout << matches[1];
Mat H12 = findHomography(matches[1], matches[0],0,3,noArray(),2000,.0995);
在此处报10-29 17:40:42.279: E/cv::error()(11947): OpenCV Error: Bad argument (The input arrays should be 2D or 3D point sets) in cv::Mat cv::findHomography(cv::InputArray, cv::InputArray, int, double, cv::OutputArray, int, double), file /builds/master_pack-android/opencv/modules/calib3d/src/fundam.cpp, line 362错误, 看文档我输入的参数没错呀!请大家帮帮忙,小弟感激不尽!!
|