OpenCV 冲浪和异常值检测

标签 opencv surf outliers

我知道这里已经有几个相同主题的问题,但我找不到任何帮助。

所以我想比较 2 张图像以查看它们的相似程度,我使用众所周知的 find_obj.cpp 演示来提取冲浪描述符,然后使用 flannFindPairs 进行匹配。

但如您所知,此方法不会丢弃异常值,我想知道真正匹配的数量,以便计算出这两张图像的相似程度。

我已经看过这个问题:Detecting outliers in SURF or SIFT algorithm with OpenCV那里的人建议使用 findFundamentalMat 但是一旦你得到了基本矩阵,我怎样才能从该矩阵中得到离群值/真阳性的数量?谢谢。

最佳答案

这是来自 descriptor_extractor_matcher.cpp 的片段OpenCV 提供的示例:

if( !isWarpPerspective && ransacReprojThreshold >= 0 )
    {
        cout << "< Computing homography (RANSAC)..." << endl;
        vector<Point2f> points1; KeyPoint::convert(keypoints1, points1, queryIdxs);
        vector<Point2f> points2; KeyPoint::convert(keypoints2, points2, trainIdxs);
        H12 = findHomography( Mat(points1), Mat(points2), CV_RANSAC, ransacReprojThreshold );
        cout << ">" << endl;
    }

    Mat drawImg;
    if( !H12.empty() ) // filter outliers
    {
        vector<char> matchesMask( filteredMatches.size(), 0 );
        vector<Point2f> points1; KeyPoint::convert(keypoints1, points1, queryIdxs);
        vector<Point2f> points2; KeyPoint::convert(keypoints2, points2, trainIdxs);
        Mat points1t; perspectiveTransform(Mat(points1), points1t, H12);

        double maxInlierDist = ransacReprojThreshold < 0 ? 3 : ransacReprojThreshold;
        for( size_t i1 = 0; i1 < points1.size(); i1++ )
        {
            if( norm(points2[i1] - points1t.at<Point2f>((int)i1,0)) <= maxInlierDist ) // inlier
                matchesMask[i1] = 1;
        }
        // draw inliers
        drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, CV_RGB(0, 255, 0), CV_RGB(0, 0, 255), matchesMask
#if DRAW_RICH_KEYPOINTS_MODE
                     , DrawMatchesFlags::DRAW_RICH_KEYPOINTS
#endif
                   );

#if DRAW_OUTLIERS_MODE
        // draw outliers
        for( size_t i1 = 0; i1 < matchesMask.size(); i1++ )
            matchesMask[i1] = !matchesMask[i1];
        drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg, CV_RGB(0, 0, 255), CV_RGB(255, 0, 0), matchesMask,
                     DrawMatchesFlags::DRAW_OVER_OUTIMG | DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
#endif
    }
    else
        drawMatches( img1, keypoints1, img2, keypoints2, filteredMatches, drawImg );

过滤的关键行在这里执行:

if( norm(points2[i1] - points1t.at<Point2f>((int)i1,0)) <= maxInlierDist ) // inlier
                matchesMask[i1] = 1;

它测量点之间的 L2 范数距离(如果没有指定,则为 3 个像素,或者用户定义的像素重投影误差数)。

希望对您有所帮助!

关于OpenCV 冲浪和异常值检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8855020/

相关文章:

java - Mat.dump() 的 OpenCV java 实现返回不准确的数据

opencv - Opencv SIFT特征提取错误

R: 'spatialSign' 函数对于识别异常值有用吗?

Javascript数字数据分组和异常值去除

python - numpy.ndarray 中值的计数

c++ - 读取位置访问冲突 0xcccccccc

c - opencv 的高级内容不熟悉...有人能给我一个如何使用 cAlloc 的简单示例吗?

android - 使用 imread OpenCV 读取图像时出错

c# - 如何在 C# 中使用 RANSAC 过滤 OpenSURF 无效匹配

matlab - MATLAB 中的统计异常值检测