如何在Qt中使用Dcmtk? [英] How to use Dcmtk in Qt?

查看:699
本文介绍了如何在Qt中使用Dcmtk?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个必须读取dicom图像的项目中。

I am working on a project where I have to read a dicom image.

我无法安装dcmtk。我正在使用Win7 64位和vs2010。

I am unable to install dcmtk. I am using win7 64-bit and vs2010.

请说明在程序中包含dcmtk的过程。

Please explain the procedure to include dcmtk in my program.

推荐答案

要使用 Windows + DCMTK + QT ,您需要执行以下步骤:

To use the Windows + DCMTK + QT, you need to execute these follow steps:


  • 编译DCMTK(步骤1.A)

  • 创建示例应用程序(步骤2)

  • 创建QT项目文件,引用已编译/安装的DCMTK库(步骤3.B)

  • 在IDE中编译应用程序(步骤4.B)

  • Compile the DCMTK (Step 1.A)
  • Create your sample application (Step 2)
  • Create your QT project file referring the compiled/installed DCMTK Libs (Step 3.B)
  • Compile your application in your IDE (Step 4.B)

如果您正在阅读且不要使用Qt,我也要回答没有Qt的版本。

If you are reading this and don't want to use the Qt, I am answering a version without Qt as well.

Windows + VisualStudio + DCMTK:步骤 1.A 2 3.A 4.A

Windows+VisualStudio+DCMTK: Steps 1.A, 2, 3.A and 4.A

Linux + GCC + DCMTK:步骤 1.B 2 N / A 4.C

Linux+GCC+DCMTK: Steps 1.B, 2, N/A, 4.C




1)编译DCMTK


首先,使用在您的应用程序中的DCMTK库中,您应该编译DCMTK源代码以生成库:


1) Compile the DCMTK

First of all, to use the DCMTK library in your application, you should compile the DCMTK source code to generate the libraries:

虽然我在编写此文件,但最后可用的版本是3.6.0。因此,我们应该下载它:

While I am writing this, the last available version is 3.6.0. So, we should download it:

ftp://dicom.offis.de/pub/dicom/offis/software/dcmtk/dcmtk360/dcmtk-3.6.0.zip

下载完成后,您需要解压缩文件夹。 DCMTK源代码没有项目文件,但这不是问题,CMakelist文件负责在所需的操作系统/编译器中生成项目文件。如果您不熟悉CMake工具,可以在这里阅读更多信息( https://cmake.org/

After the download is finished, you need to unzip the folder. The DCMTK source doesn't have a project file, but it is not a problem, there is a CMakelist file responsible for generating a project file in your desirable Operational System/Compiler. If you are not familiar with CMake tool, you can read more here (https://cmake.org/)

1.A.1)在我的情况下,您需要安装一个编译器是Visual Studio 2012

1.A.1) You need to have an installed compiler, in my case, it was the Visual Studio 2012

1.A.2)运行 CMake工具生成Visual Studio 2012的项目文件。需要能够填充 source DCMTK目录。

1.A.2) Run the CMake tool to generate a project file to Visual Studio 2012. You need be able to fill the source DCMTK directory.

1.A.3)现在,执行VisualStudio 2012,打开文件在上一步(2)中创建的 sln 并编译目标 ALL_BUILD

1.A.3) Now, execute the VisualStudio 2012, open the file sln created in the previous step (2) and compile the target ALL_BUILD

1.A.4)以 Admin 模式重新执行Visual Studio(由于权限 C:\Program Files )以编译目标 INSTALL (它将DCMTK复制并安装到默认路径: C:/ Program Files / DCMTK / ,我们可以这样引用 PATH_WHERE_DCMTK_WAS_INSTALLED

1.A.4) Re-Execute VisualStudio in Admin mode (because of permission C:\Program Files) to compile the target INSTALL (it will copy and install the DCMTK to default path: C:/Program Files/DCMTK/, we can reference it such PATH_WHERE_DCMTK_WAS_INSTALLED)

我已经在Ubuntu / CentOS上进行了测试。首先,您应该转到 DCMTK源并运行以下三个命令:

I have tested at Ubuntu/CentOS. The first, you should go to DCMTK Source and run these following three commands:

$ ./configure --prefix=path_to_dcmtk
$ make all
$ sudo make install

示例: path_to_dcmtk = / home / user / dcmtk

example: path_to_dcmtk = /home/user/dcmtk

创建名为<$的文件c $ c> your_sample / testapp.cxx 并包含以下内容。此演示在DCMTK论坛中找到,可以打开DICOM文件并打印患者的姓名。

Create a file called your_sample/testapp.cxx with the following content. This a demonstration found in DCMTK Forum to open a DICOM file and print the patient's name.

