Contents Menu Expand Light mode Dark mode Auto light/dark mode
Open3D 0.19.0 documentation
Open3D 0.19.0 documentation

Getting Started

  • Introduction
  • Getting started
  • Build from source
  • Link Open3D in C++ projects
  • Build documentation
  • Docker
  • ARM support
  • Cross-platform GPU support (SYCL)
  • Open3D-ML

Tutorial

  • Core
    • Tensor
    • Hash map
  • Geometry
    • Point cloud
    • Mesh
    • RGBD images
    • KDTree
    • File IO
    • Point cloud outlier removal
    • Voxelization
    • Octree
    • Surface reconstruction
    • Transformation
    • Mesh deformation
    • Intrinsic shape signatures (ISS)
    • Ray Casting
    • Distance Queries
    • UV Maps
    • Python Interface
    • Working with NumPy
  • Geometry (Tensor)
    • PointCloud
  • Dataset
  • Visualization
    • Visualization
    • Customized visualization
    • Interactive visualization
    • Non-blocking visualization
    • Headless rendering
    • CPU (Software) Rendering
    • Web visualizer and Jupyter
    • Open3D for TensorBoard
  • Pipelines
    • ICP registration
    • Robust kernels
    • Colored point cloud registration
    • Global registration
    • Multiway registration
    • RGBD integration
    • RGBD Odometry
    • Color Map Optimization
  • Pipelines (Tensor)
    • ICP registration
    • Robust Kernel
  • Reconstruction system
    • System overview
    • Make fragments
    • Register fragments
    • Refine registration
    • Integrate scene
    • Capture your own dataset
  • Reconstruction system (Tensor)
    • Voxel Block Grid
    • TSDF Integration
    • Customized Integration
    • Ray Casting in a Voxel Block Grid
    • Dense RGB-D SLAM
  • Sensor
    • Azure Kinect with Open3D
    • RealSense with Open3D
  • Reference

