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.
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.
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.
Thanks!
Using random() function to generate random colors To begin, import the random function in Python to obtain a random color. The variable r stands for red, g stands for green, and b stands for blue. We already know that the RGB format contains an integer value ranging from 0 to 255.
random() to generate a random color for a Matplotlib plot. Create three variables r , g , and b , each assigned a random float value in the range [0, 1] by calling random. random() . Use the syntax (r, g, b) to generate an RGB tuple color .
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With