【发布时间】:2018-07-21 12:24:56
【问题描述】:
我的目标是保存图像(opencv 2.4.13)并在图像名称中包含当前日期时间(类似于:current-datetime.jpg)。我试过下面的代码-
string d_t =
QDateTime::currentDateTime().toString(Qt::ISODate).toLocal8Bit().constData();
string output_file =
"F:\\WorkSpace\\QtPractice\\resource\\face_db\\"+d_t+".jpg";
cv::imwrite(output_file, image);
cout << output_file << endl; // to check the file location
但我在目标位置什么也没得到。
当我尝试下面的代码来检查它是否可以正常工作以保存图像时-
string d_t = to_string(3.1415926)
string output_file = "F:\\WorkSpace\\QtPractice\\resource\\face_db\\"+d_t+".jpg";
cv::imwrite(output_file, image);
cout << output_file << endl;
而且效果很好。所以,我认为我在转换字符串时做错了,因为第二个代码正常工作。有人可以帮我用当前日期时间写图像吗?我做错了什么?谢谢。
【问题讨论】:
-
QDateTime::currentDateTime().toString(Qt::ISODate).toStdString(); -
@Miki ,也试过了。没用。仍然没有得到要保存的图像。
-
IsoDate 的冒号“:”对路径无效。使用其他日期格式
-
@miki,现在我不明白我可以使用哪种格式(基本上我需要带冒号的 IsoDate 格式)。根据此文档,其他格式要么有冒号“:”,要么有空格。你能建议我如何纠正这个问题吗? doc.qt.io/qt-5/qtime.html#toString-1