对深度图进行随机采样以得到较为稀疏的深度图:
全部代码如下:
import os
import shutil
import cv2
import numpy as np
image_path = "F:\\chouxi\\23_yueye\\full\\"
save_path = "F:\\chouxi\\23_yueye\\164\\"
image_list = os.listdir(image_path)
x = 1/2 #随机采样率,1/2 表示随机采样率为 1 - 1/2 * 1/2 = 0.75。
for i in image_list:
img = cv2.imread(image_path+i, -1) #在cv2.imread参数中加入-1,表示不改变读取图像的类型直接读取
print(img.shape)
print(img.dtype)
#A = np.zeros(img.shape[1])
hang = np.arange(img.shape[0])
lie = np.arange(img.shape[1])
np.random.shuffle(hang)
np.random.shuffle(lie)
hang_1 = hang[0:round(img.shape[0]*(1-x))]
lie_1 = lie[0:round(img.shape[1]*(1-x))]
for j in hang_1:
for k in lie_1:
img[j][k] = 0.0
print(img.shape)
print(img.dtype)
print(save_path+i)
print("*"*20)
cv2.imwrite(save_path+i, img)