Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to make a pairwise_matches array in stitching_detailed?

Recently I am trying to make some modification to the stitching_detailed cpp.

I have a group of images and I know their rough positions so I think it is possible to calculate the pairwise_matches two images by two images.

    vector<std::string> tileNames;
std::map <std::string, int> tileIndex; // index in tileNames
vector<cv::Mat> images;
vector<cv::detail::ImageFeatures> features;
vector<cv::detail::MatchesInfo> pairwise_matches;


for (int i = 0; i < tileNames.size(); i++)
{
    vector<cv::detail::ImageFeatures> featuresMatching(2);
    featuresMatching[0] = features[tileIndex[tileNames[i]]];

    for (auto adjacentElement: tile.adjacentTiles)
    {
        featuresMatching[1] = features[tileIndex[ adjacentElement.name() ]];
        vector<cv::detail::MatchesInfo> pairwise_matchesMatching;

        (*featureMatcher)(featuresMatching, pairwise_matchesMatching);
        featureMatcher->collectGarbage();

        for (auto pairwiseMatchInfo : pairwise_matchesMatching)
        {
            if (pairwiseMatchInfo.dst_img_idx != -1 && pairwiseMatchInfo.src_img_idx !=-1)
            {
                pairwiseMatchInfo.dst_img_idx = featuresMatching[pairwiseMatchInfo.dst_img_idx].img_idx;
                pairwiseMatchInfo.src_img_idx = featuresMatching[pairwiseMatchInfo.src_img_idx].img_idx;

                pairwise_matches.push_back(pairwiseMatchInfo);
            }
    }
}

However, when I use the function

    cv::Ptr<cv::detail::Estimator> estimator;
estimator = cv::makePtr<cv::detail::HomographyBasedEstimator>();
vector<cv::detail::CameraParams> cameras;

(*estimator)(features, pairwise_matches, cameras);

I got a segment fault. I think the problem is that there is something wrong with the index. so I checked the matchInfo. However I am more confused.

  1. MatchesInfo.dst_img_idx and MatchesInfo.src_img_idx can be -1, what does it mean?
  2. In Matchesinfo.matches (a vector of Dmatch), Dmatch.imgIdx is always equal with -1 or 0. What does it mean?
  3. match.imgIdx, match.queryIdx, match.trainIdx, match.distance, there is nothing in the document related with these things. I think the segment error might be caused by these since I did not update them while making a new vector, the "pairwise_matches". But what should I do to make it right?

How to make a pairwise_matches array in stitching_detailed?

Recently I am trying to make some modification to the stitching_detailed cpp.

I have a group of images and I know their rough positions so I think it is possible to calculate the pairwise_matches two images by two images.

    vector<std::string> tileNames;
std::map <std::string, int> tileIndex; // index in tileNames
vector<cv::Mat> images;
vector<cv::detail::ImageFeatures> features;
vector<cv::detail::MatchesInfo> pairwise_matches;


for (int i = 0; i < tileNames.size(); i++)
{
    vector<cv::detail::ImageFeatures> featuresMatching(2);
    featuresMatching[0] = features[tileIndex[tileNames[i]]];

    for (auto adjacentElement: tile.adjacentTiles)
    {
        featuresMatching[1] = features[tileIndex[ adjacentElement.name() ]];
        vector<cv::detail::MatchesInfo> pairwise_matchesMatching;

        (*featureMatcher)(featuresMatching, pairwise_matchesMatching);
        featureMatcher->collectGarbage();

        for (auto pairwiseMatchInfo : pairwise_matchesMatching)
        {
            if (pairwiseMatchInfo.dst_img_idx != -1 && pairwiseMatchInfo.src_img_idx !=-1)
            {
                pairwiseMatchInfo.dst_img_idx = featuresMatching[pairwiseMatchInfo.dst_img_idx].img_idx;
                pairwiseMatchInfo.src_img_idx = featuresMatching[pairwiseMatchInfo.src_img_idx].img_idx;

                pairwise_matches.push_back(pairwiseMatchInfo);
            }
    }
}

However, when I use the function

    cv::Ptr<cv::detail::Estimator> estimator;
estimator = cv::makePtr<cv::detail::HomographyBasedEstimator>();
vector<cv::detail::CameraParams> cameras;

(*estimator)(features, pairwise_matches, cameras);

I got a segment fault. I think the problem is that there is something wrong with the index. so I checked the matchInfo. However I am more confused.

  1. 1. MatchesInfo.dst_img_idx and MatchesInfo.src_img_idx can be -1, what does it mean?

  2. 2. In Matchesinfo.matches (a vector of Dmatch), Dmatch.imgIdx is always equal with -1 or 0. What does it mean?

  3. 3. match.imgIdx, match.queryIdx, match.trainIdx, match.distance, there is nothing in the document related with these things. I think the segment error might be caused by these since I did not update them while making a new vector, the "pairwise_matches". But what should I do to make it right?