當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。