函数 circle() 绘制具有给定中心和半径的空心或实心圆。

函数说明

1
void cv::circle (InputOutputArray img, Point center, int radius, const Scalar &color, int thickness=1, int lineType=LINE_8, int shift=0)

参数说明

img:输入图像。
center:圆的中心点坐标。cv::Point (x, y)
radius:半径。
color:圆的颜色。cv::Scalar (B, G, R)
thickness:圆形轮廓的粗细 (如果为正)。负值 (如 FILLED) 表示要绘制实心圆。
lineType:圆边界的类型。查看 LineTypes。
shift:中心坐标和半径值中的小数位数。

代码测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/python
# coding=utf-8

import cv2
from matplotlib import pyplot as plt

import numpy as np

img = cv2.imread('pictures/photo_faces.jpg')
origin = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)  # 将图像转换为RGB格式 原因:matplotlib 的颜色通道是GBR,不是一般的RGB
plt.subplot(121),plt.imshow(origin),plt.title('Origin')

cv2.circle(origin, (100, 160), 30, (255, 0, 0), 2)  # 绘制圆形
cv2.circle(origin, (200, 160), 30, (255, 0, 0), -1)  # 绘制圆形
plt.subplot(122),plt.imshow(origin),plt.title('Circle')

plt.suptitle('Circle samples')
plt.show()

测试结果