opencv:随机数和随机颜色(十五)

文章目录

  • 一、随机数和随机颜色


一、随机数和随机颜色

using namespace std;
using namespace cv;


class QuickDemo
{
public:

	void random_drawinf()
	{
		Mat canvas = Mat::zeros(Size(512,512), CV_8UC3);
		int w = canvas.cols;
		int h = canvas.rows;
		RNG mg(12345);
		while (true) 
		{
			int c = waitKey(10);
			if (c == 27) 
			{
				break;
			}
			int x1 = mg.uniform(0, w);
			int y1 = mg.uniform(0, h);
			int x2 = mg.uniform(0, w);
			int y2 = mg.uniform(0, h);
			int b = mg.uniform(0,255);
			int g = mg.uniform(0,255);
			int r = mg.uniform(0,255);
			// 每次绘制将之前的清空
			canvas = Scalar(0,0,0);
			line(canvas, Point(x1, y1), Point(x2, y2), Scalar(b,g,r),1,LINE_AA, 0);
			imshow("123",canvas);
		}
	}

};

int main()
{
	QuickDemo qd;
	qd.random_drawinf();
}

你可能感兴趣的:(opencv,opencv,计算机视觉,c++)