13 | | | | ___ | | _ __ ___ _ __ | ___|_ _ _ __ ___ | |_ (_) ___ _ __ ___ 14 | |_| | / _ \| || '_ \ / _ \| '__| | |_ | | | || '_ \ / __|| __|| | / _ \ | '_ \ / __| 15 | _ || __/| || |_) || __/| | | _| | |_| || | | || (__ | |_ | || (_) || | | |\__ \ 16 |_| |_| \___||_|| .__/ \___||_| |_| \__,_||_| |_| \___| \__||_| \___/ |_| |_||___/ 23 calculates the root mean square deviation between to point sets 27 points1, points2: numpy matrix (K, N) 28 where K is the dimension of the points and N is the number of points 30 validPoints: bool sequence of valid points in the point set. 31 If it is left out, all points are considered valid 33 assert(points1.shape == points2.shape)
36 if validPoints ==
None:
37 validPoints = [
True]*N
39 assert(len(validPoints) == N)
41 points1 = points1[:,validPoints]
42 points2 = points2[:,validPoints]
46 dist = points1 - points2
49 rmsd += np.matmul(dist[:,col].transpose(), dist[:,col]).flatten()[0]
51 return np.sqrt(rmsd/N)
56 Returns the 3d coordinates of the chessboard corners 57 in the coordinate system of the chessboard itself. 62 (3, N) matrix with N being the number of corners 64 assert(len(chessboard_params) == 3)
65 width = chessboard_params[0]
66 height = chessboard_params[1]
67 square_size = chessboard_params[2]
68 objp = np.zeros((width * height, 3), np.float32)
69 objp[:,:2] = np.mgrid[0:width,0:height].T.reshape(-1,2)
70 return objp.transpose() * square_size
75 Searches the chessboard corners using the set infrared image and the 80 chessboard_found : bool 81 Indicates wheather the operation was successful 83 (2,N) matrix with the image coordinates of the chessboard corners 85 assert(len(chessboard_params) == 3)
86 infrared_image = np.asanyarray(infrared_frame.get_data())
87 criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
88 chessboard_found =
False 89 chessboard_found, corners = cv2.findChessboardCorners(infrared_image, (
90 chessboard_params[0], chessboard_params[1]))
93 corners = cv2.cornerSubPix(infrared_image, corners, (11,11),(-1,-1), criteria)
94 corners = np.transpose(corners, (2,0,1))
95 return chessboard_found, corners
101 Get the depth value at the desired image point 105 depth_frame : rs.frame() 106 The depth frame containing the depth information of the image coordinate 108 The x value of the image coordinate 110 The y value of the image coordinate 114 depth value at the desired pixel 117 return depth_frame.as_depth_frame().get_distance(round(pixel_x), round(pixel_y))
123 Convert the depth and image point information to metric coordinates 128 The depth value of the image point 130 The x value of the image coordinate 132 The y value of the image coordinate 133 camera_intrinsics : The intrinsic values of the imager in whose coordinate system the depth_frame is computed 138 The x value in meters 140 The y value in meters 142 The z value in meters 145 X = (pixel_x - camera_intrinsics.ppx)/camera_intrinsics.fx *depth
146 Y = (pixel_y - camera_intrinsics.ppy)/camera_intrinsics.fy *depth
153 Convert the depthmap to a 3D point cloud 157 depth_frame : rs.frame() 158 The depth_frame containing the depth map 159 camera_intrinsics : The intrinsic values of the imager in whose coordinate system the depth_frame is computed 164 The x values of the pointcloud in meters 166 The y values of the pointcloud in meters 168 The z values of the pointcloud in meters 172 [height, width] = depth_image.shape
174 nx = np.linspace(0, width-1, width)
175 ny = np.linspace(0, height-1, height)
176 u, v = np.meshgrid(nx, ny)
177 x = (u.flatten() - camera_intrinsics.ppx)/camera_intrinsics.fx
178 y = (v.flatten() - camera_intrinsics.ppy)/camera_intrinsics.fy
180 z = depth_image.flatten() / 1000;
193 Convert the world coordinate to a 2D image coordinate 197 pointcloud : numpy array with shape 3xN 199 camera_intrinsics : The intrinsic values of the imager in whose coordinate system the depth_frame is computed 204 The x coordinate in image 206 The y coordiante in image 210 assert (pointcloud.shape[0] == 3)
215 m = x_[np.nonzero(z_)]/z_[np.nonzero(z_)]
216 n = y_[np.nonzero(z_)]/z_[np.nonzero(z_)]
218 x = m*camera_intrinsics.fx + camera_intrinsics.ppx
219 y = n*camera_intrinsics.fy + camera_intrinsics.ppy
227 Get the minimum and maximum point from the array of points 232 The array of points out of which the min and max X and Y points are needed 237 The values arranged as [minX, maxX, minY, maxY] 241 if points.shape[0] == 3:
242 assert (len(points.shape)==2)
243 minPt_3d_x = np.amin(points[0,:])
244 maxPt_3d_x = np.amax(points[0,:])
245 minPt_3d_y = np.amin(points[1,:])
246 maxPt_3d_y = np.amax(points[1,:])
248 boudary = [minPt_3d_x-padding, maxPt_3d_x+padding, minPt_3d_y-padding, maxPt_3d_y+padding]
251 raise Exception(
"wrong dimension of points!")
259 Get the clipped pointcloud withing the X and Y bounds specified in the boundary 264 The input pointcloud which needs to be clipped 271 The clipped pointcloud 274 assert (pointcloud.shape[0]>=2)
275 pointcloud = pointcloud[:,np.logical_and(pointcloud[0,:]<boundary[1], pointcloud[0,:]>boundary[0])]
276 pointcloud = pointcloud[:,np.logical_and(pointcloud[1,:]<boundary[3], pointcloud[1,:]>boundary[2])]
def cv_find_chessboard(depth_frame, infrared_frame, chessboard_params)
def convert_depth_pixel_to_metric_coordinate(depth, pixel_x, pixel_y, camera_intrinsics)
def get_chessboard_points_3D(chessboard_params)
def convert_pointcloud_to_depth(pointcloud, camera_intrinsics)
def get_clipped_pointcloud(pointcloud, boundary)
def convert_depth_frame_to_pointcloud(depth_image, camera_intrinsics)
def calculate_rmsd(points1, points2, validPoints=None)
def get_boundary_corners_2D(points)
def get_depth_at_pixel(depth_frame, pixel_x, pixel_y)