當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.COLOR_BGR2BGRA屬性代碼示例

本文整理匯總了Python中cv2.COLOR_BGR2BGRA屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.COLOR_BGR2BGRA屬性的具體用法?Python cv2.COLOR_BGR2BGRA怎麽用?Python cv2.COLOR_BGR2BGRA使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在cv2的用法示例。


在下文中一共展示了cv2.COLOR_BGR2BGRA屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: enable_alpha

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def enable_alpha(self):
        if self.image_channels < 4:
            with_alpha = np.zeros((self.size[1], self.size[0], 4), self.image.dtype)
            if self.image_channels == 3:
                cv2.cvtColor(self.image, cv2.COLOR_BGR2BGRA, with_alpha)
            else:
                cv2.cvtColor(self.image, cv2.COLOR_GRAY2BGRA, with_alpha)
            self.image = with_alpha 
開發者ID:thumbor,項目名稱:opencv-engine,代碼行數:10,代碼來源:engine_cv3.py

示例2: to_alpha

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def to_alpha(logo):
    if has_alpha(logo):
        return logo

    if is_gray(logo):
        return cv2.cvtColor(logo, cv2.COLOR_GRAY2BGRA)
    else:
        return cv2.cvtColor(logo, cv2.COLOR_BGR2BGRA) 
開發者ID:ftramer,項目名稱:ad-versarial,代碼行數:10,代碼來源:utils.py

示例3: HideStringIntoPng_8bit1pixel

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def HideStringIntoPng_8bit1pixel(img,DataArray,seed = 0):
    # saving points where data is hidden
    DataHidenX = []
    DataHidenY = []
    DataHidenXY = []
    if(seed != 0):
        rd.seed(seed)
    h , w, c = img.shape
    if c <= 3:
        img = cv2.cvtColor(img,cv2.COLOR_BGR2BGRA)
    # hiding data into image
    counter = len(DataArray)
    i = 0
    while i < counter:
        x = rd.randint(0,h -1)
        y = rd.randint(0,w - 1)
        while (x,y) in DataHidenXY:
            x = rd.randint(0,h -1)
            y = rd.randint(0,w - 1)
        DataHidenXY.append((x,y))
        DataHidenX.append(x)
        DataHidenY.append(y)
        img[x][y][0] |= 0x03
        img[x][y][0] &= (0xfc | DataArray[i])
        img[x][y][1] |= 0x03
        img[x][y][1] &= (0xfc | DataArray[i + 1])
        img[x][y][2] |= 0x03
        img[x][y][2] &= (0xfc | DataArray[i + 2])
        img[x][y][3] |= 0x03
        img[x][y][3] &= (0xfc | DataArray[i + 3])
        i += 4

    return DataHidenX,DataHidenY,img 
開發者ID:immortal3,項目名稱:Hidden-Eye,代碼行數:35,代碼來源:EnStrToPng.py

示例4: HidePdfintoPng

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def HidePdfintoPng(img,DataArray,seed = 0):
    # saving points where data is hidden
    if(seed != 0):
        rd.seed(seed)
    h , w, c = img.shape
    if c <= 3:
        img = cv2.cvtColor(img,cv2.COLOR_BGR2BGRA)
    # hiding data into image
    counter = len(DataArray)
    print (counter)
    i = 0
    x = 0
    y = 0
    while i < counter:
        #print (i)
        img[x][y][0] |= 0x03
        img[x][y][0] &= (0xfc | DataArray[i])
        img[x][y][1] |= 0x03
        img[x][y][1] &= (0xfc | DataArray[i + 1])
        img[x][y][2] |= 0x03
        img[x][y][2] &= (0xfc | DataArray[i + 2])
        img[x][y][3] |= 0x03
        img[x][y][3] &= (0xfc | DataArray[i + 3])
        i += 4
        if(x == h -1):
            break
        if(y == w -1):
            x += 1
            y = 0
        y += 1

    return x,y-1,img 
開發者ID:immortal3,項目名稱:Hidden-Eye,代碼行數:34,代碼來源:EnPdfToPng.py

