opencv读摄像头_随机显示线段颜色

#include <opencv2/core/core.hpp>  
#include <opencv2/highgui/highgui.hpp> 
#include <opencv2/imgproc/imgproc.hpp> 
#include <opencv/cv.h>

using namespace cv;
using namespace std;

int main(int argc, char **argv)
{
	Mat frame,GrayFrame,resFrame,RoiImg;
	VideoCapture cap0(0);
	cap0 >> frame;
	
	//随机播种
	cv::RNG rng(time(0));
	while (cap0.isOpened())
	{
		cap0 >> frame;
		//调整图像尺寸
		resize(srcImg, resFrame, cv::Size(100, 100));
		//彩色图转灰度图
		cvtColor(frame, GrayFrame, CV_BGR2GRAY);
		
		//获取图片某一区域的图像
		cv::Rect rt;
		rt.x = 0;
		rt.y = 0;
		rt.width = GrayFrame.cols;
		rt.height = GrayFrame.rows;
		RoiImg = Gray(rt);
		Point pt1, pt2;
		
		pt1.x = 0;
		pt1.y = 0;
		pt2.x = 100;
		pt2.y = 100;
		//随机显示颜色
		line(frame, pt1, pt2, cv::Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), 2, CV_AA);
		imshow("frame", frame);
		waitKey(1);
	}
		
	system("pause");

	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值