#include <iostream>
#include <opencv2/core/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2\imgproc\types_c.h>
using namespace cv;
using namespace std;
int main() {
//VideoCapture capture("video.aiv");//打开指定视频
VideoCapture capture(0);//打开摄像头
if (!capture.isOpened())//没有打开摄像头的话,就返回。
return 1;
Mat img1;
Mat img_binary;
while (true)
{
Mat frame;
capture >> frame;
cvtColor(frame, img1, CV_BGR2GRAY);//将原图转为灰阶图
threshold(img1, img_binary, 100, 255, CV_THRESH_BINARY);//将灰度图转为二值图
putText(frame, "Hello Word!!", Point(40, 60), FONT_HERSHEY_COMPLEX_SMALL, 2, Scalar(125, 125, 225), 1, 8, false);//显示字体在原图中
imshow("原图", frame);
imshow("灰度图", img1);
imshow("二值图", img_binary);
waitKey(20000);//等待40毫秒
if (cv::waitKey(50) == 27) {//按esc键退出
//SaveImage("Image.png", frame, 0);//保存当前屏幕上的图像到本地
break;
}
return 0;
}
}
openCV测试代码(调用摄像头获取图片并转换)
最新推荐文章于 2024-07-22 15:08:28 发布