本文整理汇总了Python中cv2.COLOR_GRAY2RGB属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.COLOR_GRAY2RGB属性的具体用法?Python cv2.COLOR_GRAY2RGB怎么用?Python cv2.COLOR_GRAY2RGB使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.COLOR_GRAY2RGB属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProcessFrame
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def ProcessFrame(self, frame):
# segment arm region
segment = self.SegmentArm(frame)
# make a copy of the segmented image to draw on
draw = cv2.cvtColor(segment, cv2.COLOR_GRAY2RGB)
# draw some helpers for correctly placing hand
cv2.circle(draw,(self.imgWidth/2,self.imgHeight/2),3,[255,102,0],2)
cv2.rectangle(draw, (self.imgWidth/3,self.imgHeight/3), (self.imgWidth*2/3, self.imgHeight*2/3), [255,102,0],2)
# find the hull of the segmented area, and based on that find the
# convexity defects
[contours,defects] = self.FindHullDefects(segment)
# detect the number of fingers depending on the contours and convexity defects
# draw defects that belong to fingers green, others red
[nofingers,draw] = self.DetectNumberFingers(contours, defects, draw)
# print number of fingers on image
cv2.putText(draw, str(nofingers), (30,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255))
return draw
示例2: to_tensor
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def to_tensor(pic):
"""Convert a ``numpy.ndarray`` image to tensor.
See ``ToTensor`` for more details.
Args:
pic (numpy.ndarray): Image to be converted to tensor.
Returns:
Tensor: Converted image.
"""
if _is_numpy_image(pic):
if pic.ndim == 2:
pic = cv2.cvtColor(pic, cv2.COLOR_GRAY2RGB)
img = torch.from_numpy(pic.transpose((2, 0, 1)))
# backward compatibility
if isinstance(img, torch.ByteTensor):
return img.float().div(255)
else:
return img
else:
raise TypeError('pic should be ndarray. Got {}.'.format(type(pic)))
示例3: adjust_saturation
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def adjust_saturation(img, saturation_factor):
"""Adjust color saturation of an image.
Args:
img (CV Image): CV Image to be adjusted.
saturation_factor (float): How much to adjust the saturation. 0 will
give a black and white image, 1 will give the original image while
2 will enhance the saturation by a factor of 2.
Returns:
CV Image: Saturation adjusted image.
"""
if not _is_numpy_image(img):
raise TypeError('img should be CV Image. Got {}'.format(type(img)))
im = img.astype(np.float32)
degenerate = cv2.cvtColor(
cv2.cvtColor(
im,
cv2.COLOR_RGB2GRAY),
cv2.COLOR_GRAY2RGB)
im = (1 - saturation_factor) * degenerate + saturation_factor * im
im = im.clip(min=0, max=255)
return im.astype(img.dtype)
示例4: drawNewLocation
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def drawNewLocation(ax, image_dict, result, image_scale, radio, sx, sy, event, ar):
x_offset = 0.0
y_offset = 0.0
if sx is not None and sy is not None:
x_offset = sx.val
y_offset = sy.val
vosm = np.copy(image_dict["Visible"])
vosm = OSMTGC.addOSMToImage(result.ways, vosm, pc, image_scale, x_offset, y_offset)
image_dict["Visible Golf"] = vosm
hosm = np.copy(image_dict["Heightmap"]).astype('float32')
hosm = np.clip(hosm, 0.0, 3.5*np.median( hosm[ hosm >= 0.0 ])) # Limit outlier pixels
hosm = hosm / np.max(hosm)
hosm = cv2.cvtColor(hosm, cv2.COLOR_GRAY2RGB)
hosm = OSMTGC.addOSMToImage(result.ways, hosm, pc, image_scale, x_offset, y_offset)
image_dict["Heightmap Golf"] = hosm
# Always set to Visible Golf after drawing new golf features
ax.imshow(image_dict["Visible Golf"], origin='lower')
radio.set_active(1)
示例5: test_thresh_images
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def test_thresh_images(src, dst, s_thresh, sx_thresh):
"""
apply the thresh to images in a src folder and output to dst foler
"""
image_files = glob.glob(src+"*.jpg")
for idx, file in enumerate(image_files):
print(file)
img = mpimg.imread(file)
image_threshed = color_grid_thresh(img, s_thresh=s_thresh, sx_thresh=sx_thresh)
file_name = file.split("\\")[-1]
print(file_name)
out_image = dst+file_name
print(out_image)
# convert binary to RGB, *255, to visiual, 1 will not visual after write to file
image_threshed = cv2.cvtColor(image_threshed*255, cv2.COLOR_GRAY2RGB)
cv2.imwrite(out_image, image_threshed)
示例6: test_color_grid_thresh_dynamic
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def test_color_grid_thresh_dynamic(src, dst, s_thresh, sx_thresh):
"""
apply the thresh to images in a src folder and output to dst foler
"""
image_files = glob.glob(src+"*.jpg")
for idx, file in enumerate(image_files):
print(file)
img = mpimg.imread(file)
image_threshed = color_grid_thresh_dynamic(img, s_thresh=s_thresh, sx_thresh=sx_thresh)
file_name = file.split("\\")[-1]
print(file_name)
out_image = dst+file_name
print(out_image)
# convert binary to RGB, *255, to visiual, 1 will not visual after write to file
image_threshed = cv2.cvtColor(image_threshed*255, cv2.COLOR_GRAY2RGB)
cv2.imwrite(out_image, image_threshed)
示例7: test_yellow_grid_thresh_images
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def test_yellow_grid_thresh_images(src, dst, y_low=(10,50,0), y_high=(30,255,255), sx_thresh=(20, 100)):
"""
apply the thresh to images in a src folder and output to dst foler
"""
image_files = glob.glob(src+"*.jpg")
for idx, file in enumerate(image_files):
print(file)
img = mpimg.imread(file)
image_threshed = yellow_grid_thresh(img, y_low, y_high, sx_thresh)
file_name = file.split("\\")[-1]
print(file_name)
out_image = dst+file_name
print(out_image)
# convert binary to RGB, *255, to visiual, 1 will not visual after write to file
image_threshed = cv2.cvtColor(image_threshed*255, cv2.COLOR_GRAY2RGB)
cv2.imwrite(out_image, image_threshed)
示例8: test_yellow_white_thresh_images
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def test_yellow_white_thresh_images(src, dst, y_low=(10,50,0), y_high=(30,255,255), w_low=(180,180,180), w_high=(255,255,255)):
"""
apply the thresh to images in a src folder and output to dst foler
"""
image_files = glob.glob(src+"*.jpg")
for idx, file in enumerate(image_files):
print(file)
img = mpimg.imread(file)
image_threshed = yellow_white_thresh(img, y_low, y_high, w_low, w_high)
file_name = file.split("\\")[-1]
print(file_name)
out_image = dst+file_name
print(out_image)
# convert binary to RGB, *255, to visiual, 1 will not visual after write to file
image_threshed = cv2.cvtColor(image_threshed*255, cv2.COLOR_GRAY2RGB)
# HSV = cv2.cvtColor(img, cv2.COLOR_RGB2HSV)
# V = HSV[:,:,2]
# brightness = np.mean(V)
# info_str = "brightness is: {}".format(int(brightness))
# cv2.putText(image_threshed, info_str, (50,700), cv2.FONT_HERSHEY_SIMPLEX,2,(0,255,255),2)
cv2.imwrite(out_image, image_threshed)
示例9: imread_uint
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def imread_uint(path, n_channels=3):
# input: path
# output: HxWx3(RGB or GGG), or HxWx1 (G)
if n_channels == 1:
img = cv2.imread(path, 0) # cv2.IMREAD_GRAYSCALE
img = np.expand_dims(img, axis=2) # HxWx1
elif n_channels == 3:
img = cv2.imread(path, cv2.IMREAD_UNCHANGED) # BGR or G
if img.ndim == 2:
img = cv2.cvtColor(img, cv2.COLOR_GRAY2RGB) # GGG
else:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # RGB
return img
# --------------------------------------------
# matlab's imwrite
# --------------------------------------------
示例10: display_results
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def display_results(self, t0, t1, mask_pred, mask_gt):
w, h = self.w_orig, self.h_orig
t0_disp = cv2.resize(np.transpose(t0.numpy(), (1, 2, 0)).astype(np.uint8), (w, h))
t1_disp = cv2.resize(np.transpose(t1.numpy(), (1, 2, 0)).astype(np.uint8), (w, h))
mask_pred_disp = cv2.resize(cv2.cvtColor(mask_pred.numpy().astype(np.uint8), cv2.COLOR_GRAY2RGB), (w, h))
mask_gt_disp = cv2.resize(cv2.cvtColor(mask_gt.astype(np.uint8), cv2.COLOR_GRAY2RGB), (w, h))
img_out = np.zeros((h* 2, w * 2, 3), dtype=np.uint8)
img_out[0:h, 0:w, :] = t0_disp
img_out[0:h, w:w * 2, :] = t1_disp
img_out[h:h * 2, 0:w * 1, :] = mask_gt_disp
img_out[h:h * 2, w * 1:w * 2, :] = mask_pred_disp
for dn, img in zip(['mask', 'disp'], [mask_pred_disp, img_out]):
dn_save = os.path.join(self.args.checkpointdir, 'result', dn)
fn_save = os.path.join(dn_save, '{0:08d}.png'.format(self.index))
if not os.path.exists(dn_save):
os.makedirs(dn_save)
print('Writing ... ' + fn_save)
cv2.imwrite(fn_save, img)
示例11: draw
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def draw(self, dbscan_input_array, dbscan_label, dbscan_label_n):
# convert array to image
frame_draw = np.zeros((self.__compress_height, self.__compress_width), np.uint8)
frame_draw = cv2.cvtColor(frame_draw, cv2.COLOR_GRAY2RGB)
for i in range(dbscan_input_array.shape[0]):
if not dbscan_label[i] == -1:
color_th = dbscan_label[i] / dbscan_label_n
c_r = int(cm.hsv(color_th)[0]*255)
c_g = int(cm.hsv(color_th)[1]*255)
c_b = int(cm.hsv(color_th)[2]*255)
frame_draw = cv2.circle(frame_draw, \
(int(dbscan_input_array[i][0]), \
int(dbscan_input_array[i][1])), \
1, (c_r, c_g, c_b), 1)
return frame_draw
示例12: get_features
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def get_features(self, img, pos, sample_sz, scales):
feat1 = []
feat2 = []
if img.shape[2] == 1:
img = cv2.cvtColor(img.squeeze(), cv2.COLOR_GRAY2RGB)
if not isinstance(scales, list) and not isinstance(scales, np.ndarray):
scales = [scales]
patches = []
for scale in scales:
patch = self._sample_patch(img, pos, sample_sz*scale, sample_sz)
patch = mx.nd.array(patch / 255., ctx=self._ctx)
normalized = mx.image.color_normalize(patch,
mean=mx.nd.array([0.485, 0.456, 0.406], ctx=self._ctx),
std=mx.nd.array([0.229, 0.224, 0.225], ctx=self._ctx))
normalized = normalized.transpose((2, 0, 1)).expand_dims(axis=0)
patches.append(normalized)
patches = mx.nd.concat(*patches, dim=0)
f1, f2 = self._forward(patches)
f1 = self._feature_normalization(f1)
f2 = self._feature_normalization(f2)
return f1, f2
示例13: channel3img
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [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
示例14: adjust_saturation
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def adjust_saturation(img, saturation_factor):
"""Adjust color saturation of an image.
Args:
img (np.ndarray): CV Image to be adjusted.
saturation_factor (float): How much to adjust the saturation. 0 will
give a gray image, 1 will give the original image while
2 will enhance the saturation by a factor of 2.
Returns:
np.ndarray: Saturation adjusted image.
"""
if not _is_numpy_image(img):
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
im = img.astype(np.float32)
degenerate = cv2.cvtColor(cv2.cvtColor(im, cv2.COLOR_RGB2GRAY), cv2.COLOR_GRAY2RGB)
im = (1-saturation_factor) * degenerate + saturation_factor * im
im = im.clip(min=0, max=255)
return im.astype(img.dtype)
示例15: to_grayscale
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLOR_GRAY2RGB [as 别名]
def to_grayscale(img, num_output_channels=1):
"""Convert image to grayscale version of image.
Args:
img (np.ndarray): Image to be converted to grayscale.
Returns:
CV Image: Grayscale version of the image.
if num_output_channels == 1 : returned image is single channel
if num_output_channels == 3 : returned image is 3 channel with r == g == b
"""
if not _is_numpy_image(img):
raise TypeError('img should be CV Image. Got {}'.format(type(img)))
if num_output_channels == 1:
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
elif num_output_channels == 3:
img = cv2.cvtColor(cv2.cvtColor(img, cv2.COLOR_RGB2GRAY), cv2.COLOR_GRAY2RGB)
else:
raise ValueError('num_output_channels should be either 1 or 3')
return img