读取图像并连接电脑摄像头

//读取图像
/*#include <opencv2/opencv.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(int argc, char** argv) {
//VideoCapture capture;
//capture.open("D:/vcprojects/images/video_006.mp4");
VideoCapture capture(0);
if (!capture.isOpened()) {
printf("could not load video data...\n");
return -1;
}
// 获取帧的属性
double fps = capture.get(CV_CAP_PROP_FPS);
Size size = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT));
printf("FPS : %f", fps);
VideoWriter writer("D:/opencv基本代码/视频/vw_demo.avi", -1, 15.0, size, true);

// create window
Mat frame, gray, binary;
namedWindow("video-demo", CV_WINDOW_AUTOSIZE);

// show each frame and save
//vector<Mat> bgr;
while (capture.read(frame)) {
//inRange(frame, Scalar(0, 127, 0), Scalar(127, 255, 127), gray);
//cvtColor(frame, gray, COLOR_BGR2GRAY);
//threshold(gray, binary, 0, 255, THRESH_BINARY | THRESH_OTSU);
//bitwise_not(frame, frame);
//flip(frame, frame, 1);
imshow("video-demo", frame);
writer.write(frame);
char c = waitKey(100);
if (c == 27) {
break;
}
}

waitKey(0);
return 0;
}*/

//连接摄像头
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main(int argc, char**argv)
{
	//VideoCapture capture;
	//capture.open("D:/opencv基本代码/视频/video_004.avi");
	VideoCapture capture(0);
	/*if (!capture.isOpened()) {
		printf("could not load video data..\n");
		return -1;
	}

	double fps = capture.get(CV_CAP_PROP_FPS);
	printf("fps:%f", fps);
	Size size = Size(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_WIDTH));*/
	//VideoWriter write("D:/opencv基本代码/视频/wv_demo.mp4", CV_FOURCC('D', 'I', 'V', 'X'), 15.0, size, true);
	
	Mat frame,gray,binary;
	namedWindow("video_demo", CV_WINDOW_AUTOSIZE);
	while (capture.read(frame)) {

		cvtColor(frame, gray, COLOR_BGR2GRAY);//灰度化
		threshold(gray, binary, 0, 255, THRESH_BINARY | THRESH_OTSU);//阈值化
		//bitwise_not(frame, frame);//取反(类似于x光哈哈哈哈哈)
		imshow("video_demo",binary);

		//write.write(frame);
		char c = waitKey(100);
		if (c == 27) {
			break;
		}
	}
	waitKey(0);
	return 0;

}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值