三维重建——SiftGPU使用

在将bundlefusion移植到Linux的过程中,针对出现的问题进行了一些分析。这里主要对SiftGPU部分进行测试。

虽然bundlefusion对这些SiftGPU进行了一些改进,和Wuchangchang的源码有些许出入,但是不妨碍进行调试。这里主要记录对源码调试的一些过程。

源码的github地址:https://github.com/pitzer/SiftGPU

部分资料借鉴于:https://blog.csdn.net/yrc19950911/article/details/83785908

SiftGPU的一些主要实现有基于GL,SSE等,但是由于项目的需要,我这里主要使用其cuda版本,这里也是对cuda版本的进行测试。

配置:Ubuntu16  opencv3.2     gl的版本忘了就不记录了

一. 源码编译

1.依赖环境主要有GL,glut,devil等等,缺啥装啥就行了,基本都可以apt-get。

2.修改makefile。


ifneq ($(simple_find_cuda), )
     siftgpu_enable_cuda = 1;  //第一处修改
else
    siftgpu_enable_cuda = 0
endif
 
CUDA_INSTALL_PATH = /usr/local/cuda
#change  additional  settings, like SM version here if it is not 1.0 (eg. -arch sm_13 for GTX280)
#siftgpu_cuda_options = -Xopencc -OPT:unroll_size=200000
siftgpu_cuda_options = -arch sm_35   //第二处修改

一个是enable cuda,一个是将sm_35那个选项注释打开,具体的算力根据自己的显卡性能修改就行了。

3.cd到带有makefile的界面,直接make即可。然后可以在bin目录下看到libsiftgpu.so.

4.中间报错,所以我这里修改了一丢丢代码(不知道是不是只有我这样)

error: declaration of ‘operator new’ as non-function SIFTGPU_EXPORT void* operator new (size_t size);

解决方案如下:

在SiftGPU.h中添加  #include <stddef.h>

到这里源码编译就差不多了,源码里面自带有测试程序,有意向的同学可以自己去分析。

二.调用及调试。

为了方便调试,以及以后可能会调用的情况,我这里写了一个CMake的测试版本。

main.cpp

#include <SiftGPU.h>
#include <iostream>
#include <vector>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc.hpp"
#include <chrono>
#include <GL/gl.h>
 
using namespace std;
using namespace chrono;
 
int main( int argc, char** argv)
{
  //声明SiftGPU并初始化
  SiftGPU sift;
  //char* myargv[5] = { "-m", "-s", "-unpa", "0"};
  char* myargv[4] = {"-fo", "-1", "-cuda", "0"};
  sift.ParseParam(5, myargv);
 
  //检查硬件是否支持SiftGPU
  int support = sift.CreateContextGL();
  if ( support != SiftGPU::SIFTGPU_FULL_SUPPORTED )
  {
    std::cerr << "SiftGPU is not supported!" << std::endl;
    return 2;
  }
 
  sift.ParseParam(5, myargv);
  cv::Mat img = cv::imread("/home/yao/workspace/SIFT_detection/image/2.png");
  int width = img.cols;
  int height = img.rows;
 
  sift.AllocatePyramid(width, height);
  sift.SetTightPyramid(1);
  auto start_siftgpu = std::chrono::system_clock::now();
  sift.RunSIFT(width, height, img.data, GL_RGB, GL_UNSIGNED_BYTE);
  float time_cost = chrono::duration_cast<microseconds>(std::chrono::system_clock::now() - start_siftgpu).count() / 1000.0;
  std::cout << "siftgpu::runSIFT() cost time=" << time_cost << "ms" << std::endl;
  int num = sift.GetFeatureNum();
  std::cout << "Feature number=" << num << std::endl;
  std::vector<float> descriptors(128*num);
  std::vector<SiftGPU::SiftKeypoint> keys(num);
 
  auto start_siftfeature = std::chrono::system_clock::now();
  sift.GetFeatureVector(&keys[0], &descriptors[0]);
 
  return 0;
}
 

 CMakeLists.txt

1)版本一:调用前面生成的so

cmake_minimum_required(VERSION 2.8.3)
project(test_SiftGPU)
 
# OpenCV依赖
find_package( OpenCV REQUIRED )
 
# OpenGL
find_package(OpenGL REQUIRED)
 
# GLUT
find_package(GLUT REQUIRED)
 
# Glew
find_package(GLEW REQUIRED)
 
find_package(CUDA REQUIRED)
 
# SiftGPU:手动设置其头文件与库文件所在位置
include_directories("/home/tan/Project/SiftGPU/src/SiftGPU/" ${OpenGL_INCLUDE_DIR})
set(SIFTGPU_LIBS "/home/tan/Project/SiftGPU/bin/libsiftgpu.so")
 
add_executable( test_SiftGPU main.cpp )
target_link_libraries( testSiftGPU
    ${OpenCV_LIBS}
    ${SIFTGPU_LIBS}
    ${GLEW_LIBRARIES} ${GLUT_LIBRARIES} ${OPENGL_LIBRARIES}
)

2)版本二:直接使用前面的源码,统一编译。

待更新。。。

发布了44 篇原创文章 · 获赞 14 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/hehehetanchaow/article/details/90378010
今日推荐