Python 在图像 opencv 上画一个圆圈

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16484796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 22:47:28  来源:igfitidea点击:

draw a circle over image opencv

pythonopencvdrawing

提问by Art Grc

Im usign python and opencv to get a image from the webcam, and I want to know how to draw a circle over my image, just a simple green circle with transparent fill

我使用 python 和 opencv 从网络摄像头获取图像,我想知道如何在我的图像上绘制一个圆圈,只是一个带有透明填充的简单绿色圆圈

enter image description here

在此处输入图片说明

my code:

我的代码:

import cv2
import numpy
import sys

if __name__ == '__main__':


    #get current frame from webcam
    cam = cv2.VideoCapture(0)
    img = cam.read()

    #how draw a circle????

    cv2.imshow('WebCam', img)

    cv2.waitKey()

Thanks in advance.

提前致谢。

采纳答案by Abhishek Thakur

cv2.circle(img, center, radius, color, thickness=1, lineType=8, shift=0) → None
Draws a circle.

Parameters: 
img (CvArr) – Image where the circle is drawn
center (CvPoint) – Center of the circle
radius (int) – Radius of the circle
color (CvScalar) – Circle color
thickness (int) – Thickness of the circle outline if positive, otherwise this indicates that a filled circle is to be drawn
lineType (int) – Type of the circle boundary, see Line description
shift (int) – Number of fractional bits in the center coordinates and radius value

Use "thickness" parameter for only the border.

仅对边框使用“厚度”参数。

回答by Rachel Gallen

try

尝试

cv2.circle(img, center, radius, color[, thickness[, lineType[, shift]]])

See the documentationfor more details

有关更多详细信息,请参阅文档

回答by yang5

Just an additional information:

只是一个额外的信息:

The parameter "center" of OpenCV's drawing function cv2.circle() takes a tuple of two integers. The first is the width location and the second is the height location. This ordering is different from the usual array indexing. The following example demonstrates the issue.

OpenCV 的绘图函数 cv2.circle() 的参数“center”采用两个整数的元组。第一个是宽度位置,第二个是高度位置。这种排序不同于通常的数组索引。以下示例演示了该问题。

import numpy as np
import cv2

height, width = 150, 200
img = np.zeros((height, width, 3), np.uint8)
img[:, :] = [255, 255, 255]

# Pixel position to draw at
row, col = 20, 100

# Draw a square with position 20, 100 as the top left corner
for i in range(row, 30):
    for j in range(col, 110):
        img[i, j] = [0, 0, 255]

# Will the following draw a circle at (20, 100)?
# Ans: No. It will draw at row index 100 and column index 20.
cv2.circle(img,(row, col), 5, (0,255,0), -1)

cv2.imwrite("square_circle_opencv.jpg", img)

python opencv cv2.circle center indexing issue

python opencv cv2.circle中心索引问题