本文整理汇总了Python中cv2.COLOR_RGBA2BGRA属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.COLOR_RGBA2BGRA属性的具体用法?Python cv2.COLOR_RGBA2BGRA怎么用?Python cv2.COLOR_RGBA2BGRA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.COLOR_RGBA2BGRA属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SkipIteration
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_RGBA2BGRA [as 别名]
def SkipIteration(I1, I2, saveQuality, out1, out2) :
I1RGBA = cv2.cvtColor(np.array(I1), cv2.COLOR_RGBA2BGRA)
I2RGBA = cv2.cvtColor(np.array(I2), cv2.COLOR_RGBA2BGRA)
mask1 = np.ones((I1RGBA.shape[0], I1RGBA.shape[1])) * 100
mask2 = np.ones((I2RGBA.shape[0], I2RGBA.shape[1])) * 100
I1RGBA[:, :, 3] = mask1
I2RGBA[:, :, 3] = mask2
ratio1 = max(max(I1RGBA.shape[0], I1RGBA.shape[1]) / float(saveQuality), 1)
I1RGBA =imresize(I1RGBA, (int(I1RGBA.shape[0] / ratio1), int(I1RGBA.shape[1] / ratio1)))
ratio2 = max(I2RGBA.shape[0], I2RGBA.shape[1]) / float(saveQuality)
I2RGBA =imresize(I2RGBA, (int(I2RGBA.shape[0] / ratio2), int(I2RGBA.shape[1] / ratio2)))
cv2.imwrite(out1, I1RGBA)
cv2.imwrite(out2, I2RGBA)
## Blur the mask
示例2: rgba2bgra
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_RGBA2BGRA [as 别名]
def rgba2bgra(img):
a = alpha(img)
bgra = cv2.cvtColor(img, cv2.COLOR_RGBA2BGRA)
bgra[:, :, 3] = a
return bgra
## RGB to BGR.
示例3: imsave
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_RGBA2BGRA [as 别名]
def imsave(self, path, img, channel_first=False, as_uint16=False, auto_scale=True):
"""
Save image by cv2 module.
Args:
path (str): output filename
img (numpy.ndarray): Image array to save. Image shape is considered as (height, width, channel) by default.
channel_first:
This argument specifies the shape of img is whether (height, width, channel) or (channel, height, width).
Default value is False, which means the img shape is (height, width, channel)
as_uint16 (bool):
If True, save image as uint16.
auto_scale (bool) :
Whether upscale pixel values or not.
If you want to save float image, this argument must be True.
In cv2 backend, all below are supported.
- float ([0, 1]) to uint8 ([0, 255]) (if img.dtype==float and auto_scale==True and as_uint16==False)
- float to uint16 ([0, 65535]) (if img.dtype==float and auto_scale==True and as_uint16==True)
- uint8 to uint16 are supported (if img.dtype==np.uint8 and auto_scale==True and as_uint16==True)
"""
img = _imsave_before(img, channel_first, auto_scale)
if auto_scale:
img = upscale_pixel_intensity(img, as_uint16)
img = check_type_and_cast_if_necessary(img, as_uint16)
# revert channel order to opencv`s one.
if len(img.shape) == 3:
if img.shape[-1] == 3:
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
elif img.shape[-1] == 4:
img = cv2.cvtColor(img, cv2.COLOR_RGBA2BGRA)
cv2.imwrite(path, img)
示例4: create_image_summary
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_RGBA2BGRA [as 别名]
def create_image_summary(name, val):
"""
Args:
name(str):
val(np.ndarray): 4D tensor of NHWC. assume RGB if C==3.
Can be either float or uint8. Range has to be [0,255].
Returns:
tf.Summary:
"""
assert isinstance(name, six.string_types), type(name)
n, h, w, c = val.shape
val = val.astype('uint8')
s = tf.Summary()
imparams = [cv2.IMWRITE_PNG_COMPRESSION, 9]
for k in range(n):
arr = val[k]
# CV2 will only write correctly in BGR chanel order
if c == 3:
arr = cv2.cvtColor(arr, cv2.COLOR_RGB2BGR)
elif c == 4:
arr = cv2.cvtColor(arr, cv2.COLOR_RGBA2BGRA)
tag = name if n == 1 else '{}/{}'.format(name, k)
retval, img_str = cv2.imencode('.png', arr, imparams)
if not retval:
# Encoding has failed.
continue
img_str = img_str.tostring()
img = tf.Summary.Image()
img.height = h
img.width = w
# 1 - grayscale 3 - RGB 4 - RGBA
img.colorspace = c
img.encoded_image_string = img_str
s.value.add(tag=tag, image=img)
return s
示例5: overlay
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_RGBA2BGRA [as 别名]
def overlay(src_image, overlay_image, pos_x, pos_y):
# オーバレイ画像のサイズを取得
ol_height, ol_width = overlay_image.shape[:2]
# OpenCVの画像データをPILに変換
# BGRAからRGBAへ変換
src_image_RGBA = cv2.cvtColor(src_image, cv2.COLOR_BGR2RGB)
overlay_image_RGBA = cv2.cvtColor(overlay_image, cv2.COLOR_BGRA2RGBA)
# PILに変換
src_image_PIL=Image.fromarray(src_image_RGBA)
overlay_image_PIL=Image.fromarray(overlay_image_RGBA)
# 合成のため、RGBAモードに変更
src_image_PIL = src_image_PIL.convert('RGBA')
overlay_image_PIL = overlay_image_PIL.convert('RGBA')
# 同じ大きさの透過キャンパスを用意
tmp = Image.new('RGBA', src_image_PIL.size, (255, 255,255, 0))
# 用意したキャンパスに上書き
tmp.paste(overlay_image_PIL, (pos_x, pos_y), overlay_image_PIL)
# オリジナルとキャンパスを合成して保存
result = Image.alpha_composite(src_image_PIL, tmp)
return cv2.cvtColor(np.asarray(result), cv2.COLOR_RGBA2BGRA)
# 画像周辺のパディングを削除
示例6: generator
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_RGBA2BGRA [as 别名]
def generator():
global ename, esex, enation, eyear, emon, eday, eaddr, eidn, eorg, elife, ebgvar
name = ename.get()
sex = esex.get()
nation = enation.get()
year = eyear.get()
mon = emon.get()
day = eday.get()
org = eorg.get()
life = elife.get()
addr = eaddr.get()
idn = eidn.get()
fname = askopenfilename(initialdir=os.getcwd(), title=u'选择头像')
# print fname
im = PImage.open(os.path.join(base_dir, 'empty.png'))
avatar = PImage.open(fname) # 500x670
name_font = ImageFont.truetype(os.path.join(base_dir, 'hei.ttf'), 72)
other_font = ImageFont.truetype(os.path.join(base_dir, 'hei.ttf'), 60)
bdate_font = ImageFont.truetype(os.path.join(base_dir, 'fzhei.ttf'), 60)
id_font = ImageFont.truetype(os.path.join(base_dir, 'ocrb10bt.ttf'), 72)
draw = ImageDraw.Draw(im)
draw.text((630, 690), name, fill=(0, 0, 0), font=name_font)
draw.text((630, 840), sex, fill=(0, 0, 0), font=other_font)
draw.text((1030, 840), nation, fill=(0, 0, 0), font=other_font)
draw.text((630, 980), year, fill=(0, 0, 0), font=bdate_font)
draw.text((950, 980), mon, fill=(0, 0, 0), font=bdate_font)
draw.text((1150, 980), day, fill=(0, 0, 0), font=bdate_font)
start = 0
loc = 1120
while start + 11 < len(addr):
draw.text((630, loc), addr[start:start + 11], fill=(0, 0, 0), font=other_font)
start += 11
loc += 100
draw.text((630, loc), addr[start:], fill=(0, 0, 0), font=other_font)
draw.text((950, 1475), idn, fill=(0, 0, 0), font=id_font)
draw.text((1050, 2750), org, fill=(0, 0, 0), font=other_font)
draw.text((1050, 2895), life, fill=(0, 0, 0), font=other_font)
if ebgvar.get():
avatar = cv2.cvtColor(np.asarray(avatar), cv2.COLOR_RGBA2BGRA)
im = cv2.cvtColor(np.asarray(im), cv2.COLOR_RGBA2BGRA)
im = changeBackground(avatar, im, (500, 670), (690, 1500))
im = PImage.fromarray(cv2.cvtColor(im, cv2.COLOR_BGRA2RGBA))
else:
avatar = avatar.resize((500, 670))
avatar = avatar.convert('RGBA')
im.paste(avatar, (1500, 690), mask=avatar)
#im = paste(avatar, im, (500, 670), (690, 1500))
im.save('color.png')
im.convert('L').save('bw.png')
showinfo(u'成功', u'文件已生成到目录下,黑白bw.png和彩色color.png')