c++ - DCMTK 中的 findAndGetString() 为标签返回 null

标签 c++ qt dicom dcmtk

我正在使用DCMTK库开发一个快速的DICOM查看器,并且我正在遵循this link中提供的示例.

对于任何标签 ID,API 的缓冲区始终返回 null,例如:DCM_PatientName。 但是 findAndGetOFString() API 工作正常,但仅以 ASCII 返回标记的第一个字符,这是该 API 应该如何工作的吗?

有人可以告诉我为什么以前的 API 缓冲区为空吗?

DicomImage API 也有同样的问题。

Snippet 1:

DcmFileFormat fileformat;
OFCondition status = fileformat.loadFile(test_data_file_path.toStdString().c_str());
if (status.good())
{
   OFString  patientName;
   char* name;
   if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
    {
      name = new char[patientName.length()];
      strcpy(name, patientName.c_str());
    }
    else
    {
      qDebug() << "Error: cannot access Patient's Name!";
    }
 } 
 else
 {
    qDebug() << "Error: cannot read DICOM file (" << status.text() << ")";
 }

在上面的代码片段中,name 的 ASCII 值是“50”,实际名称是“PATIENT”。

Snippet 2:

DcmFileFormat file_format;  
OFCondition status = file_format.loadFile(test_data_file_path.toStdString().c_str());
std::shared_ptr<DcmDataset> dataset(file_format.getDataset());
qDebug() << "\nInformation extracted from DICOM file: \n";
const char* buffer = nullptr;
DcmTagKey key = DCM_PatientName;
dataset->findAndGetString(key,buffer);
std::string tag_value = buffer;
qDebug() << "Patient name: " << tag_value.c_str();

在上面的代码片段中,缓冲区为空。它不读取名称。

注意:

This is only a sample. I am just playing around the APIs for learning purpose.

最佳答案

以下示例方法从 DcmDataset 对象读取患者姓名:

std::string getPatientName(DcmDataset& dataset)
{
    // Get the tag's value in ofstring
    OFString ofstring;
    OFCondition condition = dataset.findAndGetOFString(DCM_PatientName, ofstring);
    if(condition.good())
    {
        // Tag found. Put it in a std::string and return it
        return std::string(ofstring.c_str());
    }

    // Tag not found
    return ""; // or throw if you need the tag
}

关于c++ - DCMTK 中的 findAndGetString() 为标签返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46036364/

相关文章:

dicom - fo-dicom - 如何从 PACS 下载 dcm 图像并保存它们?

c++ - 如果我在堆上声明一个类实例,它的所有成员也会在堆上吗?

c++ - C++ 放置的多个参数 new 'constructor'

c++ - 在类中操作 vector 时遇到问题

c++ - C++ header 中的 `using` 指令

qt - 有没有办法在Qt Designer中设置QLabel的可见性

Qt从字符串中删除正则表达式

dicom - 计算位图的窗口宽度和窗口中心

c++ - 如何使用局部变量作为 MySQL 查询的一部分 (Qt C++)

c# - 如何将图像保存为 DICOM