http://blog.csdn.net/qq_23880193/article/details/49257637
版权声明:本文为博主原创文章,未经博主允许不得转载。
- #include<iostream>
- #include<vector>
- #include<opencv2/opencv.hpp>
-
- using namespace cv;
- using namespace std;
-
- int main()
- {
- Mat srcImage(Size(600, 600), CV_8UC3, Scalar(0));
-
- RNG &rng = theRNG();
-
- char key;
- while (1)
- {
- //随机生成一些点
- //首先就是随机生成点的总数量
- int g_nPointCount = rng.uniform(3, 30);
- //接下来就是随机生成一些点的坐标
- vector<Point> points;
- for (int i = 0; i < g_nPointCount; i++)
- {
- Point midPoint;
-
- midPoint.x = rng.uniform(srcImage.cols / 4, srcImage.cols * 3 / 4);
- midPoint.y = rng.uniform(srcImage.rows / 4, srcImage.rows * 3 / 4);
-
- points.push_back(midPoint);
- }
-
- //显示刚刚随机生成的那些点
- for (int i = 0; i < g_nPointCount; i++)
- {
- circle(srcImage, points[i], 0, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), 3);
- }
-
- //在生成的那些随机点中寻找最小包围圆形
- Point2f center;
- float radius;
- minEnclosingCircle(points, center, radius);
-
- //根据得到的圆形和半径 绘制圆形
- circle(srcImage, static_cast<Point>(center), (int)radius
- , Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), 3);
-
- imshow("【绘制结束后的图像】", srcImage);
-
- key = waitKey();
- if (key == 27)
- break;
- else
- srcImage = Scalar::all(0);
- }
-
- return 0;
- }