当前位置: 首页>>代码示例>>Python>>正文


Python cv2.COLORMAP_RAINBOW属性代码示例

本文整理汇总了Python中cv2.COLORMAP_RAINBOW属性的典型用法代码示例。如果您正苦于以下问题:Python cv2.COLORMAP_RAINBOW属性的具体用法?Python cv2.COLORMAP_RAINBOW怎么用?Python cv2.COLORMAP_RAINBOW使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cv2的用法示例。


在下文中一共展示了cv2.COLORMAP_RAINBOW属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: draw_anchors_rect

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_RAINBOW [as 别名]
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 
开发者ID:zhuhao-nju,项目名称:hmd,代码行数:20,代码来源:utility.py

示例2: draw_joints_rect

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_RAINBOW [as 别名]
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 
开发者ID:zhuhao-nju,项目名称:hmd,代码行数:16,代码来源:utility.py

示例3: tensor2array

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_RAINBOW [as 别名]
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 
开发者ID:yechengxi,项目名称:deconvolution,代码行数:33,代码来源:util.py

示例4: tensor2array

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_RAINBOW [as 别名]
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 
开发者ID:sunghoonim,项目名称:DPSNet,代码行数:30,代码来源:utils.py

示例5: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import COLORMAP_RAINBOW [as 别名]
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) 
开发者ID:zemofreedom,项目名称:PSMNet-Tensorflow,代码行数:39,代码来源:predict.py


注:本文中的cv2.COLORMAP_RAINBOW属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。