本文整理汇总了Python中cv2.COLOR_BGRA2BGR属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.COLOR_BGRA2BGR属性的具体用法?Python cv2.COLOR_BGRA2BGR怎么用?Python cv2.COLOR_BGRA2BGR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.COLOR_BGRA2BGR属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_image_and_mask
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [as 别名]
def get_image_and_mask(img_location, gray_flag):
# Load image from file with alpha channel (UNCHANGED flag). If an alpha
# channel does not exist, just return the base image.
img = cv2.imread(img_location, cv2.IMREAD_UNCHANGED)
if img.shape[2] <= 3:
return img, None
# Create an alpha channel matrix with values between 0-255. Then
# threshold the alpha channel to create a binary mask.
channels = cv2.split(img)
mask = np.array(channels[3])
_, mask = cv2.threshold(mask, 250, 255, cv2.THRESH_BINARY)
# Convert image and mask to grayscale or BGR based on input flag.
if gray_flag:
img = cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
else:
img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
mask = cv2.cvtColor(mask, cv2.COLOR_GRAY2BGR)
return img, mask
# Resize an image and mask based on an input scale ratio.
示例2: channel3img
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [as 别名]
def channel3img(img):
'''
If img is 3-channel img(h,w,3) then this is identity funcion.
If img is grayscale img(h,w) then convert 3-channel img.
If img is bgra img, then CONVERT to bgr(TODO: warning required!)
else return None
'''
if len(img.shape) == 2: # if grayscale image, convert.
return cv2.cvtColor(img, cv2.COLOR_GRAY2RGB)
elif len(img.shape) == 3:
_,_,c = img.shape
if c == 3: # BGR(RGB)
return img
elif c == 4: # BGRA(RGBA)
return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
#NOTE: warning: no alpha!
#else: None
#---------------------------------------------------------------------------------
# for segmap
示例3: grab_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [as 别名]
def grab_image(monitor, resizeTo=None):
img = cv2.cvtColor(np.array(sct.grab(monitor)), cv2.COLOR_BGRA2BGR)
if resizeTo is not None:
return cv2.resize(img, resizeTo)
return img
示例4: to_bgr
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [as 别名]
def to_bgr(img):
if has_alpha(img):
return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
elif is_gray(img):
return cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
else:
return img
示例5: window_full_shot
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [as 别名]
def window_full_shot(self, file_name=None, gray=0):
"""
窗口截图
:param file_name=None: 截图文件的保存名称
:param gray=0: 是否返回灰度图像,0:返回BGR彩色图像,其他:返回灰度黑白图像
:return: file_name为空则返回RGB数据
"""
try:
if (not hasattr(self, 'memdc')):
self.init_mem()
if self.client == 0:
self.memdc.BitBlt((0, 0), (self._client_w, self._client_h), self.srcdc,
(self._border_l, self._border_t), win32con.SRCCOPY)
else:
self.memdc.BitBlt((0, -35), (self._client_w, self._client_h), self.srcdc,
(self._border_l, self._border_t), win32con.SRCCOPY)
if file_name != None:
self.bmp.SaveBitmapFile(self.memdc, file_name)
return
else:
signedIntsArray = self.bmp.GetBitmapBits(True)
img = np.fromstring(signedIntsArray, dtype='uint8')
img.shape = (self._client_h, self._client_w, 4)
#cv2.imshow("image", cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY))
# cv2.waitKey(0)
if gray == 0:
return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
else:
return cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)
except Exception:
self.init_mem()
logging.warning('window_full_shot执行失败')
a = traceback.format_exc()
logging.warning(a)
示例6: __annotate_minimap
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [as 别名]
def __annotate_minimap(self, minimap, color_diff, match_val):
ind_mask_minimap = np.copy(minimap)
res1 = cv2.bitwise_and(ind_mask_minimap, ind_mask_minimap, mask=self.masks[0])
ind_area_mask_minimap = np.copy(minimap)
res2 = cv2.bitwise_and(ind_area_mask_minimap, ind_area_mask_minimap, mask=self.masks[1])
cv2.putText(minimap, f"{int(color_diff)}", (25, 25), FONT, FONT_SIZE, WHITE())
cv2.putText(minimap, f"{match_val:.2f}", (25, 60), FONT, FONT_SIZE, WHITE())
cv2.putText(minimap, f"{self.missed_frames:.2f}", (25, 95), FONT, FONT_SIZE, WHITE())
minimap = cv2.cvtColor(minimap, cv2.COLOR_BGRA2BGR)
res1 = cv2.cvtColor(res1, cv2.COLOR_BGRA2BGR)
res2 = cv2.cvtColor(res2, cv2.COLOR_BGRA2BGR)
return np.concatenate((res1, res2, minimap), axis=1)
示例7: spatter
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [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
示例8: spatter
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [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
示例9: spatter
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [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
示例10: spatter
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [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
示例11: spatter
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [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
示例12: window_part_shot
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_BGRA2BGR [as 别名]
def window_part_shot(self, pos1, pos2, file_name=None, gray=0):
"""
窗口区域截图
:param pos1: (x,y) 截图区域的左上角坐标
:param pos2: (x,y) 截图区域的右下角坐标
:param file_name=None: 截图文件的保存路径
:param gray=0: 是否返回灰度图像,0:返回BGR彩色图像,其他:返回灰度黑白图像
:return: file_name为空则返回RGB数据
"""
w = pos2[0]-pos1[0]
h = pos2[1]-pos1[1]
hwindc = win32gui.GetWindowDC(self.hwnd)
srcdc = win32ui.CreateDCFromHandle(hwindc)
memdc = srcdc.CreateCompatibleDC()
bmp = win32ui.CreateBitmap()
bmp.CreateCompatibleBitmap(srcdc, w, h)
memdc.SelectObject(bmp)
if self.client == 0:
memdc.BitBlt((0, 0), (w, h), srcdc,
(pos1[0]+self._border_l, pos1[1]+self._border_t), win32con.SRCCOPY)
else:
memdc.BitBlt((0, -35), (w, h), srcdc,
(pos1[0]+self._border_l, pos1[1]+self._border_t), win32con.SRCCOPY)
if file_name != None:
bmp.SaveBitmapFile(memdc, file_name)
srcdc.DeleteDC()
memdc.DeleteDC()
win32gui.ReleaseDC(self.hwnd, hwindc)
win32gui.DeleteObject(bmp.GetHandle())
return
else:
signedIntsArray = bmp.GetBitmapBits(True)
img = np.fromstring(signedIntsArray, dtype='uint8')
img.shape = (h, w, 4)
srcdc.DeleteDC()
memdc.DeleteDC()
win32gui.ReleaseDC(self.hwnd, hwindc)
win32gui.DeleteObject(bmp.GetHandle())
#cv2.imshow("image", cv2.cvtColor(img, cv2.COLOR_BGRA2BGR))
# cv2.waitKey(0)
if gray == 0:
return cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
else:
return cv2.cvtColor(img, cv2.COLOR_BGRA2GRAY)