参考:C++ 获取当前时间,并转换成string类型https://blog.csdn.net/G_66_hero/article/details/97487543
#include#include //解决CV_RGB2GRAY:无法解析的标识符 #include #include #include #include #include #include #include #include #include using namespace cv; using namespace std; int main() { //1.从摄像头读入视频 VideoCapture cap(0); //2.循环显示每一帧 while (1) { Mat cam; cap >> cam;//获取相机当前帧图像 auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); //转为字符串 std::stringstream ss; // 可以分别以不同的形式进行显示 ss << std::put_time(std::localtime(&t), "%m-%d_%H:%M:%S"); //ss << std::put_time(std::localtime(&t), "%Y年%m月%d日%H时%M分%S秒"); //ss << std::put_time(std::localtime(&t), "%Y%m%d%H%M%S"); std::string str_time = ss.str(); //添加文本到图像 putText(cam, str_time, Point(50, 50), CV_FONT_HERSHEY_COMPLEX, 2, Scalar(25, 255, 25), 3); imshow("Camera", cam);//显示当前图像 waitKey(1);//延时 } return 0; }



