使用OpenCV显示SiftGPU提取的特征点和特征匹配,主要包括以下几个步骤:
- SiftGPU特征点提取
- OpenCV读入图像
- SiftGPU特征点类型到OpenCV特征点类型KeyPoint的转换
- OpenCV特征点显示
- SiftGPU描述子类型到OpenCV描述子类型的转换
- SiftGPU特征匹配
- SiftGPU特征匹配到OpenCV匹配DMatch类型的转换
具体代码如下:
代码采用image.txt输入待处理的图像路径,此处根据自己实际处理的图像自行设置。
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <GL/glut.h>
#include <boost/timer.hpp>
#include "compare.h"
using namespace std;
using namespace cv;
#if !defined(SIFTGPU_STATIC) && !defined(SIFTGPU_DLL_RUNTIME)
// SIFTGPU_STATIC comes from compiler
#define SIFTGPU_DLL_RUNTIME
// Load at runtime if the above macro defined
// comment the macro above to use static linking
#endif
#ifdef _WIN32
#ifdef SIFTGPU_DLL_RUNTIME
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#define FREE_MYLIB FreeLibrary
#define GET_MYPROC GetProcAddress
#else
//define this to get dll import definition for win32
#define SIFTGPU_DLL
#ifdef _DEBUG
#pragma comment(lib, "../lib/SIFTGPU.lib")
#else
#pragma comment(lib, "../lib/SIFTGPU.lib")
#endif
#endif
#else
#ifdef SIFTGPU_DLL_RUNTIME
#include <dlfcn.h>
#define FREE_MYLIB dlclose
#define GET_MYPROC dlsym
#endif
#endif
#include <SiftGPU.h>
int main(int argc, char** argv)
{
#ifdef SIFTGPU_DLL_RUNTIME
#ifdef _WIN32
#ifdef _DEBUG
HMODULE hsiftgpu = LoadLibrary("SiftGPU_d.dll");
#else
HMODULE hsiftgpu = LoadLibrary("siftgpu.dll");
#endif
#else
void * hsiftgpu = dlopen("libsiftgpu.so", RTLD_LAZY);
#endif
if (hsiftgpu == NULL) {
DWORD error_id = GetLastError();
cout << "error loading SIFTGPU.dll" << endl;
cout << "error id is " << error_id << endl;
system("pause");
return 0;
}
#endif
//声明SiftGPU并初始化
SiftGPU sift;
char* myargv[4] = {
"-fo", "-1", "-v", "1" };
sift.ParseParam(4, myargv