本文整理匯總了Python中cv2.CV_AA屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.CV_AA屬性的具體用法?Python cv2.CV_AA怎麽用?Python cv2.CV_AA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類cv2
的用法示例。
在下文中一共展示了cv2.CV_AA屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: draw_projected_box3d
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_projected_box3d(image, qs, color=(255,255,255), thickness=2):
''' Draw 3d bounding box in image
qs: (8,2) array of vertices for the 3d box in following order:
1 -------- 0
/| /|
2 -------- 3 .
| | | |
. 5 -------- 4
|/ |/
6 -------- 7
'''
qs = qs.astype(np.int32)
for k in range(0,4):
#http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html
i,j=k,(k+1)%4
cv2.line(image, (qs[i,0],qs[i,1]), (qs[j,0],qs[j,1]), color, thickness, cv2.CV_AA) # use LINE_AA for opencv3
i,j=k+4,(k+1)%4 + 4
cv2.line(image, (qs[i,0],qs[i,1]), (qs[j,0],qs[j,1]), color, thickness, cv2.CV_AA)
i,j=k,k+4
cv2.line(image, (qs[i,0],qs[i,1]), (qs[j,0],qs[j,1]), color, thickness, cv2.CV_AA)
return image
示例2: draw_projected_box3d
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_projected_box3d(image, qs, color=(255,255,255), thickness=2):
''' Draw 3d bounding box in image
qs: (8,3) array of vertices for the 3d box in following order:
1 -------- 0
/| /|
2 -------- 3 .
| | | |
. 5 -------- 4
|/ |/
6 -------- 7
'''
qs = qs.astype(np.int32)
for k in range(0,4):
# Ref: http://docs.enthought.com/mayavi/mayavi/auto/mlab_helper_functions.html
i,j=k,(k+1)%4
# use LINE_AA for opencv3
cv2.line(image, (qs[i,0],qs[i,1]), (qs[j,0],qs[j,1]), color, thickness, cv2.CV_AA)
i,j=k+4,(k+1)%4 + 4
cv2.line(image, (qs[i,0],qs[i,1]), (qs[j,0],qs[j,1]), color, thickness, cv2.CV_AA)
i,j=k,k+4
cv2.line(image, (qs[i,0],qs[i,1]), (qs[j,0],qs[j,1]), color, thickness, cv2.CV_AA)
return image
示例3: draw_mask
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_mask(im, mask, alpha=0.5, color=None, show_border=True,border_thick=1):
"""
Overlay a mask on top of the image.
Args:
im: a 3-channel uint8 image in BGR
mask: a binary 1-channel image of the same size
color: if None, will choose automatically
"""
if color is None:
color = PALETTE_RGB[np.random.choice(len(PALETTE_RGB))][::-1]
im = np.where(np.squeeze(np.repeat((mask > 0)[:, :, None], 3, axis=2)),
im * (1 - alpha) + color * alpha, im)
if show_border:
if cv2.__version__.startswith("2"):
contours, _ = cv2.findContours(mask.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
else: # cv 3
_,contours, _ = cv2.findContours(mask.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(im, contours, -1, (255,255,255), border_thick, lineType=cv2.CV_AA)
im = im.astype('uint8')
return im
示例4: draw_result
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_result(self, img, result): #輸出結果
print("hell")
print(len(result))
for i in range(len(result)):
x = int(result[i][1])
y = int(result[i][2])
w = int(result[i][3] / 2)
h = int(result[i][4] / 2)
cv2.rectangle(img, (x - w, y - h), (x + w, y + h), (0, 255, 0), 2)
cv2.rectangle(img, (x - w, y - h - 20),
(x + w, y - h), (125, 125, 125), -1)
lineType = cv2.LINE_AA if cv2.__version__ > '3' else cv2.CV_AA
cv2.putText(
img, result[i][0] + ' : %.2f' % result[i][5],
(x - w + 5, y - h - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
(0, 0, 0), 1, lineType)
示例5: vis_mask
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def vis_mask(img, mask, col, alpha=0.4, show_border=True, border_thick=1):
"""Visualizes a single binary mask."""
img = img.astype(np.float32)
idx = np.nonzero(mask)
img[idx[0], idx[1], :] *= 1.0 - alpha
img[idx[0], idx[1], :] += alpha * col
if show_border:
contours, _ = cv2.findContours(
mask.copy(), cv2.RETR_CCOMP, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(img, contours, -1, _WHITE, border_thick,
cv2.CV_AA if cv2.__version__.startswith('2') else
cv2.LINE_AA)
return img.astype(np.uint8)
示例6: vis_class
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def vis_class(img, pos, class_str, font_scale=0.35):
"""Visualizes the class."""
x0, y0 = int(pos[0]), int(pos[1])
# Compute text size.
txt = class_str
font = cv2.FONT_HERSHEY_SIMPLEX
((txt_w, txt_h), _) = cv2.getTextSize(txt, font, font_scale, 1)
# Place text background.
back_tl = x0, y0 - int(1.3 * txt_h)
back_br = x0 + txt_w, y0
cv2.rectangle(img, back_tl, back_br, _GREEN, -1)
# Show text.
txt_tl = x0, y0 - int(0.3 * txt_h)
cv2.putText(img, txt, txt_tl, font, font_scale, _GRAY,
lineType=cv2.CV_AA if cv2.__version__.startswith('2') else
cv2.LINE_AA)
return img
示例7: draw_result
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_result(self, img, result):
for i in range(len(result)):
x = int(result[i][1])
y = int(result[i][2])
w = int(result[i][3] / 2)
h = int(result[i][4] / 2)
cv2.rectangle(img, (x - w, y - h), (x + w, y + h), (0, 255, 0), 2)
cv2.rectangle(img, (x - w, y - h - 20),
(x + w, y - h), (125, 125, 125), -1)
lineType = cv2.LINE_AA if cv2.__version__ > '3' else cv2.CV_AA
cv2.putText(
img, result[i][0] + ' : %.2f' % result[i][5],
(x - w + 5, y - h - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5,
(0, 0, 0), 1, lineType)
示例8: display_shadow_text
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def display_shadow_text(img,x,y,text):
"""
Displays with a grey shadow at point x,y
"""
text_color = (255,255,255) #color as (B,G,R)
text_shadow = (0,0,0)
text_pos = (x,y)
shadow_pos = (x+1,y+1)
cv2.putText(img, text, shadow_pos, cv2.FONT_HERSHEY_PLAIN, 1.25, text_shadow, thickness=1, lineType=cv2.CV_AA)
cv2.putText(img, text, text_pos, cv2.FONT_HERSHEY_PLAIN, 1.25, text_color, thickness=1, lineType=cv2.CV_AA)
return img
示例9: mark_point
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def mark_point(img, point, circle=False, color=100, radius=20):
""" 調試用的: 標記一個點 """
x, y = point
# cv2.rectangle(img, (x, y), (x+10, y+10), 255, 1, lineType=cv2.CV_AA)
if circle:
cv2.circle(img, (x, y), radius, 255, thickness=2)
cv2.line(img, (x - radius, y), (x + radius, y), color) # x line
cv2.line(img, (x, y - radius), (x, y + radius), color) # y line
return img
示例10: draw_result
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_result(img, result):
for i in range(len(result)):
x = int(result[i][1])
y = int(result[i][2])
w = int(result[i][3] / 2)
h = int(result[i][4] / 2)
cv2.rectangle(img, (x - w, y - h), (x + w, y + h), (0, 255, 0), 2)
cv2.rectangle(img, (x - w, y - h - 20), (x + w, y - h), (125, 125, 125), -1)
cv2.putText(img, result[i][0] + ' : %.2f' % result[i][5], (x - w + 5, y - h - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1, cv2.CV_AA)
示例11: drawCross
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def drawCross(img, center, r, g, b):
'''
Draws a cross a the specified X,Y coordinates with color RGB
'''
d = 5
t = 2
color = (r, g, b)
ctrx = center[0]
ctry = center[1]
cv2.line(img, (ctrx - d, ctry - d), (ctrx + d, ctry + d), color, t, cv2.CV_AA)
cv2.line(img, (ctrx + d, ctry - d), (ctrx - d, ctry + d), color, t, cv2.CV_AA)
示例12: draw_rois
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_rois(im, all_rois):
for roi in all_rois:
x,y = roi.offset
y += roi.rectangle[3]/2
x += roi.rectangle[2]/2
cv2.putText(im, str(roi.idx), (x,y), cv2.FONT_HERSHEY_COMPLEX_SMALL, 1, (255,255,0))
black_colour,roi_colour = (0, 0,0), (0, 255,0)
cv2.drawContours(im,[roi.polygon],-1, black_colour, 3, cv2.CV_AA)
cv2.drawContours(im,[roi.polygon],-1, roi_colour, 1, cv2.CV_AA)
示例13: draw_lines
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_lines(image, facts, contour_num):
for i in range(contour_num):
for fact in facts['Contour' + str(i)]:
for line in fact.about:
cv2.line(image, line.point1, line.point2, (0, 255, 0), 2, cv2.CV_AA)
示例14: draw_str
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def draw_str(dst, pt, s):
x = pt[0]
y = pt[1]
cv2.putText(dst, s, (x+1, y+1), cv2.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 0), thickness = 2, lineType=cv2.CV_AA)
cv2.putText(dst, s, (x, y), cv2.FONT_HERSHEY_PLAIN, 1.0, (255, 255, 255), lineType=cv2.CV_AA)
示例15: defocus_kernel
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import CV_AA [as 別名]
def defocus_kernel(d, sz=65):
kern = np.zeros((sz, sz), np.uint8)
cv2.circle(kern, (sz, sz), d, 255, -1, cv2.CV_AA, shift=1)
kern = np.float32(kern) / 255.0
return kern