import numpy as np import os, os.path import cv2 """将RGB图片和视差图融合成四通道RGBD图片。RGB图片和视差图的路径分别放在txt文件中""" #通过txt文件中的路径读取RGB图片 train_file = open('/home/user/RGB.txt') input_data_train = train_file.readlines() train_file.close() #通过txt文件中的路径读取视差图 disp_file = open('/home/user/Dis.txt') input_data_disp = disp_file.readlines() disp_file.close() for i, name in enumerate(input_data_train): #去掉末尾的换行符,name = input_data_train[i] input_data_train[i] = input_data_train[i].strip() input_data_disp[i] = input_data_disp[i].strip() #用opencv读取图片 rgb = cv2.imread(input_data_train[i], cv2.CV_LOAD_IMAGE_UNCHANGED) disp = cv2.imread(input_data_disp[i], cv2.CV_LOAD_IMAGE_UNCHANGED) #将图片转换为numpy数组 rgb = np.array(rgb) disp = np.array(disp) #融合 rgbd = np.zeros((360,480,4),dtype=np.uint8) rgbd[:, :, 0] = rgb[:, :, 0] rgbd[:, :, 1] = rgb[:, :, 1] rgbd[:, :, 2] = rgb[:, :, 2] rgbd[:, :, 3] = disp input_data_train[i] = os.path.split(input_data_train[i]) #保存的RGBD图片文件名为RGB图片的文件名 cv2.imwrite('/home/user/RGBD/%s' % input_data_train[i][1], rgbd) print ("success")
将RGB图片和视差图D融合成四通道RGBD图片
最新推荐文章于 2022-07-26 22:00:04 发布