#include "dcmtk/dcmdata/dctk.h"
#include <iostream>
using namespace std;

int main()
{
   DcmFileFormat fileformat;
   OFCondition status = fileformat.loadFile("test.dcm");
   if (status.good())
   {
      OFString patientsName;
      if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientsName).good())
      {
         cout << "Patient's Name: " << patientsName << endl;
      }else{
         cerr << "Error: cannot access Patient's Name!" << endl;
      }

   }else{
      cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
   }
   return 0;
}




3)使用VisuaStudio作为编译器创建应用程序项目


在上一步中创建的文件需要放置在项目中。您可以在选项 Windows VisualStudio(3.1) Windows Qt(3.2)之间进行选择。如果您使用的是Linux,则可以跳过此步骤。


3) Creating the Application Project using the VisuaStudio as Compiler

The created file at the previous step needs to be placed in a project. You can choose between the option Windows VisualStudio (3.1) and Windows Qt (3.2). If you are using Linux, you can skip this step.

创建Visual Studio项目,您可以使用向导并进行必要的设置,例如: Linker Libraries 等。但是,为了使此答案更容易,我将使用 CMakeList.txt 为Visual Studio 2012创建一个项目。因此,创建一个名为 your_sample / CmakeList.txt 的文件,其内容如下:

To create a Visual Studio project, you can use the Wizard and set the necessary settings such: Linker, Libraries, etc. However, to make easier on this answer, I will use the CMakeList.txt to create a Project for Visual Studio 2012. So, please, create a file called your_sample/CmakeList.txt with the following content:

PROJECT(testapp)

SET(DCMTK_DIR ABSOLUTE_PATH_WHERE_DCMTK_WAS_INSTALLED)
#an example: SET(DCMTK_DIR "C:\\Users\\test\\test_dcmtk\\DCMTK")

# settings for Microsoft Visual C++ 6
SET(CMAKE_C_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_C_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_C_FLAGS_RELEASE "/MT /O2")
SET(CMAKE_CXX_FLAGS "/nologo /W3 /GX /Gy /YX")
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd /Z7 /Od")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /O2")

ADD_DEFINITIONS(-D_REENTRANT)

INCLUDE_DIRECTORIES(${DCMTK_DIR}/include)
LINK_DIRECTORIES(${DCMTK_DIR}/lib)

ADD_EXECUTABLE(testapp testapp)
TARGET_LINK_LIBRARIES(testapp netapi32 wsock32 ofstd dcmdata)


3.B)使用VisuaStudio作为编译器的Windows QtCreator IDE


为QtCreator IDE创建项目文件。您需要创建一个名为 your_sample / my_project.pro 的文件,其内容如下:

3.B) Windows QtCreator IDE using the VisuaStudio as Compiler

To create a project file for QtCreator IDE. You need to create a file called your_sample/my_project.pro with the following content:

SOURCES += testapp.cxx
CONFIG += debug console
DEFINES += _REENTRANT

QMAKE_CFLAGS_RELEASE -= -MD
QMAKE_CFLAGS_RELEASE = -MT
QMAKE_CFLAGS_DEBUG -= -MDd
QMAKE_CFLAGS_DEBUG = -MTd
QMAKE_CXXFLAGS_RELEASE -= -MD
QMAKE_CXXFLAGS_RELEASE += -MT
QMAKE_CXXFLAGS_DEBUG -= -MDd
QMAKE_CXXFLAGS_DEBUG += -MTd

INCLUDEPATH += (RELATIVE_PATH_WHERE_DCMTK_WAS_INSTALLED)/include
#an example: INCLUDEPATH += ../../../test_dcmtk/DCMTK/include

LIBS += -L"(RELATIVE_PATH_WHERE_YOU_INSTALLED_DCMTK)/lib" \
-ladvapi32 \
-ldcmdata \
-loflog \
-lofstd \
-lws2_32 \
-lnetapi32 \
-lwsock32
#an example: LIBS += -L"../../../test_dcmtk/DCMTK/lib" \




4.A)带有Visual Studio 2012 IDE的Windows


VisualStudio 中打开项目文件,然后单击 Build


4.A) Windows with Visual Studio 2012 IDE

Open the project file at VisualStudio and click on Build.

QT 中打开项目文件,然后单击 Build

Open the project file at QT and click on Build.

g++ testapp.cxx -DHAVE_CONFIG_H -I/path_to_dcmtk/include -L/path_to_dcmtk/lib -pthread -ldcmdata -lz -loflog -lofstd -o main






请注意,是否已在 DEBUG 模式,您的应用程序也应以 DEBUG 模式进行编译。

Please, note that whether you have compiled the libraries in DEBUG mode, your application should be compiled in DEBUG mode as well.




参考


查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