当前位置: 首页>>代码示例>>Python>>正文


Python cv2.COLOR_BGRA2RGBA属性代码示例

本文整理汇总了Python中cv2.COLOR_BGRA2RGBA属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.COLOR_BGRA2RGBA属性的具体用法?Python cv2.COLOR_BGRA2RGBA怎么用?Python cv2.COLOR_BGRA2RGBA使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cv2的用法示例。


在下文中一共展示了cv2.COLOR_BGRA2RGBA属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [as 别名]
def main():

    jpg_inputs = find_inputs(JPGPATH, types=('.jpg',), prefix=PREFIX)
    tif_inputs = find_inputs(TIFPATH, types=('.tif',), prefix=PREFIX)

    jpg_stats = []
    for f in jpg_inputs:
        img = cv2.imread(f[1])
        mean, std = cv2.meanStdDev(img)
        jpg_stats.append(np.array([mean[::-1] / 255, std[::-1] / 255]))
    jpg_vals = np.mean(jpg_stats, axis=0)
    print(jpg_vals)

    tif_stats = []
    for f in tif_inputs:
        img = cv2.imread(f[1], -1)
        img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA)
        mean, std = cv2.meanStdDev(img)
        tif_stats.append(np.array([mean, std]))
    tif_vals = np.mean(tif_stats, axis=0)
    print(tif_vals) 
开发者ID:rwightman,项目名称:pytorch-planet-amazon,代码行数:23,代码来源:stats.py

示例2: cv2_imshow

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [as 别名]
def cv2_imshow(a):
  """A replacement for cv2.imshow() for use in Jupyter notebooks.

  Args:
    a : np.ndarray. shape (N, M) or (N, M, 1) is an NxM grayscale image. shape
      (N, M, 3) is an NxM BGR color image. shape (N, M, 4) is an NxM BGRA color
      image.
  """
  a = a.clip(0, 255).astype('uint8')
  # cv2 stores colors as BGR; convert to RGB
  if a.ndim == 3:
    if a.shape[2] == 4:
      a = cv2.cvtColor(a, cv2.COLOR_BGRA2RGBA)
    else:
      a = cv2.cvtColor(a, cv2.COLOR_BGR2RGB)
  display.display(PIL.Image.fromarray(a)) 
开发者ID:googlecolab,项目名称:colabtools,代码行数:18,代码来源:__init__.py

示例3: copy_figure_to_clipboard

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [as 别名]
def copy_figure_to_clipboard(fig):
    """
    References:
        https://stackoverflow.com/questions/17676373/python-matplotlib-pyqt-copy-image-to-clipboard
    """
    print('Copying figure %d to the clipboard' % fig.number)
    import matplotlib as mpl
    app = mpl.backends.backend_qt5.qApp
    QtGui = mpl.backends.backend_qt5.QtGui
    im_bgra = render_figure_to_image(fig, transparent=True)
    im_rgba = cv2.cvtColor(im_bgra, cv2.COLOR_BGRA2RGBA)
    im = im_rgba
    QImage = QtGui.QImage
    qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_RGBA8888)
    clipboard = app.clipboard()
    clipboard.setImage(qim)

    # size = fig.canvas.size()
    # width, height = size.width(), size.height()
    # qim = QtGui.QImage(fig.canvas.buffer_rgba(), width, height, QtGui.QImage.Format_ARGB32)

    # QtWidgets = mpl.backends.backend_qt5.QtWidgets
    # pixmap = QtWidgets.QWidget.grab(fig.canvas)
    # clipboard.setPixmap(pixmap) 
开发者ID:Erotemic,项目名称:netharn,代码行数:26,代码来源:mplutil.py

示例4: bgra2rgba

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [as 别名]
def bgra2rgba(img):
    a = alpha(img)
    rgba = cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA)
    if a is not None:
        rgba[:, :, 3] = a
    return rgba


## RGBA to BGRA. 
开发者ID:tody411,项目名称:ColorHistogram,代码行数:11,代码来源:image.py

示例5: save

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [as 别名]
def save(path, img): #TODO: multimethod..?
    if len(img.shape) == 3:
        n_channels = img.shape[-1]
        if n_channels == 4:   # bgra -> rgba
            rgb_img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA)
        elif n_channels == 3: # bgr -> rgb
            rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    elif len(img.shape) == 2: # bw = bw
        rgb_img = img

    imageio.imwrite(path, rgb_img) 
开发者ID:KUR-creative,项目名称:SickZil-Machine,代码行数:13,代码来源:imgio.py

示例6: convert_channel_from_bgra

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [as 别名]
def convert_channel_from_bgra(img, num_channels):
        if num_channels in [0, 1]:
            img = cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
            if num_channels == 1:
                img = img[..., np.newaxis]

            return img

        elif num_channels == 3:  # BGRA => RGB
            return cv2.cvtColor(img, cv2.COLOR_BGRA2RGB)

        elif num_channels in [-1, 4]:  # BGRA => RGBA
            return cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA, dst=img)

        raise ValueError("num_channels must be [-1, 0, 1, 3, 4]") 
开发者ID:sony,项目名称:nnabla,代码行数:17,代码来源:cv2_backend.py

示例7: on_show_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [as 别名]
def on_show_image (self, wnd_name, img):
        pass
        # # cv2 stores colors as BGR; convert to RGB
        # if img.ndim == 3:
        #     if img.shape[2] == 4:
        #         img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGBA)
        #     else:
        #         img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        # img = PIL.Image.fromarray(img)
        # plt.imshow(img)
        # plt.show() 
开发者ID:iperov,项目名称:DeepFaceLab,代码行数:13,代码来源:interact.py

示例8: overlay

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [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)

# 画像周辺のパディングを削除 
开发者ID:leetenki,项目名称:YOLOv2,代码行数:29,代码来源:image_generator.py

示例9: generator

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2RGBA [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') 
开发者ID:airob0t,项目名称:idcardgenerator,代码行数:59,代码来源:gui.py


注:本文中的cv2.COLOR_BGRA2RGBA属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。