1. 程式人生 > >opencv讀攝像頭_隨機顯示線段顏色

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