Python API

  • open3d.camera
    • PinholeCameraIntrinsic
    • PinholeCameraIntrinsicParameters
    • PinholeCameraParameters
    • PinholeCameraTrajectory
  • open3d.core
    • Blob
    • Device
    • Dtype
    • DynamicSizeVector
    • HashMap
    • HashSet
    • Scalar
    • SizeVector
    • Tensor
    • capsule
    • addmm
    • append
    • concatenate
    • det
    • inv
    • lstsq
    • lu
    • lu_ipiv
    • matmul
    • maximum
    • minimum
    • solve
    • svd
    • sycl_demo
    • tril
    • triu
    • triul
    • nns
      • NearestNeighborSearch
  • open3d.data
    • ArmadilloMesh
    • AvocadoModel
    • BedroomRGBDImages
    • BunnyMesh
    • CrateModel
    • DamagedHelmetModel
    • DataDescriptor
    • Dataset
    • DemoColoredICPPointClouds
    • DemoCropPointCloud
    • DemoCustomVisualization
    • DemoDopplerICPSequence
    • DemoFeatureMatchingPointClouds
    • DemoICPPointClouds
    • DemoPoseGraphOptimization
    • DownloadDataset
    • EaglePointCloud
    • FlightHelmetModel
    • JackJackL515Bag
    • JuneauImage
    • KnotMesh
    • LivingRoomPointClouds
    • LoungeRGBDImages
    • MetalTexture
    • MonkeyModel
    • OfficePointClouds
    • PCDPointCloud
    • PLYPointCloud
    • PaintedPlasterTexture
    • RedwoodIndoorLivingRoom1
    • RedwoodIndoorLivingRoom2
    • RedwoodIndoorOffice1
    • RedwoodIndoorOffice2
    • SampleFountainRGBDImages
    • SampleL515Bag
    • SampleNYURGBDImage
    • SampleRedwoodRGBDImages
    • SampleSUNRGBDImage
    • SampleTUMRGBDImage
    • SwordModel
    • TerrazzoTexture
    • TilesTexture
    • WoodFloorTexture
    • WoodTexture
  • open3d.geometry
    • AxisAlignedBoundingBox
    • DeformAsRigidAsPossibleEnergy
    • FilterScope
    • Geometry
    • Geometry2D
    • Geometry3D
    • HalfEdge
    • HalfEdgeTriangleMesh
    • Image
    • ImageFilterType
    • KDTreeFlann
    • KDTreeSearchParam
    • KDTreeSearchParamHybrid
    • KDTreeSearchParamKNN
    • KDTreeSearchParamRadius
    • LineSet
    • MeshBase
    • Octree
    • OctreeColorLeafNode
    • OctreeInternalNode
    • OctreeInternalPointNode
    • OctreeLeafNode
    • OctreeNode
    • OctreeNodeInfo
    • OctreePointColorLeafNode
    • OrientedBoundingBox
    • PointCloud
    • RGBDImage
    • SimplificationContraction
    • TetraMesh
    • TriangleMesh
    • Voxel
    • VoxelGrid
    • get_rotation_matrix_from_axis_angle
    • get_rotation_matrix_from_quaternion
    • get_rotation_matrix_from_xyz
    • get_rotation_matrix_from_xzy
    • get_rotation_matrix_from_yxz
    • get_rotation_matrix_from_yzx
    • get_rotation_matrix_from_zxy
    • get_rotation_matrix_from_zyx
  • open3d.io
    • AzureKinectMKVMetadata
    • AzureKinectMKVReader
    • AzureKinectRecorder
    • AzureKinectSensor
    • AzureKinectSensorConfig
    • FileGeometry
    • read_azure_kinect_mkv_metadata
    • read_azure_kinect_sensor_config
    • read_feature
    • read_file_geometry_type
    • read_image
    • read_line_set
    • read_octree
    • read_pinhole_camera_intrinsic
    • read_pinhole_camera_parameters
    • read_pinhole_camera_trajectory
    • read_point_cloud
    • read_point_cloud_from_bytes
    • read_pose_graph
    • read_triangle_mesh
    • read_triangle_model
    • read_voxel_grid
    • write_azure_kinect_mkv_metadata
    • write_azure_kinect_sensor_config
    • write_feature
    • write_image
    • write_line_set
    • write_octree
    • write_pinhole_camera_intrinsic
    • write_pinhole_camera_parameters
    • write_pinhole_camera_trajectory
    • write_point_cloud
    • write_point_cloud_to_bytes
    • write_pose_graph
    • write_triangle_mesh
    • write_voxel_grid
    • rpc
      • BufferConnection
      • Connection
      • destroy_zmq_context
      • data_buffer_to_meta_geometry
      • set_active_camera
      • set_legacy_camera
      • set_mesh_data
      • set_point_cloud
      • set_time
      • set_triangle_mesh
  • open3d.t
    • geometry
      • AxisAlignedBoundingBox
      • DrawableGeometry
      • Geometry
      • Image
      • InterpType
      • LineSet
      • Metric
      • MetricParameters
      • OrientedBoundingBox
      • PointCloud
      • RGBDImage
      • RaycastingScene
      • TensorMap
      • TriangleMesh
      • VectorMetric
      • VoxelBlockGrid
    • io
      • DepthNoiseSimulator
      • RGBDSensor
      • RGBDVideoMetadata
      • RGBDVideoReader
      • RSBagReader
      • RealSenseSensor
      • RealSenseSensorConfig
      • RealSenseValidConfigs
      • SensorType
      • read_image
      • read_point_cloud
      • read_triangle_mesh
      • write_image
      • write_point_cloud
      • write_triangle_mesh
    • pipelines
      • odometry
        • Method
        • OdometryConvergenceCriteria
        • OdometryLossParams
        • OdometryResult
        • compute_odometry_information_matrix
        • compute_odometry_result_hybrid
        • compute_odometry_result_intensity
        • compute_odometry_result_point_to_plane
        • rgbd_odometry_multi_scale
      • registration
        • ICPConvergenceCriteria
        • RegistrationResult
        • TransformationEstimation
        • TransformationEstimationForColoredICP
        • TransformationEstimationForDopplerICP
        • TransformationEstimationPointToPlane
        • TransformationEstimationPointToPoint
        • compute_fpfh_feature
        • correspondences_from_features
        • evaluate_registration
        • get_information_matrix
        • icp
        • multi_scale_icp
      • slac
        • control_grid
        • slac_debug_option
        • slac_optimizer_params
        • run_rigid_optimizer_for_fragments
        • run_slac_optimizer_for_fragments
        • save_correspondences_for_pointclouds
      • slam
        • Frame
        • Model
  • open3d.ml
    • tf
      • dataloaders
        • TFDataloader
      • datasets
        • Argoverse
        • Custom3D
        • InferenceDummySplit
        • KITTI
        • Lyft
        • MatterportObjects
        • NuScenes
        • ParisLille3D
        • S3DIS
        • Scannet
        • SemSegRandomSampler
        • SemSegSpatiallyRegularSampler
        • Semantic3D
        • SemanticKITTI
        • ShapeNet
        • SunRGBD
        • TUMFacade
        • Toronto3D
        • Waymo
        • augment
          • ObjdetAugmentation
          • SemsegAugmentation
        • utils
          • BEVBox3D
          • DataProcessing
          • ObjdetAugmentation
          • create_3D_rotations
          • get_min_bbox
          • trans_augment
          • trans_crop_pc
          • trans_normalize
      • layers
        • ContinuousConv
        • FixedRadiusSearch
        • KNNSearch
        • RadiusSearch
        • SparseConv
        • SparseConvTranspose
        • VoxelPooling
      • models
        • KPFCNN
        • PVCNN
        • PointPillars
        • PointRCNN
        • PointTransformer
        • RandLANet
        • SparseConvUnet
      • modules
        • losses
          • CrossEntropyLoss
          • FocalLoss
          • SemSegLoss
          • SmoothL1Loss
        • metrics
          • SemSegMetric
      • ops
        • build_spatial_hash_table
        • continuous_conv
        • continuous_conv_backprop_filter
        • continuous_conv_transpose
        • continuous_conv_transpose_backprop_filter
        • fixed_radius_search
        • invert_neighbors_list
        • knn_search
        • nms
        • radius_search
        • reduce_subarrays_sum
        • voxel_pooling
        • voxel_pooling_grad
        • voxelize
      • pipelines
        • ObjectDetection
        • SemanticSegmentation
      • vis
        • BoundingBox3D
        • Colormap
        • DataModel
        • DatasetModel
        • LabelLUT
        • Model
        • Visualizer
        • deque
        • rgb_to_yiq
    • torch
      • classes
        • RaggedTensor
      • dataloaders
        • ConcatBatcher
        • DefaultBatcher
        • TorchDataloader
        • get_sampler
      • datasets
        • Argoverse
        • Custom3D
        • InferenceDummySplit
        • KITTI
        • Lyft
        • MatterportObjects
        • NuScenes
        • ParisLille3D
        • S3DIS
        • Scannet
        • SemSegRandomSampler
        • SemSegSpatiallyRegularSampler
        • Semantic3D
        • SemanticKITTI
        • ShapeNet
        • SunRGBD
        • TUMFacade
        • Toronto3D
        • Waymo
        • augment
          • ObjdetAugmentation
          • SemsegAugmentation
        • samplers
          • SemSegRandomSampler
          • SemSegSpatiallyRegularSampler
        • utils
          • BEVBox3D
          • DataProcessing
          • ObjdetAugmentation
          • create_3D_rotations
          • get_min_bbox
          • trans_augment
          • trans_crop_pc
          • trans_normalize
      • layers
        • ContinuousConv
        • FixedRadiusSearch
        • KNNSearch
        • RadiusSearch
        • SparseConv
        • SparseConvTranspose
        • VoxelPooling
      • models
        • KPFCNN
        • PVCNN
        • PointPillars
        • PointRCNN
        • PointTransformer
        • RandLANet
        • SparseConvUnet
      • modules
        • losses
          • CrossEntropyLoss
          • FocalLoss
          • SemSegLoss
          • SmoothL1Loss
          • filter_valid_label
        • metrics
          • SemSegMetric
      • ops
        • build_spatial_hash_table
        • continuous_conv
        • continuous_conv_transpose
        • fixed_radius_search
        • invert_neighbors_list
        • knn_search
        • nms
        • radius_search
        • reduce_subarrays_sum
        • voxel_pooling
        • voxelize
      • pipelines
        • ObjectDetection
        • SemanticSegmentation
      • vis
        • BoundingBox3D
        • Colormap
        • DataModel
        • DatasetModel
        • LabelLUT
        • Model
        • Visualizer
        • deque
        • rgb_to_yiq
  • open3d.pipelines
    • color_map
      • NonRigidOptimizerOption
      • RigidOptimizerOption
      • run_non_rigid_optimizer
      • run_rigid_optimizer
    • integration
      • ScalableTSDFVolume
      • TSDFVolume
      • TSDFVolumeColorType
      • UniformTSDFVolume
    • odometry
      • OdometryOption
      • RGBDOdometryJacobian
      • RGBDOdometryJacobianFromColorTerm
      • RGBDOdometryJacobianFromHybridTerm
      • compute_correspondence
      • compute_rgbd_odometry
    • registration
      • CauchyLoss
      • CorrespondenceChecker
      • CorrespondenceCheckerBasedOnDistance
      • CorrespondenceCheckerBasedOnEdgeLength
      • CorrespondenceCheckerBasedOnNormal
      • FastGlobalRegistrationOption
      • Feature
      • GMLoss
      • GlobalOptimizationConvergenceCriteria
      • GlobalOptimizationGaussNewton
      • GlobalOptimizationLevenbergMarquardt
      • GlobalOptimizationMethod
      • GlobalOptimizationOption
      • HuberLoss
      • ICPConvergenceCriteria
      • L1Loss
      • L2Loss
      • PoseGraph
      • PoseGraphEdge
      • PoseGraphEdgeVector
      • PoseGraphNode
      • PoseGraphNodeVector
      • RANSACConvergenceCriteria
      • RegistrationResult
      • RobustKernel
      • TransformationEstimation
      • TransformationEstimationForColoredICP
      • TransformationEstimationForGeneralizedICP
      • TransformationEstimationPointToPlane
      • TransformationEstimationPointToPoint
      • TukeyLoss
      • compute_fpfh_feature
      • correspondences_from_features
      • evaluate_registration
      • get_information_matrix_from_point_clouds
      • global_optimization
      • registration_colored_icp
      • registration_fgr_based_on_correspondence
      • registration_fgr_based_on_feature_matching
      • registration_generalized_icp
      • registration_icp
      • registration_ransac_based_on_correspondence
      • registration_ransac_based_on_feature_matching
  • open3d.utility
    • DoubleVector
    • IntVector
    • Matrix3dVector
    • Matrix4dVector
    • Vector2dVector
    • Vector2iVector
    • Vector3dVector
    • Vector3iVector
    • Vector4iVector
    • VerbosityContextManager
    • VerbosityLevel
    • get_verbosity_level
    • reset_print_function
    • set_verbosity_level
  • open3d.visualization
    • ExternalVisualizer
    • Material
    • MeshColorOption
    • MeshShadeOption
    • O3DVisualizer
    • PickedPoint
    • PointColorOption
    • RenderOption
    • ScalarProperties
    • SelectedIndex
    • SelectionPolygonVolume
    • TextureMaps
    • VectorProperties
    • ViewControl
    • Visualizer
    • VisualizerWithEditing
    • VisualizerWithKeyCallback
    • VisualizerWithVertexSelection
    • draw
    • draw_geometries
    • draw_geometries_with_animation_callback
    • draw_geometries_with_custom_animation
    • draw_geometries_with_editing
    • draw_geometries_with_key_callbacks
    • draw_geometries_with_vertex_selection
    • read_selection_polygon_volume
    • gui
      • Application
      • Button
      • CheckableTextTreeCell
      • Checkbox
      • CollapsableVert
      • Color
      • ColorEdit
      • ColormapTreeCell
      • Combobox
      • Dialog
      • FileDialog
      • FontDescription
      • FontStyle
      • Horiz
      • ImageWidget
      • KeyEvent
      • KeyModifier
      • KeyName
      • LUTTreeCell
      • Label
      • Label3D
      • Layout1D
      • LayoutContext
      • ListView
      • Margins
      • Menu
      • MouseButton
      • MouseEvent
      • NumberEdit
      • ProgressBar
      • RadioButton
      • Rect
      • SceneWidget
      • ScrollableVert
      • Size
      • Slider
      • StackedWidget
      • TabControl
      • TextEdit
      • Theme
      • ToggleSwitch
      • TreeView
      • UIImage
      • VGrid
      • VectorEdit
      • Vert
      • Widget
      • WidgetProxy
      • WidgetStack
      • Window
      • WindowBase
    • rendering
      • Camera
      • ColorGrading
      • Gradient
      • MaterialRecord
      • OffscreenRenderer
      • Open3DScene
      • Renderer
      • Scene
      • TextureHandle
      • TriangleMeshModel
      • View
    • webrtc_server
      • call_http_api
      • disable_http_handshake
      • enable_webrtc
      • register_data_channel_message_callback
    • tensorboard_plugin.summary
      • add_3d

