本文整理汇总了Python中cv2.COLORMAP_JET属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.COLORMAP_JET属性的具体用法?Python cv2.COLORMAP_JET怎么用?Python cv2.COLORMAP_JET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类cv2
的用法示例。
在下文中一共展示了cv2.COLORMAP_JET属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_landmarks
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def show_landmarks(image, heatmap, gt_landmarks, gt_heatmap):
"""Show image with pred_landmarks"""
pred_landmarks = []
pred_landmarks, _ = get_preds_fromhm(torch.from_numpy(heatmap).unsqueeze(0))
pred_landmarks = pred_landmarks.squeeze()*4
# pred_landmarks2 = get_preds_fromhm2(heatmap)
heatmap = np.max(gt_heatmap, axis=0)
heatmap = heatmap / np.max(heatmap)
# image = ski_transform.resize(image, (64, 64))*255
image = image.astype(np.uint8)
heatmap = np.max(gt_heatmap, axis=0)
heatmap = ski_transform.resize(heatmap, (image.shape[0], image.shape[1]))
heatmap *= 255
heatmap = heatmap.astype(np.uint8)
heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET)
plt.imshow(image)
plt.scatter(gt_landmarks[:, 0], gt_landmarks[:, 1], s=0.5, marker='.', c='g')
plt.scatter(pred_landmarks[:, 0], pred_landmarks[:, 1], s=0.5, marker='.', c='r')
plt.pause(0.001) # pause a bit so that plots are updated
示例2: test_heatmaps
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def test_heatmaps(heatmaps,img,i):
heatmaps=heatmaps.numpy()
#heatmaps=np.squeeze(heatmaps)
heatmaps=heatmaps[:,:64,:]
heatmaps=heatmaps.transpose(1,2,0)
print('heatmap inside shape is',heatmaps.shape)
## print('----------------here')
## print(heatmaps.shape)
img=img.numpy()
#img=np.squeeze(img)
img=img.transpose(1,2,0)
img=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# print('heatmaps',heatmaps.shape)
heatmaps = cv2.resize(heatmaps,(0,0), fx=4,fy=4)
# print('heatmapsafter',heatmaps.shape)
for j in range(0, 16):
heatmap = heatmaps[:,:,j]
heatmap = heatmap.reshape((256,256,1))
heatmapimg = np.array(heatmap * 255, dtype = np.uint8)
heatmap = cv2.applyColorMap(heatmapimg, cv2.COLORMAP_JET)
heatmap = heatmap/255
plt.imshow(img)
plt.imshow(heatmap, alpha=0.5)
plt.show()
#plt.savefig('hmtestpadh36'+str(i)+js[j]+'.png')
示例3: calculate_gradient_weighted_CAM
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def calculate_gradient_weighted_CAM(gradient_function, image):
output, evaluated_gradients = gradient_function([image, False])
output, evaluated_gradients = output[0, :], evaluated_gradients[0, :, :, :]
weights = np.mean(evaluated_gradients, axis=(0, 1))
CAM = np.ones(output.shape[0: 2], dtype=np.float32)
for weight_arg, weight in enumerate(weights):
CAM = CAM + (weight * output[:, :, weight_arg])
CAM = cv2.resize(CAM, (64, 64))
CAM = np.maximum(CAM, 0)
heatmap = CAM / np.max(CAM)
# Return to BGR [0..255] from the preprocessed image
image = image[0, :]
image = image - np.min(image)
image = np.minimum(image, 255)
CAM = cv2.applyColorMap(np.uint8(255 * heatmap), cv2.COLORMAP_JET)
CAM = np.float32(CAM) + np.float32(image)
CAM = 255 * CAM / np.max(CAM)
return np.uint8(CAM), heatmap
示例4: calculate_gradient_weighted_CAM
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def calculate_gradient_weighted_CAM(gradient_function, image):
output, evaluated_gradients = gradient_function([image, False])
output, evaluated_gradients = output[0, :], evaluated_gradients[0, :, :, :]
weights = np.mean(evaluated_gradients, axis = (0, 1))
CAM = np.ones(output.shape[0 : 2], dtype=np.float32)
for weight_arg, weight in enumerate(weights):
CAM = CAM + (weight * output[:, :, weight_arg])
CAM = cv2.resize(CAM, (64, 64))
CAM = np.maximum(CAM, 0)
heatmap = CAM / np.max(CAM)
#Return to BGR [0..255] from the preprocessed image
image = image[0, :]
image = image - np.min(image)
image = np.minimum(image, 255)
CAM = cv2.applyColorMap(np.uint8(255 * heatmap), cv2.COLORMAP_JET)
CAM = np.float32(CAM) + np.float32(image)
CAM = 255 * CAM / np.max(CAM)
return np.uint8(CAM), heatmap
示例5: read_h5py_example
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def read_h5py_example():
h5_in = h5py.File(os.path.join(dir_path, 'data.h5'), 'r')
print (h5_in.keys())
print (h5_in['train']['image'].dtype)
print (h5_in['train']['image'][0].shape)
image_size = h5_in['train']['image'].attrs['size']
label_size = h5_in['train']['label'].attrs['size']
x_img = np.reshape(h5_in['train']['image'][0], tuple(image_size))
y_img = np.reshape(h5_in['train']['label'][0], tuple(label_size))
name = h5_in['train']['name'][0]
print (name)
y_img = (y_img.astype(np.float32)*255/33).astype(np.uint8)
y_show = cv2.applyColorMap(y_img, cv2.COLORMAP_JET)
show = cv2.addWeighted(x_img, 0.5, y_show, 0.5, 0)
cv2.imshow("show", show)
cv2.waitKey()
示例6: image_copy_to_dir
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def image_copy_to_dir(mode, x_paths, y_paths):
target_path = '/run/media/tkwoo/myWorkspace/workspace/01.dataset/03.Mask_data/cityscape'
target_path = os.path.join(target_path, mode)
for idx in trange(len(x_paths)):
image = cv2.imread(x_paths[idx], 1)
mask = cv2.imread(y_paths[idx], 0)
image = cv2.resize(image, None, fx=0.25, fy=0.25, interpolation=cv2.INTER_LINEAR)
mask = cv2.resize(mask, None, fx=0.25, fy=0.25, interpolation=cv2.INTER_NEAREST)
cv2.imwrite(os.path.join(target_path, 'image', os.path.basename(x_paths[idx])), image)
cv2.imwrite(os.path.join(target_path, 'mask', os.path.basename(y_paths[idx])), mask)
# show = image.copy()
# mask = (mask.astype(np.float32)*255/33).astype(np.uint8)
# mask_color = cv2.applyColorMap(mask, cv2.COLORMAP_JET)
# show = cv2.addWeighted(show, 0.5, mask_color, 0.5, 0.0)
# cv2.imshow('show', show)
# key = cv2.waitKey(1)
# if key == 27:
# return
示例7: train_generator
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def train_generator(self, image_generator, mask_generator):
# cv2.namedWindow('show', 0)
# cv2.resizeWindow('show', 1280, 640)
while True:
image = next(image_generator)
mask = next(mask_generator)
label = self.make_regressor_label(mask).astype(np.float32)
# print (image.dtype, label.dtype)
# print (image.shape, label.shape)
# exit()
# cv2.imshow('show', image[0].astype(np.uint8))
# cv2.imshow('label', label[0].astype(np.uint8))
# mask = self.select_labels(mask)
# print (image.shape)
# print (mask.shape)
# image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
# mask = (mask.astype(np.float32)*255/33).astype(np.uint8)
# mask_color = cv2.applyColorMap(mask, cv2.COLORMAP_JET)
# print (mask_color.shape)
# show = cv2.addWeighted(image, 0.5, mask_color, 0.5, 0.0)
# cv2.imshow("show", show)
# key = cv2.waitKey()
# if key == 27:
# exit()
yield (image, label)
示例8: draw_lines
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def draw_lines(imgs, lines, scores=None, width=2):
assert len(imgs) == len(lines)
imgs = np.uint8(imgs)
bs = len(imgs)
if scores is not None:
assert len(scores) == bs
res = []
for b in range(bs):
img = imgs[b].transpose((1, 2, 0))
line = lines[b]
if scores is None:
score = np.zeros(len(line))
else:
score = scores[b]
img = img.copy()
for (x1, y1, x2, y2), c in zip(line, score):
pt1, pt2 = (x1, y1), (x2, y2)
c = tuple(cv2.applyColorMap(np.array(c * 255, dtype=np.uint8), cv2.COLORMAP_JET).flatten().tolist())
img = cv2.line(img, pt1, pt2, c, width)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
res.append(th.from_numpy(img.transpose((2, 0, 1))))
return res
示例9: render
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def render(self, n_max=0, fallback_im=None):
if self.image_scores is not None:
im = cv2.applyColorMap((self.image_scores * 255).astype(np.uint8),
cv2.COLORMAP_JET)
else:
assert fallback_im is not None
im = cv2.cvtColor(fallback_im, cv2.COLOR_GRAY2BGR)
if n_max == 0:
n_max = self.ips_rc.shape[1]
for i in range(n_max):
thickness_relevant_score = \
np.clip(self.ip_scores[i], 0.2, 0.6) - 0.2
thickness = int(thickness_relevant_score * 20)
if type(self.scales) == np.ndarray:
radius = int(self.scales[i] * 10)
else:
radius = 10
cv2.circle(im, tuple(self.ips_rc[[1, 0], i]),
radius, (0, 255, 0), thickness, cv2.LINE_AA)
return im
示例10: tile
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def tile(net_outs, rows, cols, downscale, ips_rc=None):
assert net_outs.shape[2] == 128
xdim = net_outs.shape[1]
ydim = net_outs.shape[0]
im = np.zeros([rows * ydim, cols * xdim, 3])
for r in range(rows):
for c in range(cols):
im_i = cv2.applyColorMap(
(net_outs[:, :, r * cols + c] * 255).astype(np.uint8),
cv2.COLORMAP_JET)
if ips_rc is not None:
cv2.circle(im_i, tuple(ips_rc[[1, 0], r * cols + c]),
downscale * 5, (0, 0, 0), downscale * 3,
cv2.LINE_AA)
im[r * ydim:(r + 1) * ydim, c * xdim:(c + 1) * xdim, :] = im_i
return skimage.measure.block_reduce(im, (downscale, downscale, 1), np.max)
示例11: color_pro
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def color_pro(pro, img=None, mode='hwc'):
H, W = pro.shape
pro_255 = (pro*255).astype(np.uint8)
pro_255 = np.expand_dims(pro_255,axis=2)
color = cv2.applyColorMap(pro_255,cv2.COLORMAP_JET)
color = cv2.cvtColor(color, cv2.COLOR_BGR2RGB)
if img is not None:
rate = 0.5
if mode == 'hwc':
assert img.shape[0] == H and img.shape[1] == W
color = cv2.addWeighted(img,rate,color,1-rate,0)
elif mode == 'chw':
assert img.shape[1] == H and img.shape[2] == W
img = np.transpose(img,(1,2,0))
color = cv2.addWeighted(img,rate,color,1-rate,0)
color = np.transpose(color,(2,0,1))
else:
if mode == 'chw':
color = np.transpose(color,(2,0,1))
return color
示例12: generate_colorbar
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def generate_colorbar(self, min_temp=None, max_temp=None, cmap=cv.COLORMAP_JET, height=None):
if min_temp is None:
min_temp = self.global_min_temp
if max_temp is None:
max_temp = self.global_max_temp
cb_gray = np.arange(255,0,-1,dtype=np.uint8).reshape((255,1))
if cmap is not None:
cb_color = cv.applyColorMap(cb_gray, cmap)
else:
cb_color = cv.cvtColor(cb_gray, cv.COLOR_GRAY2BGR)
for i in range(1,6):
cb_color = np.concatenate( (cb_color, cb_color), axis=1 )
if height is None:
append_img = np.zeros( (self.thermal_image.shape[0], cb_color.shape[1]+30, 3), dtype=np.uint8 )
else:
append_img = np.zeros( (height, cb_color.shape[1]+30, 3), dtype=np.uint8 )
append_img[append_img.shape[0]//2-cb_color.shape[0]//2 : append_img.shape[0]//2 - (cb_color.shape[0]//2) + cb_color.shape[0] , 10 : 10 + cb_color.shape[1] ] = cb_color
cv.putText(append_img, str(min_temp), (5, append_img.shape[0]//2 - (cb_color.shape[0]//2) + cb_color.shape[0] + 30), cv.FONT_HERSHEY_PLAIN, 1, (255,0,0) , 1, 8)
cv.putText(append_img, str(max_temp), (5, append_img.shape[0]//2-cb_color.shape[0]//2-20) , cv.FONT_HERSHEY_PLAIN, 1, (0,0,255) , 1, 8 )
return append_img
示例13: line_measurement
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def line_measurement(self, image, thermal_np, cmap=cv.COLORMAP_JET):
img = image.copy()
line, point1, point2 = CFlir.get_line(img)
line_temps = np.zeros(len(line))
if len(img.shape) == 3:
gray_values = np.arange(256, dtype=np.uint8)
color_values = map(tuple, cv.applyColorMap(gray_values, cmap).reshape(256, 3))
color_to_gray_map = dict(zip(color_values, gray_values))
img = np.apply_along_axis(lambda bgr: color_to_gray_map[tuple(bgr)], 2, image)
for i in range(0,len(line)):
line_temps[i] = thermal_np[ line[i][1], line[i][0] ]
cv.line(img, point1, point2, 255, 2, 8)
plt.subplot(1, 5, (1,2) )
plt.imshow(img, cmap='jet')
plt.title('Image')
plt.subplot(1, 5, (4,5) )
plt.plot(line_temps)
plt.title('Distance vs Temperature')
plt.show()
logger.info(f'\nMin line: {np.amin(line_temps)}\nMax line: {np.amax(line_temps)}' )
示例14: get_scaled_image
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def get_scaled_image(self, img, thermal_np, raw_thermal_np, cmap=cv.COLORMAP_JET, is_rect=False ) :
self.scale_contours = []
CFlir.contour=[]
CFlir.get_contours(img, self.scale_contours)
flag = False
if len (self.scale_contours) > 0:
if len(self.scale_contours[0]) > 15:
flag = True
thermal_roi_values = CFlir.get_roi(img, thermal_np, raw_thermal_np, self.scale_contours, 0)[1]
temp_scaled = CFlir.scale_with_roi(thermal_np, thermal_roi_values)
temp_scaled_image = CFlir.get_temp_image(temp_scaled, colormap=cmap)
if flag == False:
temp_scaled = thermal_np.copy()
temp_scaled_image = CFlir.get_temp_image(temp_scaled, colormap=cmap)
return temp_scaled , temp_scaled_image
示例15: various_scale_attention_weights_visualize
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_JET [as 别名]
def various_scale_attention_weights_visualize(spatial_weights,original_img1,original_img2,save_base_path,filename):
nchannel, height,width = spatial_weights.shape
scale_list = ['common','t0','t1']
original_imgs = [original_img1,original_img1,original_img2]
assert len(scale_list) == len(spatial_weights)
for idx in range(nchannel):
height_img, width_img, channel = original_imgs[idx].shape
scale_x = spatial_weights[idx]
scale_name = scale_list[idx]
scalex_x_att_map = cv2.resize(scale_x,(width_img,height_img),interpolation=cv2.INTER_LINEAR)
scalex_x_att_map_ = cv2.applyColorMap(np.uint8(255* scalex_x_att_map),cv2.COLORMAP_JET)
fuse_scale_att_map = 0.6 * scalex_x_att_map_ + 0.4 * original_imgs[idx]
cv2.imwrite(save_base_path + '_' + str(filename) + '_origin_' + str(scale_name) + '.jpg', scalex_x_att_map_)
cv2.imwrite(save_base_path + '_' + str(filename) + '_fuse_' + str(scale_name) + '.jpg', fuse_scale_att_map)