使用背景:
需要用程序自动存储很多个文件,但不太方便自定义有限个名称(数组或其他);借助ros时间戳来实现命名
c++代码实现:
//把ros时间转换为浮点数类型,即数值型
double image_time =ros::Time::now().toSec();
//把数值型转换为字符串型
std::string image_time_=to_string(image_time);
//存储文件,这里是图片
cv::imwrite(image_time_+".jpeg",my_img);