使用C ++中的ITK读取Nifti图像

时间:2018-04-24 13:23:34

标签: vtk itk

如果问题很原始,我很抱歉,但我无法解决问题。我想使用ITK库在C ++中读取nifti图像。我在Github上使用了代码:https://gist.github.com/rafamanzo/a3c258f4f74e898e9418。读取图像的代码非常简单。然后我使用ITKCMake配置到我的项目中。以下是我的CMakeLists.txt文件:

cmake_minimum_required(VERSION 2.8)
project(MyProject)
set(CMAKE_INSTALL_PREFIX "/home/itk")
set(ITK_DIR "/home/itk/InsightToolkit-4.13.0/bin/")
set(VTK_DIR "/home/vtk/VTK-8.1.0/bin/")
find_package(ITK REQUIRED)
find_package(VTK REQUIRED)
if (ITKVtkGlue_LOADED)
  find_package(VTK REQUIRED)
  include(${VTK_USE_FILE})
else()
  find_package(ItkVtkGlue REQUIRED)
  include(${ItkVtkGlue_USE_FILE})
  set(Glue ItkVtkGlue)
endif()
include(${ITK_USE_FILE})
include(${VTK_USE_FILE})
add_executable(MyProject mainFile.cxx)
target_link_libraries(MyProject ${ITK_LIBRARIES})

“cmake ..”成功运行。 但是“make all”给了我一个错误:

make[2]: *** No rule to make target '/home/vtk/VTK-8.1.0/bin/lib/libvtkRenderingOpenGL2.so', needed by 'MyProject'.  Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/MyProject.dir/all' failed
make[1]: *** [CMakeFiles/MyProject.dir/all] Error 2
Makefile:83: recipe for target 'all' failed

令人惊讶的是,当我从Eclipse构建项目时,我又遇到了另一个错误:

./bin/CMakeFiles/feature_tests.o: In function `main':
/home/MyProject/Debug/../bin/CMakeFiles/feature_tests.c:34: multiple definition of `main'
makefile:32: recipe for target 'MyProject' failed
./bin/CMakeFiles/3.6.2/CompilerIdC/CMakeCCompilerId.o:/home/MyProject/Debug/../bin/CMakeFiles/3.6.2/CompilerIdC/CMakeCCompilerId.c:540: first defined here
/usr/bin/ld: cannot find -l/home/vtk/VTK-8.1.0/bin/lib/libvtkRenderingContextOpenGL2-8.1.so
collect2: error: ld returned 1 exit status
make: *** [MyProject] Error 1

我很确定配置ITK很简单,特别是我以前做过,但只使用ImageFileReader。任何帮助深表感谢。谢谢。

1 个答案:

答案 0 :(得分:0)

只是为了阅读您不需要 VTKGlue 部分ITKVTK本身的图片。报告的问题来自VTK。如果你想保留VTK(用于别的东西?),你应该修复它。也许您需要将VTK_RENDERING_BACKEND设置为OpenGL2或类似的东西。尝试使用VTK构建一些VTK examples,看看这些示例是否构建并运行。这可能会更准确地指出你的问题。