Python Examples

  • Camera
  • Geometry
    • Image
    • KD Tree
    • Octree
    • Point Cloud
    • Ray Casting
    • RGBD Image
    • Triangle Mesh
    • Voxel Grid
  • IO
  • Pipelines
  • Utility
  • Visualization

C++ API

  • C++ documentation

Contribute

  • Contributing to Open3D
  • Contribution methods
  • Open3D style guide

Docs Version

main main C++
0.19.0 (release) 0.19.0 C++ (release)
0.18.0 0.18.0 C++
0.17.0 0.17.0 C++
0.16.0 0.16.0 C++
0.15.1 0.15.1 C++
0.14.1 0.14.1 C++
0.13.0 0.13.0 C++
0.12.0 0.12.0 C++
0.11.1 0.11.1 C++
0.11.0 0.11.0 C++
0.10.0 0.10.0 C++
0.9.0 0.9.0 C++
0.8.0 0.8.0 C++
0.7.0 0.7.0 C++
0.6.0 0.6.0 C++
Back to top

open3d.ml.torch.ops.knn_search#

open3d.ml.torch.ops.knn_search(points, queries, k, points_row_splits, queries_row_splits, index_dtype=3, metric='L2', ignore_query_point=False, return_distances=False)#

Computes the indices of k nearest neighbors.

