将tiff文件解析并存储为raw。
读取及解析tiff:
QString fileName = QFileDialog::getOpenFileName(this, tr("打开图片文件"), "./");
if (fileName.endsWith(".tiff")) {
m_img = cv::imread(fileName.toStdString(), CV_LOAD_IMAGE_UNCHANGED);
if (m_imgData != NULL) {
delete m_imgData;
m_imgData = NULL;
}
m_rows = m_img.rows;
m_cols = m_img.cols;
qDebug() << "data: " << m_img.at<ushort>(0, 0);
m_imgData = new ushort[m_rows * m_cols]();
memset(m_imgData, 0, m_rows*m_cols * sizeof(ushort));
for (int i = 0; i < m_img.rows; i++) {
for (int j = 0; j < m_img.cols; j++) {
m_imgData[i * m_img.cols + j] = m_img.at<ushort>(i, j);
}
}
}
写raw文件:
QString setFilter = "Raw Files(*.raw)";
QString fileName = QFileDialog::getSaveFileName(this, tr("保存文件"), "./", setFilter);
//qDebug() << "save filename: " << fileName;
if (m_imgData == NULL)
return;
FILE *file;
errno_t error = fopen_s(&file, fileName.toStdString().data(), "wb");
if (error == 0) {
fwrite(m_imgData, sizeof(ushort), m_rows * m_cols, file);
}
fclose(file);
qDebug() << "on_writeBtn_clicked data: " << m_imgData[0];
读raw文件:
if (m_imgData == NULL)
return;
QString setFilter = "Raw Files(*.raw)";
QString fileName = QFileDialog::getOpenFileName(this, tr("打开图片文件"), "./", setFilter);
FILE* file;
errno_t error = fopen_s(&file, fileName.toStdString().data(), "rb");
if (error == 0) {
fread(m_imgData, sizeof(ushort), m_rows * m_cols, file);
}
fclose(file);
qDebug() << "on_readBtn_clicked data: " << m_imgData[0];