赞
踩
import scipy.io as scio import open3d as o3d import numpy as np import cv2 import matplotlib from matplotlib import pyplot as plt # read mat file data = scio.loadmat("D:\xx\A2J\ITOP-Dataset\itop_side_test/1.mat") depth_map = data['DepthNormal'][:,:,3] image = np.zeros(depth_map.shape, dtype = np.uint8) for r in range(depth_map.shape[0]): for c in range(depth_map.shape[1]): if depth_map[r,c] < 6.0: # max depth value is 6.0 image[r,c] = depth_map[r,c]/6.0 * 255 # Display image plt.figure("test", figsize=(8,8)) # 创建一个名为astronaut的窗口,并设置大小 plt.subplot(2,2,1) plt.title("U8") plt.imshow(image) plt.subplot(2,2,2) plt.title("Float") plt.imshow(depth_map) plt.subplot(2,2,3) plt.title("U8-gray") plt.imshow(image, plt.cm.gray) plt.subplot(2,2,4) plt.title("Float-gray") plt.imshow(depth_map, plt.cm.gray) plt.show() ## save image plt.imsave('plt-u8.png', image) plt.imsave('plt-float.png',depth_map)
data = scio.loadmat("D:\xx\A2J\ITOP-Dataset\itop_side_test/1.mat") depth_map = data['DepthNormal'][:,:,3] image = np.zeros(depth_map.shape, dtype = np.uint8) for r in range(depth_map.shape[0]): for c in range(depth_map.shape[1]): if depth_map[r,c] < 6.0: # max depth value is 6.0 image[r,c] = depth_map[r,c]/6.0 * 255 cv2.imwrite("opencv_gray.png", image) depth_colormap = cv2.applyColorMap(cv2.convertScaleAbs(image, alpha=1.0), cv2.COLORMAP_JET) cv2.imwrite("opencv_color.png", depth_colormap) # Stack multiple images horizontal depth_image = np.zeros((depth_map.shape[0],depth_map.shape[1], 3), dtype = np.uint8) depth_image[:,:,0] = image[:,:] depth_image[:,:,1] = image[:,:] depth_image[:,:,2] = image[:,:] images = np.hstack((depth_image, depth_colormap)) # hstack image must have the same shape cv2.imshow('images', images) cv2.waitKey() cv2.destroyAllWindows()
img = plt.imread("D:\APractise\A2J\A2J-master\src/1.jpg") plt.figure("test", figsize=(8,8)) # 创建一个名为test的窗口,并设置大小 plt.subplot(2,2,1) plt.title("RGB") plt.imshow(img) plt.subplot(2,2,2) plt.title("R") plt.imshow(img[:,:,0]) plt.subplot(2,2,3) plt.title("G") plt.imshow(img[:,:,1]) plt.subplot(2,2,4) plt.title("B") plt.imshow(img[:,:,2]) plt.show()
def generate_anchors(P_h=None, P_w=None): if P_h is None: P_h = np.array([2,6,10,14]) if P_w is None: P_w = np.array([2,6,10,14]) num_anchors = len(P_h) * len(P_h) #print("num_anchors=", num_anchors) # initialize output anchors anchors = np.zeros((num_anchors, 2)) k = 0 for i in range(len(P_w)): for j in range(len(P_h)): anchors[k,1] = P_w[j] anchors[k,0] = P_h[i] k += 1 #print("anchors=\n", anchors) #print("anchors.shape=", anchors.shape) print("Display Template Anchors:") plt.plot(anchors[:,0], anchors[:,1], marker='.', color='blue', linestyle='none') plt.show() return anchors # anchors.shape=(16,2) generate_anchors()
def pixel2world(x,y,z): worldX = (x - 160.0)*z*0.0035 worldY = (120.0 - y)*z*0.0035 return worldX,worldY, z data = scio.loadmat("D:\xx\A2J\ITOP-Dataset\itop_side_test-ok/0.mat") depth_map = data['DepthNormal'][:,:,3] np_points = np.zeros((depth_map.shape[0] * depth_map.shape[1], 3), dtype='float32') # generate the point cloud data height, width = np.shape(depth_map) print("height={}, width={}".format(height, width)) print(depth_map.shape) for y in range(0, height-1): index = y * width for x in range(0, width-1): if depth_map[y,x] < 3.5: np_points[index+x,:] = pixel2world(x,y,depth_map[y,x]) pcd = o3d.geometry.PointCloud() # create open3d PCD pcd.points = o3d.utility.Vector3dVector(np_points) # from numpy to Open3D # o3d.visualization.draw_geometries([pcd]) # show the pcd o3d.visualization.draw_geometries([pcd], front = [ 0.0, 0.0, -1.0], lookat = [ 0.25160008668899536, 0.074648439884185791, 2.095703125 ], up = [ 0.0, 1.0, 0.0 ], zoom = 0.5)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。