【问题标题】:Read Nifti image with ITK in C++在 C++ 中使用 ITK 读取 Nifti 图像
【发布时间】:2018-04-24 22:24:30
【问题描述】:

如果问题很原始,我很抱歉,但我无法解决问题。我想使用 ITK 库在 C++ 中读取 nifti 图像。我在 Github 上使用过代码:https://gist.github.com/rafamanzo/a3c258f4f74e898e9418。这是读取图像的非常简单的代码。然后我使用CMakeITK 配置到我的项目中。以下是我的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。任何帮助深表感谢。谢谢。

【问题讨论】:

    标签: vtk itk


    【解决方案1】:

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

    【讨论】:

    • 我从CMakeLists.txt 中删除了VTK 的所有实例,但我仍然收到同样的错误make[2]: *** No rule to make target '/home/vtk/VTK-8.1.0/bin/lib/libvtkRenderingOpenGL2.so', needed by 'MyProject'. Stop. 我该如何解决这个问题?
    • 所以,我尝试从头开始,并在此处找到 HelloWorld 教程:https://itk.org/Wiki/ITK/HelloInsight 我仍然收到相同的错误消息:$ make.. Scanning dependencies of target HelloWorld [ 50%] Building CXX object CMakeFiles/HelloWorld.dir/HelloWorld.cxx.o make[2]: *** No rule to make target '/home/vtk/VTK-8.1.0/bin/lib/libvtkRenderingOpenGL2.so', needed by 'HelloWorld'. Stop.
    • 你找错树了。您的 ITK 依赖于 VTK,而您的 VTK 似乎已损坏。在CMake中配置/home/itk/InsightToolkit-4.13.0/bin/,将Module_ITKVtkGlue设置为OFF。然后重建 ITK 和你的例子。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-09
    • 1970-01-01
    相关资源
    最近更新 更多