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

我的代码:
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()
Run Code Online (Sandbox Code Playgroud)
提前致谢.
Abh*_*kur 18
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
Run Code Online (Sandbox Code Playgroud)
仅对边框使用"thickness"参数.
yan*_*ng5 15
只是一个额外的信息:
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)
Run Code Online (Sandbox Code Playgroud)