C++_OpenCV_在图像上显示时刻

参考:C++ 获取当前时间,并转换成string类型icon-default.png?t=M4ADhttps://blog.csdn.net/G_66_hero/article/details/97487543


#include<opencv.hpp>
#include<opencv2\imgproc\types_c.h>//解决CV_RGB2GRAY:无法解析的标识符
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui_c.h>
#include<opencv2\imgproc\types_c.h>

#include <iostream>
#include <sstream>
#include <iomanip>
#include <chrono>

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;
}

 

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值