示例5: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def __init__(self, parent, minimap_iterator, output_file, output_flags):
        super(PUBGISWorkerThread, self).__init__(parent)
        self.parent = parent
        self.minimap_iterator = minimap_iterator
        self.output_file = output_file
        self.full_positions = []
        self.timestamps = []
        self.base_map_alpha = cv2.cvtColor(PUBGISMatch.full_map, cv2.COLOR_BGR2BGRA)
        self.preview_map = cv2.cvtColor(PUBGISMatch.full_map, cv2.COLOR_BGR2BGRA)
        self.output_flags = output_flags 
開發者ID:andrewzwicky,項目名稱:PUBGIS,代碼行數:12,代碼來源:gui.py

示例6: overlay

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def overlay(image, layer):
    if (len(layer.shape) == 2):
        layer = cv2.cvtColor(layer, cv2.COLOR_GRAY2BGR)
    
    image = cv2.cvtColor(image, cv2.COLOR_BGR2BGRA)
    layer = cv2.cvtColor(layer, cv2.COLOR_BGR2BGRA)

    layer[np.where((layer == [0,0,0,255]).all(axis=2))] = const.BACKGROUND_COLOR + [255]
    layer[np.where((layer == [255,255,255,255]).all(axis=2))] = const.SEGMENTATION_COLOR + [255]
    layer = cv2.addWeighted(image, 0.6, layer, 0.4, 0)
    return layer 
開發者ID:arthurflor23,項目名稱:surface-crack-detection,代碼行數:13,代碼來源:image.py

示例7: spatter

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def spatter(x, severity=1):
    c = [(0.65, 0.3, 4, 0.69, 0.6, 0),
         (0.65, 0.3, 3, 0.68, 0.6, 0),
         (0.65, 0.3, 2, 0.68, 0.5, 0),
         (0.65, 0.3, 1, 0.65, 1.5, 1),
         (0.67, 0.4, 1, 0.65, 1.5, 1)][severity - 1]
    x = np.array(x, dtype=np.float32) / 255.

    liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1])

    liquid_layer = gaussian(liquid_layer, sigma=c[2])
    liquid_layer[liquid_layer < c[3]] = 0
    if c[5] == 0:
        liquid_layer = (liquid_layer * 255).astype(np.uint8)
        dist = 255 - cv2.Canny(liquid_layer, 50, 150)
        dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5)
        _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC)
        dist = cv2.blur(dist, (3, 3)).astype(np.uint8)
        dist = cv2.equalizeHist(dist)
        ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]])
        dist = cv2.filter2D(dist, cv2.CV_8U, ker)
        dist = cv2.blur(dist, (3, 3)).astype(np.float32)

        m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA)
        m /= np.max(m, axis=(0, 1))
        m *= c[4]

        # water is pale turqouise
        color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1])), axis=2)

        color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA)
        x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA)

        return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255
    else:
        m = np.where(liquid_layer > c[3], 1, 0)
        m = gaussian(m.astype(np.float32), sigma=c[4])
        m[m < 0.8] = 0

        # mud brown
        color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]),
                                42 / 255. * np.ones_like(x[..., :1]),
                                20 / 255. * np.ones_like(x[..., :1])), axis=2)

        color *= m[..., np.newaxis]
        x *= (1 - m[..., np.newaxis])

        return np.clip(x + color, 0, 1) * 255 
開發者ID:hendrycks,項目名稱:robustness,代碼行數:52,代碼來源:corruptions.py

