如何在OpenCV中绘制具有随机颜色的圆

如何在OpenCV中绘制具有随机颜色的圆

本文介绍了如何在OpenCV中绘制具有随机颜色的圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SURF算法将两个图像与OpenCV匹配。
而且我有按键。

I am using SURF algorithm to match two images with OpenCV.And I have got the keypioints.

现在,我想用随机的颜色圆圈绘制这些关键点。

Now I want to draw these keypoints with random colors circles.

我知道如何使用cvCircle函数在OpenCV中绘制圆,但是颜色由 cvScalar(r,g,b)固定。

I know how to draw a circle in OpenCV with the function cvCircle, but the color is fixed with cvScalar(r,g,b).

我希望图像中关键点的圆形颜色与其附近的圆形不同。

I want the the color of the circle of a keypoint in a image is different to the circles near it.

库函数OpenCV中的 cv :: drawMatches()具有我想要的效果。但是我不知道该怎么实现。

The library function cv::drawMatches() in OpenCV have the effect I want. But I don't know how to realize it.

有人可以告诉我如何绘制圆圈吗?

Does anyone who can tell me how to draw the circles.

谢谢!

推荐答案

假设您要在垫子图像上绘制不同颜色的圆圈。这是一种生成随机颜色的方法:

Suppose you want to draw circles in different colors on Mat image. Here is a way to generate random colors:

RNG rng(12345);
Mat image = Mat::zeros(500, 500, CV_8UC3);     // change to the size of your image
for (int i = 0; i < circleNum; i++) {
    Scalar color = Scalar(rng.uniform(0,255), rng.uniform(0, 255), rng.uniform(0, 255));
    circle(image, center[i], radius[i], color, -1, 8, 0);
}

这篇关于如何在OpenCV中绘制具有随机颜色的圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:21