OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 3280|回复: 1

opencV图片融合问题

[复制链接]
发表于 2015-10-29 18:01:40 | 显示全部楼层 |阅读模式
上第一段代码: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错误, 看文档我输入的参数没错呀!请大家帮帮忙,小弟感激不尽!!



回复

使用道具 举报

发表于 2016-2-26 15:21:38 | 显示全部楼层
能分享一下源码么。。我最近也要用这个。。谢谢
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-5-7 17:39 , Processed in 0.011616 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表