示例8: spatter

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def spatter(x, severity=1):
    c = [(0.65, 0.3, 4, 0.69, 0.6, 0),
         (0.65, 0.3, 3, 0.68, 0.6, 0),
         (0.65, 0.3, 2, 0.68, 0.5, 0),
         (0.65, 0.3, 1, 0.65, 1.5, 1),
         (0.67, 0.4, 1, 0.65, 1.5, 1)][severity - 1]
    x = np.array(x, dtype=np.float32) / 255.

    liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1])

    liquid_layer = gaussian(liquid_layer, sigma=c[2])
    liquid_layer[liquid_layer < c[3]] = 0
    if c[5] == 0:
        liquid_layer = (liquid_layer * 255).astype(np.uint8)
        dist = 255 - cv2.Canny(liquid_layer, 50, 150)
        dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5)
        _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC)
        dist = cv2.blur(dist, (3, 3)).astype(np.uint8)
        dist = cv2.equalizeHist(dist)
        #     ker = np.array([[-1,-2,-3],[-2,0,0],[-3,0,1]], dtype=np.float32)
        #     ker -= np.mean(ker)
        ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]])
        dist = cv2.filter2D(dist, cv2.CV_8U, ker)
        dist = cv2.blur(dist, (3, 3)).astype(np.float32)

        m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA)
        m /= np.max(m, axis=(0, 1))
        m *= c[4]

        # water is pale turqouise
        color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1])), axis=2)

        color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA)
        x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA)

        return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255
    else:
        m = np.where(liquid_layer > c[3], 1, 0)
        m = gaussian(m.astype(np.float32), sigma=c[4])
        m[m < 0.8] = 0
        #         m = np.abs(m) ** (1/c[4])

        # mud brown
        color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]),
                                42 / 255. * np.ones_like(x[..., :1]),
                                20 / 255. * np.ones_like(x[..., :1])), axis=2)

        color *= m[..., np.newaxis]
        x *= (1 - m[..., np.newaxis])

        return np.clip(x + color, 0, 1) * 255 
開發者ID:hendrycks,項目名稱:robustness,代碼行數:55,代碼來源:make_imagenet_c.py

示例9: spatter

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def spatter(x, severity=1):
    c = [(0.62,0.1,0.7,0.7,0.5,0),
         (0.65,0.1,0.8,0.7,0.5,0),
         (0.65,0.3,1,0.69,0.5,0),
         (0.65,0.1,0.7,0.69,0.6,1),
         (0.65,0.1,0.5,0.68,0.6,1)][severity - 1]
    x = np.array(x, dtype=np.float32) / 255.

    liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1])

    liquid_layer = gaussian(liquid_layer, sigma=c[2])
    liquid_layer[liquid_layer < c[3]] = 0
    if c[5] == 0:
        liquid_layer = (liquid_layer * 255).astype(np.uint8)
        dist = 255 - cv2.Canny(liquid_layer, 50, 150)
        dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5)
        _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC)
        dist = cv2.blur(dist, (3, 3)).astype(np.uint8)
        dist = cv2.equalizeHist(dist)
        #     ker = np.array([[-1,-2,-3],[-2,0,0],[-3,0,1]], dtype=np.float32)
        #     ker -= np.mean(ker)
        ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]])
        dist = cv2.filter2D(dist, cv2.CV_8U, ker)
        dist = cv2.blur(dist, (3, 3)).astype(np.float32)

        m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA)
        m /= np.max(m, axis=(0, 1))
        m *= c[4]

        # water is pale turqouise
        color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1])), axis=2)

        color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA)
        x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA)

        return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255
    else:
        m = np.where(liquid_layer > c[3], 1, 0)
        m = gaussian(m.astype(np.float32), sigma=c[4])
        m[m < 0.8] = 0
        #         m = np.abs(m) ** (1/c[4])

        # mud brown
        color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]),
                                42 / 255. * np.ones_like(x[..., :1]),
                                20 / 255. * np.ones_like(x[..., :1])), axis=2)

        color *= m[..., np.newaxis]
        x *= (1 - m[..., np.newaxis])

        return np.clip(x + color, 0, 1) * 255 
開發者ID:hendrycks,項目名稱:robustness,代碼行數:55,代碼來源:make_cifar_c.py