This op computes the neighborhood for each query point and returns the indices of the neighbors. The output format is compatible with the radius_search and fixed_radius_search ops and supports returning less than k neighbors if there are less than k points or ignore_query_point is enabled and the queries and points arrays are the same point cloud. The following example shows the usual case where the outputs can be reshaped to a [num_queries, k] tensor:

import tensorflow as tf
import open3d.ml.tf as ml3d

points = [
  [0.1,0.1,0.1],
  [0.5,0.5,0.5],
  [1.7,1.7,1.7],
  [1.8,1.8,1.8],
  [0.3,2.4,1.4]]

queries = [
    [1.0,1.0,1.0],
    [0.5,2.0,2.0],
    [0.5,2.1,2.2],
]

ans = ml3d.ops.knn_search(points, queries, k=2,
                    points_row_splits=[0,5],
                    queries_row_splits=[0,3],
                    return_distances=True)
# returns ans.neighbors_index      = [1, 2, 4, 2, 4, 2]
#         ans.neighbors_row_splits = [0, 2, 4, 6]
#         ans.neighbors_distance   = [0.75 , 1.47, 0.56, 1.62, 0.77, 1.85]
# Since there are more than k points and we do not ignore any points we can
# reshape the output to [num_queries, k] with
neighbors_index = tf.reshape(ans.neighbors_index, [3,2])
neighbors_distance = tf.reshape(ans.neighbors_distance, [3,2])


