Python cv2.COLORMAP_RAINBOW Examples
The following are 5
code examples of cv2.COLORMAP_RAINBOW().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: utility.py From hmd with MIT License | 6 votes |
def draw_anchors_rect(img_arr, anchor_posi, sample = 1, ratio = 1): ori_dtype = img_arr.dtype joint_num = len(anchor_posi) seed_arr = np.array([range(1,255,255/joint_num)]).astype(np.uint8) color_list = cv2.applyColorMap(seed_arr, cv2.COLORMAP_RAINBOW)[0] draw_arr = img_arr.astype(np.float) for i in range(joint_num): if (i%sample)!=0: continue draw_arr = draw_rect(draw_arr, anchor_posi[i], size = 32, color = color_list[i].tolist()) if ratio < 1: draw_arr = draw_arr*ratio + img_arr.astype(np.float)*(1-ratio) return draw_arr.astype(ori_dtype) # write OBJ from vertex # not tested yet
Example #2
Source File: utility.py From hmd with MIT License | 5 votes |
def draw_joints_rect(img_arr, joint_posi, ratio = 1): ori_dtype = img_arr.dtype joint_num = len(joint_posi) seed_arr = np.array([range(1,255,255/joint_num)]).astype(np.uint8) color_list = cv2.applyColorMap(seed_arr, cv2.COLORMAP_RAINBOW)[0] draw_arr = img_arr.astype(np.float) for i in range(joint_num): draw_arr = draw_rect(draw_arr, joint_posi[i], color = color_list[i].tolist()) if ratio < 1: draw_arr = draw_arr*ratio + img_arr.astype(np.float)*(1-ratio) return draw_arr.astype(ori_dtype) # for visualizing predict window in images
Example #3
Source File: util.py From deconvolution with GNU General Public License v3.0 | 5 votes |
def tensor2array(tensor, max_value=None, colormap='rainbow'): if max_value is None: tensor=(tensor-tensor.min())/(tensor.max()-tensor.min()+1e-6) max_value = tensor.max().item() if tensor.ndimension() == 2 or tensor.size(0) == 1: try: import cv2 if cv2.__version__.startswith('3'): color_cvt = cv2.COLOR_BGR2RGB else: # 2.4 color_cvt = cv2.cv.CV_BGR2RGB if colormap == 'rainbow': colormap = cv2.COLORMAP_RAINBOW elif colormap == 'bone': colormap = cv2.COLORMAP_BONE array = (tensor.squeeze().numpy()*255./max_value).clip(0, 255).astype(np.uint8) colored_array = cv2.applyColorMap(array, colormap) array = cv2.cvtColor(colored_array, color_cvt).astype(np.float32)/255 except ImportError: if tensor.ndimension() == 2: tensor.unsqueeze_(2) array = (tensor.expand(tensor.size(0), tensor.size(1), 3).numpy()/max_value).clip(0,1) elif tensor.ndimension() == 3: assert(tensor.size(0) == 3) array = 0.5 + tensor.numpy().transpose(1, 2, 0)*0.5 #for tensorboardx 1.4 #array=array.transpose(2,0,1) return array
Example #4
Source File: utils.py From DPSNet with MIT License | 5 votes |
def tensor2array(tensor, max_value=255, colormap='rainbow'): if max_value is None: max_value = tensor.max() if tensor.ndimension() == 2 or tensor.size(0) == 1: try: import cv2 if cv2.__version__.startswith('2'): # 2.4 color_cvt = cv2.cv.CV_BGR2RGB else: color_cvt = cv2.COLOR_BGR2RGB if colormap == 'rainbow': colormap = cv2.COLORMAP_RAINBOW elif colormap == 'bone': colormap = cv2.COLORMAP_BONE array = (255*tensor.squeeze().numpy()/max_value).clip(0, 255).astype(np.uint8) colored_array = cv2.applyColorMap(array, colormap) array = cv2.cvtColor(colored_array, color_cvt).astype(np.float32)/255 #array = array.transpose(2, 0, 1) except ImportError: if tensor.ndimension() == 2: tensor.unsqueeze_(2) array = (tensor.expand(tensor.size(0), tensor.size(1), 3).numpy()/max_value).clip(0,1) elif tensor.ndimension() == 3: #assert(tensor.size(0) == 3) #array = 0.5 + tensor.numpy()*0.5 array = 0.5 + tensor.numpy().transpose(1,2,0)*0.5 return array
Example #5
Source File: predict.py From PSMNet-Tensorflow with MIT License | 5 votes |
def main(): height = 368 #544 #368 weight = 1232 #960 #1232 left_img = args.datapath+args.leftimg right_img = args.datapath+args.leftimg with tf.Session() as sess: img_L = cv2.cvtColor(cv2.imread(left_img), cv2.COLOR_BGR2RGB) img_L = cv2.resize(img_L, (weight, height)) img_R = cv2.cvtColor(cv2.imread(right_img), cv2.COLOR_BGR2RGB) img_R = cv2.resize(img_R, (weight, height)) img_L = DataLoaderKITTI.mean_std(img_L) img_L = np.expand_dims(img_L, axis=0) img_R = DataLoaderKITTI.mean_std(img_R) img_R = np.expand_dims(img_R, axis=0) PSMNet = Model(sess, height=height, weight=weight, batch_size=args.batch, max_disp=args.maxdisp) saver = tf.train.Saver() saver.restore(sess, args.loadmodel) pred = PSMNet.predict(img_L, img_R) pred = np.squeeze(pred,axis=0) print(pred.shape) print(pred.max()) #np.save('pred.npy',pred) pred_disp = pred.astype(np.uint8) print(pred_disp.shape) #pred_disp = np.squeeze(pred_disp,axis=0) cv2.imwrite('pred_disp.png', pred_disp) pred_rainbow = cv2.applyColorMap(pred_disp, cv2.COLORMAP_RAINBOW) cv2.imwrite('pred_rainbow.png', pred_rainbow)