2013-05-10 105 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