温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

ubuntu下如何安装ITK

发布时间:2022-11-29 09:16:11 来源:亿速云 阅读:174 作者:iii 栏目:服务器

这篇文章主要介绍“ubuntu下如何安装ITK”,在日常操作中,相信很多人在ubuntu下如何安装ITK问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”ubuntu下如何安装ITK”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

一、操作环境

vmware 10

ubuntu-14.04.2-desktop-amd64

二、具体操作

1、安装Cmake

(1)安装curses库,这个库可以让cmake运行成GUI界面,生成ccmake

sudo apt-get install libncurses5-dev
sudo apt-get install cmake-curses-gui

(2)安装cmake,这里一定要手动选择安装3.7.0的cmake,而不是apt-get install,否则会是问题很多的2.8.12

cd /home/bwb #进入你自己的目录
wget "https://cmake.org/files/v3.7/cmake-3.7.0.tar.gz"
tar zxvf cmake-3.7.0.tar.gz
cd cmake-3.7.0
sudo su #一定要加这句话root,否则下面语句会没有权限
./bootstrap && make && make install

(3)验证安装

cmake --version
ccmake --version

2、安装编译ITK

(1)下载4.10.1版本的ITK,需要自己用浏览器下载,因为并不是文件地址,而是一个下载服务的网页

"https://sourceforge.net/projects/itk/files/itk/4.10/InsightToolkit-4.10.1.tar.gz/download"

下载文件InsightToolkit-4.10.1.tar.gz放入/home/bwb

(2)建立目录,解压

cd /home/bwb
mkdir ITK
mkdir ITK/build
tar -zxvf ../InsightToolkit-4.10.1.tar.gz #把/home/bwb下的压缩文件解压到/home/bwb/ITK里

(3)编译

cd /home/bwb/ITK/build
ccmake ../InsightToolkit-4.10.1

(4)出现了GUI界面,按c键配置。然后会提示一些设置,但其实根本不用设置,注意下这两个选项是不是OFF就行,不是OFF改成OFF:

BUILD_EXAMPLES  *OFF
BUILD_TESTING     *OFF

更改的方法是,光标上下选择,回车修改,回车保存

(5)继续按c键配置,提示成功,然后按g生成编译文件。

(6)make

make

三、测试ITK

1、建立目录

cd /home/bids/ITK
mkdir test       //工程文件
mkdir test/src   //存放源代码
mkdir test/bin    //示例编译目标
mkdir test/src/HelloWorld //项目名称
mkdir test/bin/HelloWorld //项目名称

2、拷贝官方的HelloWorld程序

cp /home/bwb/ITK/InsightToolkit-4.10.1/Examples/Installation/* /home/bwb/ITK/test/src/HelloWorld

会有两个文件:CMakeLists.txt、HelloWorld.cxx

3、进入bin目录,编译src的文件

cd /home/bwb/test/bin/HelloWorld
ccmake /home/bwb/ITK/test/src/HelloWorld

可能会出现错误:

ITK_DIR_NOTFOUND

同样用箭头上下选择,回车修改保存,改为ITK的目录:

/home/bwb/ITK/build

重新按c配置,按g生成编译文件

4、make

make   //生成 HelloWorld 可执行文件
./HelloWrold  //执行

ubuntu下如何安装ITK

最终结果:

ITK Hello World!

5、Helloworld的CMakeList.txt解释

#最低cmake版本要求
cmake_minimum_required(VERSION 2.8.9)

if(COMMAND CMAKE_POLICY)
  cmake_policy(SET CMP0003 NEW)
endif()

#项目名称
project(HelloWorld)

#ITK依赖的包的路径,include进来
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

#把HelloWorld.cxx源文件编译成HelloWorld可执行程序
add_executable(HelloWorld HelloWorld.cxx )

#指定编译参数
target_link_libraries(HelloWorld ${ITK_LIBRARIES})

四、安装过程中出现的坑

1、出现undefined reference to symbol 'pthread_create'

<h1pingfang sc',="" 'microsoft="" yahei',="" simhei,="" arial,="" simsun;="" margin:="" 0px;="" padding:="" 0px="" 29px;="" font-weight:="" 700;="" box-sizing:="" border-box;="" word-break:="" break-all;="" word-wrap:="" break-word;="" color:="" rgb(44,="" 48,="" 51);="" font-size:="" 24px;="" line-height:="" 38px;="" font-style:="" normal;="" font-variant:="" letter-spacing:="" orphans:="" auto;="" text-align:="" start;="" text-indent:="" text-transform:="" none;="" white-space:="" widows:="" word-spacing:="" -webkit-text-stroke-width:="" 0px;"="">修改了一下CMakeLists.txt:

target_link_libraries(HelloWorld ${ITK_LIBRARIES})
改为
target_link_libraries(HelloWorld ${ITK_LIBRARIES} -lpthread)

解决了。

2、报错undefined reference to 'itksys::SystemTools....'

ubuntu下如何安装ITK

没有相关的资料,唯一在google查到的资料是一段邮件对话:

他说问题在cmake:

These messages indicate possible issues with the CMake configuration.

For more information, see the "Configuring and Building ITK" section
of the ITK Software Guide:

  https://itk.org/ITKSoftwareGuide/html/Book1/ITKSoftwareGuide-Book1ch2.html#x22-130002

and find a downloadable HelloWorld example that includes the CMake
configuration here:

  https://itk.org/ITKExamples/src/Core/Common/BuildAHelloWorldProgram/Documentation.html

Hope this helps,
Matt

我用的2.8.12,是ITK最新版本的最低要求,所以我直接换用更高版本cmake和更低版本ITK了,才解决了,否则怎么改makefile文件都会报这个错。

到此,关于“ubuntu下如何安装ITK”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI