本文整理汇总了Python中cv2.ellipse方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.ellipse方法的具体用法?Python cv2.ellipse怎么用?Python cv2.ellipse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.ellipse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getEllipseRotation
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def getEllipseRotation(image, cnt):
try:
# Gets rotated bounding ellipse of contour
ellipse = cv2.fitEllipse(cnt)
centerE = ellipse[0]
# Gets rotation of ellipse; same as rotation of contour
rotation = ellipse[2]
# Gets width and height of rotated ellipse
widthE = ellipse[1][0]
heightE = ellipse[1][1]
# Maps rotation to (-90 to 90). Makes it easier to tell direction of slant
rotation = translateRotation(rotation, widthE, heightE)
cv2.ellipse(image, ellipse, (23, 184, 80), 3)
return rotation
except:
# Gets rotated bounding rectangle of contour
rect = cv2.minAreaRect(cnt)
# Creates box around that rectangle
box = cv2.boxPoints(rect)
# Not exactly sure
box = np.int0(box)
# Gets center of rotated rectangle
center = rect[0]
# Gets rotation of rectangle; same as rotation of contour
rotation = rect[2]
# Gets width and height of rotated rectangle
width = rect[1][0]
height = rect[1][1]
# Maps rotation to (-90 to 90). Makes it easier to tell direction of slant
rotation = translateRotation(rotation, width, height)
return rotation
#################### FRC VISION PI Image Specific #############
示例2: additive_shade
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def additive_shade(image, nb_ellipses=20, transparency_range=(-0.5, 0.8),
kernel_size_range=(250, 350)):
def _py_additive_shade(img):
img=img.astype(np.float32)
min_dim = min(img.shape[:2]) / 4
mask = np.zeros(img.shape[:2], np.uint8)
for i in range(nb_ellipses):
ax = int(max(np.random.rand() * min_dim, min_dim / 5))
ay = int(max(np.random.rand() * min_dim, min_dim / 5))
max_rad = max(ax, ay)
x = np.random.randint(max_rad, img.shape[1] - max_rad) # center
y = np.random.randint(max_rad, img.shape[0] - max_rad)
angle = np.random.rand() * 90
cv2.ellipse(mask, (x, y), (ax, ay), angle, 0, 360, 255, -1)
transparency = np.random.uniform(*transparency_range)
kernel_size = np.random.randint(*kernel_size_range)
if (kernel_size % 2) == 0: # kernel_size has to be odd
kernel_size += 1
mask = cv2.GaussianBlur(mask.astype(np.float32), (kernel_size, kernel_size), 0)
shaded = img * (1 - transparency * mask[..., np.newaxis]/255.)
return np.clip(shaded, 0, 255).astype(np.uint8)
return _py_additive_shade(image)
示例3: draw_face_ellipse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def draw_face_ellipse(image, faces_coord):
""" Draws an ellipse around the face found.
"""
for (x, y, w, h) in faces_coord:
center = (x + w / 2, y + h / 2)
axis_major = h / 2
axis_minor = w / 2
cv2.ellipse(image,
center=center,
axes=(axis_major, axis_minor),
angle=0,
startAngle=0,
endAngle=360,
color=(206, 0, 209),
thickness=2)
return image
示例4: get_forehead_landmark
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def get_forehead_landmark(self,im_bgr,face_landmark,mask_organs,mask_nose):
'''
计算额头坐标
'''
#画椭圆
radius=(np.linalg.norm(face_landmark[0]-face_landmark[16])/2).astype('int32')
center_abs=tuple(((face_landmark[0]+face_landmark[16])/2).astype('int32'))
angle=np.degrees(np.arctan((lambda l:l[1]/l[0])(face_landmark[16]-face_landmark[0]))).astype('int32')
mask=np.zeros(mask_organs.shape[:2], dtype=np.float64)
cv2.ellipse(mask,center_abs,(radius,radius),angle,180,360,1,-1)
#剔除与五官重合部分
mask[mask_organs[:,:,0]>0]=0
#根据鼻子的肤色判断真正的额头面积
index_bool=[]
for ch in range(3):
mean,std=np.mean(im_bgr[:,:,ch][mask_nose[:,:,ch]>0]),np.std(im_bgr[:,:,ch][mask_nose[:,:,ch]>0])
up,down=mean+0.5*std,mean-0.5*std
index_bool.append((im_bgr[:,:,ch]<down)|(im_bgr[:,:,ch]>up))
index_zero=((mask>0)&index_bool[0]&index_bool[1]&index_bool[2])
mask[index_zero]=0
index_abs=np.array(np.where(mask>0)[::-1]).transpose()
landmark=cv2.convexHull(index_abs).squeeze()
return landmark
示例5: __draw_ellipse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def __draw_ellipse(a_max, a_min, angle, aurmax, aurmin, details, hairmax, hairmin, nipmax, nipmin, obj,
titmax, titmin, vagmax, vagmin, x, y):
# Draw ellipse
if obj.name == "tit":
cv2.ellipse(details, (x, y), (titmax, titmin), angle, 0, 360, (0, 205, 0), -1) # (0,0,0,50)
elif obj.name == "aur":
cv2.ellipse(details, (x, y), (aurmax, aurmin), angle, 0, 360, (0, 0, 255), -1) # red
elif obj.name == "nip":
cv2.ellipse(details, (x, y), (nipmax, nipmin), angle, 0, 360, (255, 255, 255), -1) # white
elif obj.name == "belly":
cv2.ellipse(details, (x, y), (a_max, a_min), angle, 0, 360, (255, 0, 255), -1) # purple
elif obj.name == "vag":
cv2.ellipse(details, (x, y), (vagmax, vagmin), angle, 0, 360, (255, 0, 0), -1) # blue
elif obj.name == "hair":
xmin = x - hairmax
ymin = y - hairmin
xmax = x + hairmax
ymax = y + hairmax
cv2.rectangle(details, (xmin, ymin), (xmax, ymax), (100, 100, 100), -1)
示例6: gaussian
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def gaussian(self, mean, covariance, label=None):
"""Draw 95% confidence ellipse of a 2-D Gaussian distribution.
Parameters
----------
mean : array_like
The mean vector of the Gaussian distribution (ndim=1).
covariance : array_like
The 2x2 covariance matrix of the Gaussian distribution.
label : Optional[str]
A text label that is placed at the center of the ellipse.
"""
# chi2inv(0.95, 2) = 5.9915
vals, vecs = np.linalg.eigh(5.9915 * covariance)
indices = vals.argsort()[::-1]
vals, vecs = np.sqrt(vals[indices]), vecs[:, indices]
center = int(mean[0] + .5), int(mean[1] + .5)
axes = int(vals[0] + .5), int(vals[1] + .5)
angle = int(180. * np.arctan2(vecs[1, 0], vecs[0, 0]) / np.pi)
cv2.ellipse(
self.image, center, axes, angle, 0, 360, self._color, 2)
if label is not None:
cv2.putText(self.image, label, center, cv2.FONT_HERSHEY_PLAIN,
2, self.text_color, 2)
示例7: drawBrushesOnImage
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def drawBrushesOnImage(brushes, color, im, pc, image_scale, fill=True):
for brush in brushes:
center = pc.tgcToCV2(brush["position"]["x"], brush["position"]["z"], image_scale)
center = (center[1], center[0]) # In point coordinates, not pixel
width = brush["scale"]["x"] / image_scale
height = brush["scale"]["z"] / image_scale
rotation = - brush["rotation"]["y"] # Inverted degrees, cv2 bounding_box uses degrees
thickness = 4
if fill:
thickness = -1 # Negative thickness is a filled ellipse
brush_type_name = tgc_definitions.brushes.get(int(brush["type"]), "unknown")
if 'square' in brush_type_name:
box_points = cv2.boxPoints((center, (2.0*width, 2.0*height), rotation)) # Squares seem to be larger than circles
box_points = np.int32([box_points]) # Bug with fillPoly, needs explict cast to 32bit
if fill:
cv2.fillPoly(im, box_points, color, lineType=cv2.LINE_AA)
else:
cv2.polylines(im, box_points, True, color, thickness, lineType=cv2.LINE_AA)
else: # Draw as ellipse for now
'''center – The rectangle mass center.
size – Width and height of the rectangle.
angle – The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.'''
bounding_box = (center, (1.414*width, 1.414*height), rotation) # Circles seem to scale according to radius
cv2.ellipse(im, bounding_box, color, thickness=thickness, lineType=cv2.LINE_AA)
示例8: drawObjectsOnImage
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def drawObjectsOnImage(objects, color, im, pc, image_scale):
for ob in objects:
for item in ob["Value"]["items"]:
# Assuming all items are ellipses for now
center = pc.tgcToCV2(item["position"]["x"], item["position"]["z"], image_scale)
center = (center[1], center[0]) # In point coordinates, not pixel
width = max(item["scale"]["x"] / image_scale, 8.0)
height = max(item["scale"]["z"] / image_scale, 8.0)
rotation = - item["rotation"]["y"] * math.pi / 180.0 # Inverted degrees, cv2 uses clockwise radians
'''center – The rectangle mass center.
size – Width and height of the rectangle.
angle – The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.'''
bounding_box_of_ellipse = (center, (width, height), rotation)
cv2.ellipse(im, bounding_box_of_ellipse, color, thickness=-1, lineType=cv2.LINE_AA)
for cluster in ob["Value"]["clusters"]:
# Assuming all items are ellipses for now
center = pc.tgcToCV2(cluster["position"]["x"], cluster["position"]["z"], image_scale)
center = (center[1], center[0]) # In point coordinates, not pixel
width = cluster["radius"] / image_scale
height = cluster["radius"] / image_scale
rotation = - cluster["rotation"]["y"] * math.pi / 180.0 # Inverted degrees, cv2 uses clockwise radians
'''center – The rectangle mass center.
size – Width and height of the rectangle.
angle – The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.'''
bounding_box_of_ellipse = (center, (width, height), rotation)
cv2.ellipse(im, bounding_box_of_ellipse, color, thickness=-1, lineType=cv2.LINE_AA)
示例9: describe
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def describe(self, image):
# convert the image to the HSV color space and initialize
# the features used to quantify the image
image = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
features = []
# grab the dimensions and compute the center of the image
(h, w) = image.shape[:2]
(cX, cY) = (int(w * 0.5), int(h * 0.5))
# divide the image into four rectangles/segments (top-left,
# top-right, bottom-right, bottom-left)
segments = [(0, cX, 0, cY), (cX, w, 0, cY),
(cX, w, cY, h), (0, cX, cY, h)]
# construct an elliptical mask representing the center of the
# image
(axesX, axesY) = (int(w * 0.75) / 2, int(h * 0.75) / 2)
ellipMask = np.zeros(image.shape[:2], dtype="uint8")
cv2.ellipse(ellipMask, (cX, cY), (axesX, axesY), 0, 0, 360, 255, -1)
# loop over the segments
for (startX, endX, startY, endY) in segments:
# construct a mask for each corner of the image, subtracting
# the elliptical center from it
cornerMask = np.zeros(image.shape[:2], dtype="uint8")
cv2.rectangle(cornerMask, (startX, startY), (endX, endY), 255, -1)
cornerMask = cv2.subtract(cornerMask, ellipMask)
# extract a color histogram from the image, then update the
# feature vector
hist = self.histogram(image, cornerMask)
features.extend(hist)
# extract a color histogram from the elliptical region and
# update the feature vector
hist = self.histogram(image, ellipMask)
features.extend(hist)
# return the feature vector
return features
示例10: draw_gaussain
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def draw_gaussain(img, mean, cov, color):
x, y = np.int32(mean)
w, u, vt = cv2.SVDecomp(cov)
ang = np.arctan2(u[1, 0], u[0, 0])*(180/np.pi)
s1, s2 = np.sqrt(w)*3.0
cv2.ellipse(img, (x, y), (s1, s2), ang, 0, 360, color, 1, cv2.LINE_AA)
示例11: make_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def make_image():
img = np.zeros((500, 500), np.uint8)
black, white = 0, 255
for i in xrange(6):
dx = int((i%2)*250 - 30)
dy = int((i/2.)*150)
if i == 0:
for j in xrange(11):
angle = (j+5)*np.pi/21
c, s = np.cos(angle), np.sin(angle)
x1, y1 = np.int32([dx+100+j*10-80*c, dy+100-90*s])
x2, y2 = np.int32([dx+100+j*10-30*c, dy+100-30*s])
cv2.line(img, (x1, y1), (x2, y2), white)
cv2.ellipse( img, (dx+150, dy+100), (100,70), 0, 0, 360, white, -1 )
cv2.ellipse( img, (dx+115, dy+70), (30,20), 0, 0, 360, black, -1 )
cv2.ellipse( img, (dx+185, dy+70), (30,20), 0, 0, 360, black, -1 )
cv2.ellipse( img, (dx+115, dy+70), (15,15), 0, 0, 360, white, -1 )
cv2.ellipse( img, (dx+185, dy+70), (15,15), 0, 0, 360, white, -1 )
cv2.ellipse( img, (dx+115, dy+70), (5,5), 0, 0, 360, black, -1 )
cv2.ellipse( img, (dx+185, dy+70), (5,5), 0, 0, 360, black, -1 )
cv2.ellipse( img, (dx+150, dy+100), (10,5), 0, 0, 360, black, -1 )
cv2.ellipse( img, (dx+150, dy+150), (40,10), 0, 0, 360, black, -1 )
cv2.ellipse( img, (dx+27, dy+100), (20,35), 0, 0, 360, white, -1 )
cv2.ellipse( img, (dx+273, dy+100), (20,35), 0, 0, 360, white, -1 )
return img
示例12: DrawROIOLDOLDOLD
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def DrawROIOLDOLDOLD(self, url):
im = cv2.imread(url)
d = 2
d_eclipse = 1
x = self.reference_p0[0]
y = self.reference_p0[1]
h, w = self.ref0.shape[:2]
cv2.rectangle(im,(x-d,y-d),(x+w+2*d,y+h+2*d),(0,0,255),d)
cv2.putText(im,'ref0',(x,y-5),0,0.4,(0,0,255))
x = self.reference_p1[0]
y = self.reference_p1[1]
h, w = self.ref1.shape[:2]
cv2.rectangle(im,(x-d,y-d),(x+w+2*d,y+h+2*d),(0,0,255),d)
cv2.putText(im,'ref1',(x,y-5),0,0.4,(0,0,255))
x = self.reference_p2[0]
y = self.reference_p2[1]
h, w = self.ref2.shape[:2]
cv2.rectangle(im,(x-d,y-d),(x+w+2*d,y+h+2*d),(0,0,255),d)
cv2.putText(im,'ref2',(x,y-5),0,0.4,(0,0,255))
if self.AnalogReadOutEnabled:
for zeiger in self.Analog_Counter:
x, y, w, h = zeiger[1]
cv2.rectangle(im,(x-d,y-d),(x+w+2*d,y+h+2*d),(0,255,0),d)
xct = int(x+w/2)+1
yct = int(y+h/2)+1
cv2.line(im,(xct-5,yct),(xct+5,yct),(0,255,0),1)
cv2.line(im,(xct,yct-5),(xct,yct+5),(0,255,0),1)
cv2.ellipse(im, (xct, yct), (int(w/2)+2*d_eclipse, int(h/2)+2*d_eclipse), 0, 0, 360, (0,255,0), d_eclipse)
cv2.putText(im,zeiger[0],(x,y-5),0,0.4,(0,255,0))
for zeiger in self.Digital_Digit:
x, y, w, h = zeiger[1]
cv2.rectangle(im,(x-d,y-d),(x+w+2*d,y+h+2*d),(0,255,0),d)
cv2.putText(im,zeiger[0],(x,y-5),0,0.4,(0,255,0))
cv2.imwrite('./image_tmp/roi.jpg', im)
示例13: DrawROI
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def DrawROI(self, image_in, image_out='./image_tmp/roi.jpg', draw_ref=False, draw_dig=True, draw_cou=True, ign_ref=-1, ign_dig=-1, ign_cou=-1):
zwimage = str(image_in)
im = cv2.imread(zwimage)
d = 3
d_eclipse = 1
_colour = (255, 0, 0)
if draw_ref:
for i in range(3):
if i != ign_ref:
x, y = self.reference_pos[i]
h, w = self.reference_image[i].shape[:2]
cv2.rectangle(im,(x-d,y-d),(x+w+2*d,y+h+2*d),_colour,d)
cv2.putText(im,self.reference_name[i].replace("./config/", ""),(x,y-5),0,0.4,_colour)
if self.AnalogReadOutEnabled and draw_cou:
for i in range(len(self.Analog_Counter)):
if i != ign_cou:
x, y, w, h = self.Analog_Counter[i][1]
cv2.rectangle(im,(x-d,y-d),(x+w+2*d,y+h+2*d),(0,255,0),d)
xct = int(x+w/2)+1
yct = int(y+h/2)+1
cv2.line(im,(x,yct),(x+w+5,yct),(0,255,0),1)
cv2.line(im,(xct,y),(xct,y+h),(0,255,0),1)
cv2.ellipse(im, (xct, yct), (int(w/2)+2*d_eclipse, int(h/2)+2*d_eclipse), 0, 0, 360, (0,255,0), d_eclipse)
cv2.putText(im,self.Analog_Counter[i][0],(x,y-5),0,0.5,(0,255,0))
if draw_dig:
for i in range(len(self.Digital_Digit)):
if i != ign_dig:
x, y, w, h = self.Digital_Digit[i][1]
cv2.rectangle(im,(x-d,y-d),(x+w+2*d,y+h+2*d),(0,255,0),d)
cv2.putText(im,self.Digital_Digit[i][0],(x,y-5),0,0.5,(0,255,0))
zwname = str(image_out)
cv2.imwrite(zwname, im)
示例14: drawElipse
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def drawElipse(img, center, axes, angle, startAngle, endAngle, color, width):
img = cv2.ellipse(img, center, axes, angle, startAngle, endAngle, color, width, cv2.LINE_AA)
# 四角形の描画
示例15: draw_oval
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import ellipse [as 别名]
def draw_oval(imraw,num_oval):
centers = np.random.randint(0,512,[num_oval,2])
lens = np.random.randint(50,300,[num_oval,2])
total_rots = np.random.randint(-181,181,[num_oval,3])
thick = np.random.randint(10,30,num_oval)
for i in range(num_oval):
cv2.ellipse(imraw,tuple(centers[i]),tuple(lens[i]),total_rots[i][0],total_rots[i][1],total_rots[i][2],0,thick[i])
return imraw