# or with pytorch
import torch
import open3d.ml.torch as ml3d

points = torch.Tensor([
  [0.1,0.1,0.1],
  [0.5,0.5,0.5],
  [1.7,1.7,1.7],
  [1.8,1.8,1.8],
  [0.3,2.4,1.4]])

queries = torch.Tensor([
    [1.0,1.0,1.0],
    [0.5,2.0,2.0],
    [0.5,2.1,2.2],
])

radii = torch.Tensor([1.0,1.0,1.0])

ans = ml3d.ops.knn_search(points, queries, k=2,
                          points_row_splits=torch.LongTensor([0,5]),
                          queries_row_splits=torch.LongTensor([0,3]),
                          return_distances=True)
# returns ans.neighbors_index      = [1, 2, 4, 2, 4, 2]
#         ans.neighbors_row_splits = [0, 2, 4, 6]
#         ans.neighbors_distance   = [0.75 , 1.47, 0.56, 1.62, 0.77, 1.85]
# Since there are more than k points and we do not ignore any points we can
# reshape the output to [num_queries, k] with
neighbors_index = ans.neighbors_index.reshape(3,2)
neighbors_distance = ans.neighbors_distance.reshape(3,2)

metric: Either L1 or L2. Default is L2

ignore_query_point: If true the points that coincide with the center of the

search window will be ignored. This excludes the query point if queries and

points are the same point cloud.

return_distances: If True the distances for each neighbor will be returned in

the output tensor neighbors_distances. If False a zero length Tensor will be returned for neighbors_distances.

points: The 3D positions of the input points.

queries: The 3D positions of the query points.

k: The number of nearest neighbors to search.

points_row_splits: 1D vector with the row splits information if points is

batched. This vector is [0, num_points] if there is only 1 batch item.

queries_row_splits: 1D vector with the row splits information if queries is

batched. This vector is [0, num_queries] if there is only 1 batch item.

neighbors_index: The compact list of indices of the neighbors. The

corresponding query point can be inferred from the neighbor_count_prefix_sum vector. Neighbors for the same point are sorted with respect to the distance.

Note that there is no guarantee that there will be exactly k neighbors in some cases. These cases are:

  • There are less than k points.

  • ignore_query_point is True and there are multiple points with the same position.

neighbors_row_splits: The exclusive prefix sum of the neighbor count for the

query points including the total neighbor count as the last element. The size of this array is the number of queries + 1.

neighbors_distance: Stores the distance to each neighbor if return_distances

is True. The distances are squared only if metric is L2. This is a zero length Tensor if return_distances is False.

Next
open3d.ml.torch.ops.nms
Previous
open3d.ml.torch.ops.invert_neighbors_list
Copyright © 2018 - 2023, www.open3d.org
Made with Sphinx and @pradyunsg's Furo
On this page
  • open3d.ml.torch.ops.knn_search
    • knn_search()