当前位置: 首页>>代码示例>>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;未经允许,请勿转载。