gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:29:03 31 4
gpt4 key购买 nike

我正在使用 DCMTK 库 开发一个快速的 DICOM 查看器,我正在按照 this link 中提供的示例进行操作.

来自 API 的缓冲区始终为任何标签 ID 返回 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/

31 4 0