2013-05-10 109 views
4

林usign蟒蛇和OpenCV一个圆圈,从摄像头获取的图像,我想知道如何绘制了我的形象了一圈,只是一个简单的绿色圆圈透明填充上绘制图像的OpenCV

enter image description here

我的代码:

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() 

在此先感谢。

+0

cv2.circle打圈了我的形象,但我想圆的只是边界,任何想法? – 2013-05-10 15:09:04

+0

http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html 保持这个方便,同时使用绘图功能在opencv – 2016-08-14 08:57:13

回答

7
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 

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

1

尝试

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

documentation更多细节

+0

这也有帮助http://www.aishack.in/2010/07/transparent-image-overlays-in-opencv /它的直方图叠加,但你可以叉它 – 2013-05-10 16:38:11

+2

我还发现这个示例代码http://bistr-o-mathik.org/2012/06/13/simple-transparency-in- OpenCV的/ – 2013-05-10 16:42:27

3

只是一个额外的信息:

的OpenCV的绘图功能cv2.circle的参数 “中心”()有两个一个元组整数。第一个是宽度位置,第二个是高度位置。该顺序与通常的数组索引不同。以下示例演示了该问题。

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