示例10: spatter

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def spatter(x, severity=1):
    c = [(0.62,0.1,0.7,0.7,0.6,0),
         (0.65,0.1,0.8,0.7,0.6,0),
         (0.65,0.3,1,0.69,0.6,0),
         (0.65,0.1,0.7,0.68,0.6,1),
         (0.65,0.1,0.5,0.67,0.6,1)][severity - 1]
    x = np.array(x, dtype=np.float32) / 255.

    liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1])

    liquid_layer = gaussian(liquid_layer, sigma=c[2])
    liquid_layer[liquid_layer < c[3]] = 0
    if c[5] == 0:
        liquid_layer = (liquid_layer * 255).astype(np.uint8)
        dist = 255 - cv2.Canny(liquid_layer, 50, 150)
        dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5)
        _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC)
        dist = cv2.blur(dist, (3, 3)).astype(np.uint8)
        dist = cv2.equalizeHist(dist)
        #     ker = np.array([[-1,-2,-3],[-2,0,0],[-3,0,1]], dtype=np.float32)
        #     ker -= np.mean(ker)
        ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]])
        dist = cv2.filter2D(dist, cv2.CV_8U, ker)
        dist = cv2.blur(dist, (3, 3)).astype(np.float32)

        m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA)
        m /= np.max(m, axis=(0, 1))
        m *= c[4]

        # water is pale turqouise
        color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1])), axis=2)

        color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA)
        x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA)

        return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255
    else:
        m = np.where(liquid_layer > c[3], 1, 0)
        m = gaussian(m.astype(np.float32), sigma=c[4])
        m[m < 0.8] = 0
        #         m = np.abs(m) ** (1/c[4])

        # mud brown
        color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]),
                                42 / 255. * np.ones_like(x[..., :1]),
                                20 / 255. * np.ones_like(x[..., :1])), axis=2)

        color *= m[..., np.newaxis]
        x *= (1 - m[..., np.newaxis])

        return np.clip(x + color, 0, 1) * 255 
開發者ID:hendrycks,項目名稱:robustness,代碼行數:55,代碼來源:make_tinyimagenet_c.py

示例11: spatter

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import COLOR_BGR2BGRA [as 別名]
def spatter(x, severity=1):
    c = [(0.65,0.3,4,0.69,0.9,0),
         (0.65,0.3,3.5,0.68,0.9,0),
         (0.65,0.3,3,0.68,0.8,0),
         (0.65,0.3,1.2,0.65,1.8,1),
         (0.67,0.4,1.2,0.65,1.8,1)][severity - 1]
    x = np.array(x, dtype=np.float32) / 255.

    liquid_layer = np.random.normal(size=x.shape[:2], loc=c[0], scale=c[1])

    liquid_layer = gaussian(liquid_layer, sigma=c[2])
    liquid_layer[liquid_layer < c[3]] = 0
    if c[5] == 0:
        liquid_layer = (liquid_layer * 255).astype(np.uint8)
        dist = 255 - cv2.Canny(liquid_layer, 50, 150)
        dist = cv2.distanceTransform(dist, cv2.DIST_L2, 5)
        _, dist = cv2.threshold(dist, 20, 20, cv2.THRESH_TRUNC)
        dist = cv2.blur(dist, (3, 3)).astype(np.uint8)
        dist = cv2.equalizeHist(dist)
        #     ker = np.array([[-1,-2,-3],[-2,0,0],[-3,0,1]], dtype=np.float32)
        #     ker -= np.mean(ker)
        ker = np.array([[-2, -1, 0], [-1, 1, 1], [0, 1, 2]])
        dist = cv2.filter2D(dist, cv2.CV_8U, ker)
        dist = cv2.blur(dist, (3, 3)).astype(np.float32)

        m = cv2.cvtColor(liquid_layer * dist, cv2.COLOR_GRAY2BGRA)
        m /= np.max(m, axis=(0, 1))
        m *= c[4]

        # water is pale turqouise
        color = np.concatenate((175 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1]),
                                238 / 255. * np.ones_like(m[..., :1])), axis=2)

        color = cv2.cvtColor(color, cv2.COLOR_BGR2BGRA)
        x = cv2.cvtColor(x, cv2.COLOR_BGR2BGRA)

        return cv2.cvtColor(np.clip(x + m * color, 0, 1), cv2.COLOR_BGRA2BGR) * 255
    else:
        m = np.where(liquid_layer > c[3], 1, 0)
        m = gaussian(m.astype(np.float32), sigma=c[4])
        m[m < 0.8] = 0
        #         m = np.abs(m) ** (1/c[4])

        # mud brown
        color = np.concatenate((63 / 255. * np.ones_like(x[..., :1]),
                                42 / 255. * np.ones_like(x[..., :1]),
                                20 / 255. * np.ones_like(x[..., :1])), axis=2)

        color *= m[..., np.newaxis]
        x *= (1 - m[..., np.newaxis])

        return np.clip(x + color, 0, 1) * 255 
開發者ID:hendrycks,項目名稱:robustness,代碼行數:55,代碼來源:make_imagenet_c_inception.py


注:本文中的cv2.COLOR_BGR2BGRA屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。