openCV测试代码(调用摄像头获取图片并转换)

#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;
	}
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值