零、說明
我這次編譯的時候比較費神,主要還是一眼障目,不見泰山。看到
glu,glew之類的lib比較像,以為原本設好了,然后導致一直相關(guān)函數(shù)引用失敗。
0.1 主要參考網(wǎng)頁
SiftGPU在Ubuntu和Windows下的編譯與使用;
SIFTGPU編譯及測試;
SLAM拾萃(3):siftGPU;
一、SiftGPU 下載
原本的給的網(wǎng)址SiftGPU主頁:http://www.cs.unc.edu/~ccwu/siftgpu/已經(jīng)不能用了,然后就去
github找github倉庫:SiftGPU,但是下載下來實在是太慢了,最后在碼云上面下載的碼云倉庫:SiftGPU,使用登錄碼云下載zip,還是使用HTTPS克隆倉庫看個人習慣,我是使用HTTPS鏈接放到github desktop里面克隆整個倉庫的。
二、在visual studio 下面編譯
2.1 準備工作
2.2 構(gòu)建 SiftGPU.sln
下載下來的倉庫目錄應該是如下這樣
.
├─bin
├─data
├─demos
├─doc
│ └─evaluation
├─lib
├─msvc
│ ├─ServerSiftGPU
│ ├─SiftGPU
│ └─TestWin
└─src
├─ServerSiftGPU
├─SiftGPU
└─TestWin
在
msvc文件夾下找到SiftGPU.sln,雙擊打開,我這兒默認是使用visual studio 2017打開的,打開后會提示升級,正常升級即可。
接下來配置glew和DevIL:
在項目SiftGPU上右鍵屬性,然后在vc++目錄-->包含目錄 里面添加兩者的包含頭文件目錄,根據(jù)自己的解壓路徑對應修改。
D:\glew-2.1.0\include
D:\DevIL Windows SDK\include
D:\DevIL Windows SDK\include\IL
在
vc++目錄-->庫目錄 里面添加兩者庫文件所在目錄,根據(jù)自己解壓地址修改具體地址
D:\glew-2.1.0\lib\Release\x64
D:\DevIL Windows SDK\lib\x64\Release
在 鏈接器-->輸入-->附加依賴項 中添加如下內(nèi)容,根據(jù)自己具體下載的庫的版本來寫,比如我這兒就沒有*64.lb,*64s.lib之類的,而項目原本寫的里面是有的,記得刪掉。
opengl32.lib
glu32.lib
winmm.lib
glew32.lib
glew32s.lib
接下來是關(guān)于
DevIL.lib,把文件GLTexImage.cpp中第46行開始改成如下:
#ifndef SIFTGPU_NO_DEVIL
#include "IL/il.h"
#if defined(_WIN64)
#pragma comment(lib, "D:/DevIL Windows SDK/lib/x64/Release/DevIL.lib")
#elif defined(_WIN32)
#pragma comment(lib, "D:/DevIL Windows SDK/lib/x86/Release/DevIL.lib")
#endif
#else
#include <string.h>
#endif
右鍵項目,生成。
2.3 SiftGPU_CUDA_Enabled.sln 生成
同樣在
msvc文件夾下找到SiftGPU_CUDA_Enabled.sln,雙擊打開,vs2017或者vs2019提示升級就直接升級就是了。
包含目錄,庫目錄,附加依賴項,以及庫加載代碼的改動和SiftGPU.sln一致。
與
SiftGPU.sln方案不同的是,SiftGPU_CUDA_Enabled.sln方案中的SiftGPU_CUDA_Enabled項目包含*.cu文件,要記得把項目的右鍵菜單的生成依賴項-->生成自定義里面的cuda勾選上。如下圖:

接下來就是把
*.cu文件的選項也改了。找到ProgramCU.cu文件在右鍵菜單-->屬性 里面更改如下:
都改好后,右鍵項目,生成。
三、測試
首先給出測試代碼如下,主要參考了高翔博士的博客。
#include "../../src/SiftGPU/SiftGPU.h"
//標準C++
#include <iostream>
#include <vector>
// OpenCV圖像
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
// boost庫中計時函數(shù)
//#include <boost/timer.hpp>
//#include <GL/gl.h>
#ifndef SIFTGPU_NO_DEVIL
#if defined(_WIN64)
#pragma comment(lib, "../../lib/SIFTGPU.lib")
#elif defined(_WIN32)
#pragma comment(lib, "../../lib/SIFTGPU.lib")
#endif
#else
#include <string.h>
#endif
using namespace std;
int main()
{
SiftGPU sift;
char* argv[4] = { "-fo", "-1", "-v", "1" };
double timeOneBegin, timeOneEnd;
timeOneBegin = (double)clock() / CLOCKS_PER_SEC;
sift.ParseParam(4, argv);
int support = sift.CreateContextGL();
if (support != SiftGPU::SIFTGPU_FULL_SUPPORTED)
{
return 0;
}
//測試直接讀取一張圖像
cout << "running sift" << endl;
timeOneBegin = (double)clock() / CLOCKS_PER_SEC;
//在此填入你想測試的圖像的路徑!不要用我的路徑!不要用我的路徑!不要用我的路徑!
sift.RunSIFT("你的圖片路徑");
cout << "siftgpu::runsift() cost time=" << (double)clock() / CLOCKS_PER_SEC - timeOneBegin << endl;
// 獲取關(guān)鍵點與描述子
int num = sift.GetFeatureNum();
cout << "Feature number=" << num << endl;
vector<float> descriptors(128 * num);
vector<SiftGPU::SiftKeypoint> keys(num);
//timer.restart();
sift.GetFeatureVector(&keys[0], &descriptors[0]);
//cout << "siftgpu::getFeatureVector() cost time=" << timer.elapsed() << endl;
// 先用OpenCV讀取一個圖像,然后調(diào)用SiftGPU提取特征
cv::Mat img = cv::imread("你的圖片路徑", 0);
int width = img.cols;
int height = img.rows;
//timer.restart();
// 注意我們處理的是灰度圖,故照如下設置
unsigned int GL_INTENSITY8 = 0x804B;
unsigned int GL_UNSIGNED_BYTE = 0x1401;
timeOneBegin = (double)clock() / CLOCKS_PER_SEC;
sift.RunSIFT(width, height, img.data, GL_INTENSITY8, GL_UNSIGNED_BYTE);
cout << "siftgpu::runSIFT() cost time=" << (double)clock() / CLOCKS_PER_SEC - timeOneBegin << endl;
return 0;
}
我是直接在對應的方案下面新建一個
TestSiftGPU項目,然后新建一個testMain.cpp文件,輸入上面這些代碼進行測試,記得項目要添加opencv的依賴,以及更改自己對應的文件路徑。