SIFTGPU编译及测试

由于COLMAP编译后生成的静态库中包含了SIFTGPU库,COLMAP编译过程:
https://blog.csdn.net/Z5122/article/details/84197127 因此,不需要再次下载SIFTGPU源码进行编译,提供SIFTGPU静态库和测试需要的相关头文件
https://github.com/nxyzgf/sgg-siftgpu

测试代码

#include<colmap/lib/SiftGPU/SiftGPU.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/features2d/features2d.hpp"
#include <Windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <boost/timer.hpp>
#include <iostream>
#include <vector>

using namespace std;
using namespace chrono;

int main()
{
    SiftGPU sift;
    SiftMatchGPU matcher;
    std::vector<float> descriptors1(1), descriptors2(1);
    std::vector<SiftGPU::SiftKeypoint> keys1(1), keys2(1);
    int num1 = 0, num2 = 0;
    const char * argv[] = { "-fo", "-1",  "-v", "1" };
    int argc = sizeof(argv) / sizeof(char*);
    sift.ParseParam(argc, argv);

    int support = sift.CreateContextGL();
    if (support != SiftGPU::SIFTGPU_FULL_SUPPORTED)
    {
        std::cerr << "SiftGPU is not supported!" << std::endl;
        return 2;
    }
    cv::Mat img1 = cv::imread("C:\\Users\\sggzg\\Desktop\\images\\IMG_2332.jpg");
    cv::Mat img2 = cv::imread("C:\\Users\\sggzg\\Desktop\\images\\IMG_2333.jpg");
    int width1 = img1.cols;
    int width2 = img2.cols;
    int height1 = img1.rows;
    int height2 = img2.rows;

    auto start_siftgpu = std::chrono::system_clock::now();
    sift.RunSIFT(width1, height1, img1.data, GL_RGB, GL_UNSIGNED_BYTE);
    num1 = sift.GetFeatureNum();
    keys1.resize(num1);
    descriptors1.resize(128 * num1);
    sift.GetFeatureVector(&keys1[0], &descriptors1[0]);
    sift.RunSIFT(width2, height2, img2.data, GL_RGB, GL_UNSIGNED_BYTE);
    num2 = sift.GetFeatureNum();
    keys2.resize(num2);
    descriptors2.resize(128 * num2);
    sift.GetFeatureVector(&keys2[0], &descriptors2[0]);

    matcher.VerifyContextGL();
    matcher.SetDescriptors(0, num1, &descriptors1[0]);
    matcher.SetDescriptors(1, num2, &descriptors2[0]);
    uint32_t (*match_buf)[2] = new uint32_t [num1][2];
    int num_match = matcher.GetSiftMatch(num1, match_buf);
    float time_cost = chrono::duration_cast<microseconds>(std::chrono::system_clock::now() - start_siftgpu).count() / 1000.0;
    
    std::cout << "siftgpu两张图像特征提取与匹配总计时间:" << time_cost << "ms" <<   std::endl;
    std::cout << num_match << "sift特征匹配被找到;\n";
    system("pause");
    return 0;
}

测试图像
在这里插入图片描述
测试结果

在这里插入图片描述

SIFTGPU是一个用于实现尺度不变特征变换(Scale-Invariant Feature Transform,SIFT)的GPU加速库。下面是一些基本的使用教程: 1. 安装SIFTGPU:你可以从 https://github.com/pitzer/SIFTGPU 下载SIFTGPU的源代码。根据该项目中的安装说明,编译并安装SIFTGPU库。 2. 导入SIFTGPU库:在你的项目中,导入SIFTGPU库的头文件,并链接SIFTGPU的库文件。 3. 初始化SIFTGPU:在你的代码中,使用以下代码初始化SIFTGPU: ```cpp #include <GL/glew.h> #include <GL/glut.h> #include <SiftGPU.h> SiftGPU sift; int width = 640, height = 480; int main(int argc, char *argv[]) { // 初始化OpenGL上下文 glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(width, height); glutCreateWindow("SIFTGPU"); // 初始化SIFTGPU if (sift.CreateContextGL() != SiftGPU::SIFTGPU_FULL_SUPPORTED) { printf("SIFTGPU is not supported!\n"); return 1; } // 设置SIFTGPU参数 sift.SetVerbose(true); sift.SetOuputFormat(SiftGPU::SIFTGPU_SIFT); sift.VerifyContextGL(); // ...其他操作 return 0; } ``` 4. 加载图像数据:使用以下代码将图像数据传递给SIFTGPU进行处理: ```cpp // 设置图像尺寸 sift.SetImageSize(width, height); // 加载图像数据 unsigned char* imageData = new unsigned char[width * height * 3]; // ...从文件或其他方式获取图像数据并存储到imageData中 // 传递图像数据给SIFTGPU sift.RunSIFT(width, height, imageData, GL_RGB, GL_UNSIGNED_BYTE); ``` 5. 提取特征点:使用以下代码提取图像中的特征点: ```cpp int numFeatures = sift.GetFeatureNum(); // 为特征点分配内存 float* featureData = new float[numFeatures * 128]; // 提取特征点 sift.GetFeatureVector(featureData); // 遍历特征点并进行处理 for (int i = 0; i < numFeatures; ++i) { // 获取特征点的关键信息(位置、尺度、方向等) SiftGPU::SiftKeypoint& keypoint = sift.GetFeature(i); // ...在这里可以对每个特征点进行处理 } // 释放内存 delete[] featureData; ``` 这只是一个简单的SIFTGPU使用教程,更详细的用法可以参考SIFTGPU的文档和示例代码。希望对你有帮助!如果你有更多问题,可以继续问我。
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值