當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。