opencv3.4.7+opencv_contrib3.4.7 安装 cmake编译 适用于vs2019 教程
(9条消息) opencv_contrib安装笔记_weijifen000的博客-CSDN博客_opencv_contrib
首先非常感谢上面博客的博主。
编译后的opencv3.4.7 opencv_contrib3.4.7 总体资源如下网盘连接:(真心分享给需要的初学opencv的朋友们)
1.链接:https://pan.baidu.com/s/1tktzImF00I7magqAUrIR4A
提取码:ly01
2.或者扫下列二维码
之所以用网盘,是因为超出可csdn上传资源的1g限制。
1.下载好压缩包OpenCV后,解压到C盘,(其实解压到哪里都可以,只要相关配置改为与你的路径一致即可,我这里是直接装载了C盘,下面就以C盘为例)
2.解压后文件夹里什么也别改。大的文件夹叫OpenCV(别改这个名字)。内部包含一下情况:(具体要用到的在opencv-build文件中)
3.配置环境变量
在系统环境变量path中加入以下路径:(根据你OpenCV文件夹的路径,更改下面C:\的部分)
C:\OpenCV\opencv-build\install\x64\vc16\bin
4.配置vs2019
包含目录中添加:
C:\OpenCV\opencv-build\install\include
C:\OpenCV\opencv-build\install\include\opencv
C:\OpenCV\opencv-build\install\include\opencv2
库目录中添加:
C:\OpenCV\opencv-build\install\x64\vc16\lib
链接器--输入中添加:
opencv_world347d.lib
5.然后就可以使用了 你可以试一下 以下程序能不能用
#include
#include
//#include
using namespace std;
using namespace cv;
int main()
{
cv::Mat imageL = cv::imread("origin_1.jpg");
cv::Mat imageR = cv::imread("origin_2.jpg");
/*imshow("1", imageL);
imshow("2", imageR);
waitKey();
return 0;*/
//提取特征点方法
//SIFT
cv::Ptr sift = cv::xfeatures2d::SIFT::create();
//ORB
//cv::Ptr orb = cv::ORB::create();
//SURF
//cv::Ptr surf = cv::xfeatures2d::SURF::create();
//特征点
std::vector keyPointL, keyPointR;
//单独提取特征点
sift->detect(imageL, keyPointL);
sift->detect(imageR, keyPointR);
//画特征点
cv::Mat keyPointImageL;
cv::Mat keyPointImageR;
drawKeypoints(imageL, keyPointL, keyPointImageL, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(imageR, keyPointR, keyPointImageR, cv::Scalar::all(-1), cv::DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
//显示窗口
cv::namedWindow("KeyPoints of imageL");
cv::namedWindow("KeyPoints of imageR");
//显示特征点
cv::imshow("KeyPoints of imageL", keyPointImageL);
cv::imshow("KeyPoints of imageR", keyPointImageR);
//特征点匹配
cv::Mat despL, despR;
//提取特征点并计算特征描述子
sift->detectAndCompute(imageL, cv::Mat(), keyPointL, despL);
sift->detectAndCompute(imageR, cv::Mat(), keyPointR, despR);
//Struct for DMatch: query descriptor index, train descriptor index, train image index and distance between descriptors.
//int queryIdx –>是测试图像的特征点描述符( descriptor )的下标,同时也是描述符对应特征点(keypoint)的下标。
//int trainIdx –> 是样本图像的特征点描述符的下标,同样也是相应的特征点的下标。
//int imgIdx –>当样本是多张图像的话有用。
//float distance –>代表这一对匹配的特征点描述符(本质是向量)的欧氏距离,数值越小也就说明两个特征点越相像。
std::vector matches;
//如果采用 flannBased 方法 那么 desp通过orb的到的类型不同需要先转换类型
if (despL.type() != CV_32F || despR.type() != CV_32F)
{
despL.convertTo(despL, CV_32F);
despR.convertTo(despR, CV_32F);
}
cv::Ptr matcher = cv::DescriptorMatcher::create("FlannBased");
matcher->match(despL, despR, matches);
//计算特征点距离的最大值
double maxDist = 0;
for (int i = 0; i < despL.rows; i++)
{
double dist = matches[i].distance;
if (dist > maxDist)
maxDist = dist;
}
//挑选好的匹配点
std::vector< cv::DMatch > good_matches;
for (int i = 0; i < despL.rows; i++)
{
if (matches[i].distance < 0.5 * maxDist)
{
good_matches.push_back(matches[i]);
}
}
cv::Mat imageOutput;
cv::drawMatches(imageL, keyPointL, imageR, keyPointR, good_matches, imageOutput);
cv::namedWindow("picture of matching");
cv::imshow("picture of matching", imageOutput);
cv::waitKey(0);
return 0;
}
UI_DIR=./
INCLUDEPATH += C:\OpenCV\opencv-build\install\include
INCLUDEPATH += C:\OpenCV\opencv-build\install\include\opencv
INCLUDEPATH += C:\OpenCV\opencv-build\install\include\opencv2
LIBS += C:\OpenCV\opencv-build\install\x64\vc16\lib\opencv_world347.lib
LIBS += C:\OpenCV\opencv-build\install\x64\vc16\lib\opencv_world347d.lib
如需,请转载
love you!!!