• 大小: 9.73MB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2023-08-24
  • 语言: 其他
  • 标签: opencv  极线约束  

资源简介

该代码是在VS2010平台上结合OpenCV编写,对于初学者来说有比较大的帮助。

资源截图

代码片段和文件信息

#include 
#include “opencv2/core/core.hpp“
#include “opencv2/features2d/features2d.hpp“
#include “opencv2/highgui/highgui.hpp“
#include “opencv2/nonfree/nonfree.hpp“
#include 
#include 
using namespace std;

using namespace cv;

static void help()
{
    printf(“\nThis program demonstrates using features2d detector descriptor extractor and simple matcher\n“
            “Using the SURF desriptor:\n“
            “\n“
            “Usage:\n matcher_simple  \n“);
}

int main(int argc char** argv)
{
    //if(argc != 3)
    //{
    //    help();
    //    return -1;
    //}

    Mat img1 = imread(“111.jpg“ CV_LOAD_IMAGE_GRAYSCALE);
    Mat img2 = imread(“222.jpg“ CV_LOAD_IMAGE_GRAYSCALE);
    if(img1.empty() || img2.empty())
    {
        printf(“Can‘t read one of the images\n“);
        return -1;
    }

    // detecting keypoints
    SurfFeatureDetector detector(1000);
    vector keypoints1 keypoints2;
    detector.detect(img1 keypoints1);
    detector.detect(img2 keypoints2);

    // computing descriptors
    SurfDescriptorExtractor extractor;
    Mat descriptors1 descriptors2;
    extractor.compute(img1 keypoints1 descriptors1);
    extractor.compute(img2 keypoints2 descriptors2);

    // matching descriptors
    BFMatcher matcher(NORM_L2);
    vector matches;
    matcher.match(descriptors1 descriptors2 matches);

    // drawing the results
    namedWindow(“matches“ 1);
    Mat img_matches0img_matches1;
drawMatches(img1 keypoints1 img2 keypoints2 matches img_matches0);
//for(int i=0;i //{
// //if(abs((keypoints1[matches[i].queryIdx].pt.y-keypoints2[matches[i].trainIdx].pt.y)>5)
// //{

// //}
// //cout< // Point2f pt1pt2;
// pt1=keypoints1[matches[i].queryIdx].pt;
// pt2=keypoints2[matches[i].trainIdx].pt;
// if(abs(pt1.y-pt2.y)>5)
// {
// matches[i].distance=100;
// }


//}
 //   drawMatches(img1 keypoints1 img2 keypoints2 matches img_matches1);
// 分配空间
int ptCount = (int)matches.size();
Mat p1(ptCount 2 CV_32F);
Mat p2(ptCount 2 CV_32F);

// 把Keypoint转换为Mat
Point2f pt;
for (int i=0; i {
pt = keypoints1[matches[i].queryIdx].pt;
p1.at(i 0) = pt.x;
p1.at(i 1) = pt.y;

pt = keypoints2[matches[i].trainIdx].pt;
p2.at(i 0) = pt.x;
p2.at(i 1) = pt.y;
}
// 用RANSAC方法计算F
// Mat m_Fundamental;
// 上面这个变量是基本矩阵
 vector m_RANSACStatus;
// 上面这个变量已经定义过,用于存储RANSAC后每个点的状态
//m_Fundamental = findFundamentalMat(p1 p2 m_RANSACStatus FM_RANSAC);
 Mat m_Fundamental=findFundamentalMat(p1 p2 m_RANSACStatus FM_RANSAC);
 cout< // 计算野点个数
int OutlinerCount = 0;
for (int i=0; i {
if (m_RANSACStatus[i] == 0) // 状态为0表示野点
{
OutlinerCount++;
}
}

// 计

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     122368  2018-04-10 15:28  jixianyuesu\Debug\jixianyuesu.exe

     文件     733140  2018-04-10 15:28  jixianyuesu\Debug\jixianyuesu.ilk

     文件    1231872  2018-04-10 15:28  jixianyuesu\Debug\jixianyuesu.pdb

     文件   44957696  2018-04-10 15:27  jixianyuesu\ipch\jixianyuesu-28353e67\jixianyuesu-233a92aa.ipch

     文件      76590  2018-03-21 16:16  jixianyuesu\jixianyuesu\1.jpg

     文件      59827  2018-04-09 16:39  jixianyuesu\jixianyuesu\11.jpg

     文件      71261  2018-04-10 15:28  jixianyuesu\jixianyuesu\111.jpg

     文件      83052  2018-03-21 16:16  jixianyuesu\jixianyuesu\2.jpg

     文件      75396  2018-04-09 16:40  jixianyuesu\jixianyuesu\22.jpg

     文件      97309  2018-04-10 15:29  jixianyuesu\jixianyuesu\222.jpg

     文件       8637  2018-04-07 20:30  jixianyuesu\jixianyuesu\3.png

     文件       8236  2018-04-07 20:30  jixianyuesu\jixianyuesu\4.png

     文件        854  2018-04-10 15:27  jixianyuesu\jixianyuesu\Debug\cl.command.1.tlog

     文件      15956  2018-04-10 15:27  jixianyuesu\jixianyuesu\Debug\CL.read.1.tlog

     文件        628  2018-04-10 15:27  jixianyuesu\jixianyuesu\Debug\CL.write.1.tlog

     文件       3224  2018-04-10 15:27  jixianyuesu\jixianyuesu\Debug\jixianyuesu.Build.CppClean.log

     文件        406  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\jixianyuesu.exe.embed.manifest

     文件        472  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\jixianyuesu.exe.embed.manifest.res

     文件        381  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\jixianyuesu.exe.intermediate.manifest

     文件        100  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\jixianyuesu.lastbuildstate

     文件       5925  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\jixianyuesu.log

     文件     475470  2018-04-10 15:27  jixianyuesu\jixianyuesu\Debug\jixianyuesu.obj

     文件          0  2018-04-10 15:27  jixianyuesu\jixianyuesu\Debug\jixianyuesu.write.1.tlog

     文件        212  2018-04-10 15:27  jixianyuesu\jixianyuesu\Debug\jixianyuesu_manifest.rc

     文件          2  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\link-cvtres.read.1.tlog

     文件          2  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\link-cvtres.write.1.tlog

     文件          2  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\link.7180-cvtres.read.1.tlog

     文件          2  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\link.7180-cvtres.write.1.tlog

     文件          2  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\link.7180.read.1.tlog

     文件          2  2018-04-10 15:28  jixianyuesu\jixianyuesu\Debug\link.7180.write.1.tlog

............此处省略27个文件信息

评论

共有 条评论