定制cv2.ci

2024-06-23 19:50:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我用下面的代码画圆周围的脸。在

for (x, y, w, h) in faces:
    cv2.circle(img, ( int((x + x + w )/2), int((y + y + h)/2 )), int (h / 2), (0, 255, 0), 5)

然而,绘制的圆的厚度是完全绿色的。有没有办法让这个圆圈的几个百分比(比如30%)变成粉红色?在


Tags: 代码inimgfor绘制cv2int百分比
1条回答
网友
1楼 · 发布于 2024-06-23 19:50:25

正如我在评论中建议的那样,您可以使用^{}分别绘制两个圆弧。例如:

import numpy as np
import cv2

img = np.ones((400,400,3), np.uint8) * 255

# See:
#   http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html#cv2.ellipse
#   http://docs.opencv.org/3.1.0/dc/da5/tutorial_py_drawing_functions.html

circ_center = (200,200)
circ_radius = 150
circ_thick  = 12
circ_axes   = (circ_radius,circ_radius)

# cv2.ellipse(img, center, axes, angle, startAngle, endAngle, color[, thickness[, lineType[, shift]]])    
cv2.ellipse(img, circ_center, circ_axes, 0,  0,  90, (255,0,0), circ_thick, cv2.LINE_AA)
cv2.ellipse(img, circ_center, circ_axes, 0, 90, 360, (0,255,0), circ_thick, cv2.LINE_AA)

cv2.imshow("Image", img)
cv2.imwrite("circ1.png", img)
cv2.waitKey()

产生:

Arcs1

现在,弧有圆边。这对你来说可能是个问题,也可能不是问题。我不确定OpenCV中是否有更好的方法,但是我创建了一种边缘平坦的粗线条的方法,就是用许多细线构建粗线条。在

例如:

^{pr2}$

产生:

Arcs2

您可以通过调整startAngleendAngle参数来调整着色的起点和终点。您可能需要在其中调整一些其他参数,但这将使您了解一种方法。在

你也可以画一个完整的圆,然后在上面画一个弧,与你想要的颜色不同,这可能会更容易。在

相关问题 更多 >

    热门问题