Mat bg = Mat::zeros(Size(512,512), CV_8UC3); int w = bg.cols; int h = bg.rows; RNG rng(12345); while (true) { int c = cv::waitKey(10); if (c == 27) { break; } int x1 = rng.uniform(0, w); int y1 = rng.uniform(0, h); int x2 = rng.uniform(0, w); int y2 = rng.uniform(0, h); bg = Scalar(0, 0, 0); line(bg, Point(x1, y1), Point(x2, y2), Scalar(rng.uniform(0,255), rng.uniform(0, 255), rng.uniform(0, 255)), 2, LINE_AA, 0); imshow("Draw_random", bg); }
推荐一个零声学院项目课,个人觉得老师讲得不错,分享给大家: