VS2019+opencv 4.1.0+contribute 4.1.0配置

1.下載opencv 4.1.0+contribute 4.1.0的源碼

2.新建一個文件夾opencv410,在該目錄下新建文件夾source和build,把代碼都解壓放到一個source中。

3. 打開cmake,配置好目錄,然後點擊configure,這個過程會等好久,然後會出現下圖中的紅色。在紅色中找到藍色框住的兩項。在nonfree中勾選對號,在下面加上contribute/modules的地址。再點擊configure,直到所有紅框變白。最後點擊generate

4.用vs生成項目在build下有OpenCV.sln 點擊生成->批生成->選中ALL_BUILD與INSTALL,然後生成。(編譯生成需要花一定的時間)

5. 編譯成功之後make目錄中就會有install目錄,該目錄就是opencv的函數庫

6. 配置opencv的環境變量,在PATH中添加*\build\install\x64\vc16\bin

 

 

(1) 創建空的C++工程;

(2) 打開該工程的屬性,配置VC++目錄中的包含目錄與庫目錄

(3) 鏈接器->輸入->添加依賴庫,這裏爲D:\opencv410\build\install\x64\vc16\lib的lib文件,其中release是不帶d的lib文件,debug是帶d的lib文件。

PS:文件比較多,可以在cmd中輸入dir /b *d.lib>debug.txt  dir /b *412.lib>release.txt,方可得到debug和release模式不同的依賴項。

 

7. 測試sift特徵

(1) 創建.cpp相關代碼文件;

(2) 代碼如下:

 

#include <opencv2/opencv.hpp>

 

#include <iostream>

 

 

using namespace cv;

 

using namespace std;

 

 

int main(int argc, char** argv) {

 

Mat box = imread("1.png");

 

Mat box_in_sence = imread("2.png");

 

 

// 創建AKAZE

 

auto akaze_detector = AKAZE::create();

 

vector<KeyPoint> kpts_01, kpts_02;

 

Mat descriptors1, descriptors2;

 

 

akaze_detector->detectAndCompute(box, Mat(), kpts_01, descriptors1);

 

akaze_detector->detectAndCompute(box_in_sence, Mat(), kpts_02, descriptors2);

 

// 定義描述子匹配 - 暴力匹配

 

Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);

 

std::vector< DMatch > matches;

 

matcher->match(descriptors1, descriptors2, matches);

 

// 繪製匹配

 

Mat img_matches;

 

drawMatches(box, kpts_01, box_in_sence, kpts_02, matches, img_matches);

 

imshow("AKAZE-Matches", img_matches);

 

imwrite("result.png", img_matches);

 

waitKey(0);

 

return 0;

 

}

(3) 效果圖

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章