segmentation

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2024 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package segmentation implements object segmentation algorithms.

Index

Constants

View Source
const (
	MaxCCLIterations            = 300000
	GridSize                    = 200
	MinPtsInPlaneDefault        = 500
	MaxDistFromPlaneDefault     = 100
	AngleToleranceDefault       = 30.0
	ClusteringRadiusDefault     = 5
	ClusteringStrictnessDefault = 1
)

MaxCCLIterations is a value to stop the CCL algo from going on for too long.

View Source
const (
	DefaultColorThreshold             = 1.0
	DefaultLookback                   = 15  // how many pixels do we ensure are similar
	DefaultLookbackScaling            = 6.0 // the bigger the number, the tighter the threshold
	DefaultInterestingThreshold       = .45
	DefaultInterestingRange           = 5
	DefaultAverageColorDistanceWeight = .5
)

TODO.

Variables

This section is empty.

Functions

func ApplyERCCLToPointCloud added in v0.11.0

func ApplyERCCLToPointCloud(ctx context.Context, cloud pc.PointCloud, cfg *ErCCLConfig) ([]*vision.Object, error)

ApplyERCCLToPointCloud clusters a point cloud according to the ER-CCL algorithm.

func GetPointCloudPositions

func GetPointCloudPositions(cloud pc.PointCloud) ([]r3.Vector, []pc.Data)

GetPointCloudPositions extracts the positions of the points from the pointcloud into a Vec3 slice.

func LabelMapUpdate added in v0.8.0

func LabelMapUpdate(labelMap [][]node, r int, alpha, beta, s float64) error

LabelMapUpdate updates the label map until it converges or errors.

func SegmentPlane

func SegmentPlane(ctx context.Context, cloud pc.PointCloud, nIterations int, threshold float64) (pc.Plane, pc.PointCloud, error)

SegmentPlane segments the biggest plane in the 3D Pointcloud. nIterations is the number of iteration for ransac nIter to choose? nIter = log(1-p)/log(1-(1-e)^s), where p is prob of success, e is outlier ratio, s is subset size (3 for plane). threshold is the float64 value for the maximum allowed distance to the found plane for a point to belong to it This function returns a Plane struct, as well as the remaining points in a pointcloud It also returns the equation of the found plane: [0]x + [1]y + [2]z + [3] = 0.

func SegmentPlaneWRTGround added in v0.7.0

func SegmentPlaneWRTGround(ctx context.Context, cloud pc.PointCloud, nIterations int, angleThreshold,
	dstThreshold float64, normalVec r3.Vector,
) (pc.Plane, pc.PointCloud, error)

SegmentPlaneWRTGround segments the biggest 'ground' plane in the 3D Pointcloud. nIterations is the number of iteration for ransac nIter to choose? nIter = log(1-p)/log(1-(1-e)^s), where p is prob of success, e is outlier ratio, s is subset size (3 for plane). dstThreshold is the float64 value for the maximum allowed distance to the found plane for a point to belong to it This function returns a Plane struct, as well as the remaining points in a pointcloud It also returns the equation of the found plane: [0]x + [1]y + [2]z + [3] = 0. angleThrehold is the maximum acceptable angle between the groundVec and angle of the plane, if the plane is at a larger angle than maxAngle, it will not be considered for segmentation, if set to 0 then not considered normalVec is the normal vector of the plane representing the ground.

func SplitPointCloudByPlane

func SplitPointCloudByPlane(cloud pc.PointCloud, plane pc.Plane) (pc.PointCloud, pc.PointCloud, error)

SplitPointCloudByPlane divides the point cloud in two point clouds, given the equation of a plane. one point cloud will have all the points above the plane and the other with all the points below the plane. Points exactly on the plane are not included!

func ThresholdPointCloudByPlane

func ThresholdPointCloudByPlane(cloud pc.PointCloud, plane pc.Plane, threshold float64) (pc.PointCloud, error)

ThresholdPointCloudByPlane returns a pointcloud with the points less than or equal to a given distance from a given plane.

Types

type ColorObjectsConfig

type ColorObjectsConfig struct {
	HueTolerance     float64 `json:"hue_tolerance_pct"`
	SaturationCutoff float64 `json:"saturation_cutoff_pct,omitempty"`
	ValueCutoff      float64 `json:"value_cutoff_pct,omitempty"`
	Color            string  `json:"detect_color"` // form #RRGGBB
	MeanK            int     `json:"mean_k"`       // used for StatisticalFilter
	Sigma            float64 `json:"sigma"`        // used for StatisticalFilter
	MinSegmentSize   int     `json:"min_points_in_segment"`
	Label            string  `json:"label,omitempty"`
}

ColorObjectsConfig specifies the necessary parameters for the color detection and transformation to 3D objects.

func (*ColorObjectsConfig) CheckValid

func (csc *ColorObjectsConfig) CheckValid() error

CheckValid checks to see in the input values are valid.

func (*ColorObjectsConfig) ConvertAttributes

func (csc *ColorObjectsConfig) ConvertAttributes(am utils.AttributeMap) error

ConvertAttributes changes the AttributeMap input into a ColorObjectsConfig.

type DetectionSegmenterConfig added in v0.1.0

type DetectionSegmenterConfig struct {
	resource.TriviallyValidateConfig
	DetectorName     string  `json:"detector_name"`
	ConfidenceThresh float64 `json:"confidence_threshold_pct"`
	MeanK            int     `json:"mean_k"`
	Sigma            float64 `json:"sigma"`
}

DetectionSegmenterConfig are the optional parameters to turn a detector into a segmenter.

func (*DetectionSegmenterConfig) ConvertAttributes added in v0.1.0

func (dsc *DetectionSegmenterConfig) ConvertAttributes(am utils.AttributeMap) error

ConvertAttributes changes the AttributeMap input into a DetectionSegmenterConfig.

type ErCCLConfig added in v0.8.0

type ErCCLConfig struct {
	resource.TriviallyValidateConfig
	MinPtsInPlane        int       `json:"min_points_in_plane"`
	MinPtsInSegment      int       `json:"min_points_in_segment"`
	MaxDistFromPlane     float64   `json:"max_dist_from_plane_mm"`
	NormalVec            r3.Vector `json:"ground_plane_normal_vec"`
	AngleTolerance       float64   `json:"ground_angle_tolerance_degs"`
	ClusteringRadius     int       `json:"clustering_radius"`
	ClusteringStrictness float64   `json:"clustering_strictness"`
}

ErCCLConfig specifies the necessary parameters to apply the connected components based clustering algo.

func (*ErCCLConfig) CheckValid added in v0.8.0

func (erCCL *ErCCLConfig) CheckValid() error

CheckValid checks to see in the input values are valid.

func (*ErCCLConfig) ConvertAttributes added in v0.8.0

func (erCCL *ErCCLConfig) ConvertAttributes(am utils.AttributeMap) error

ConvertAttributes changes the AttributeMap input into an ErCCLConfig.

func (*ErCCLConfig) ErCCLAlgorithm added in v0.8.0

func (erCCL *ErCCLConfig) ErCCLAlgorithm(ctx context.Context, src camera.VideoSource) ([]*vision.Object, error)

ErCCLAlgorithm applies the connected components clustering algorithm to a VideoSource.

type MyWalkError

type MyWalkError struct {
	// contains filtered or unexported fields
}

MyWalkError TODO.

func (MyWalkError) Error

func (e MyWalkError) Error() string

Error TODO.

type PlaneSegmentation

type PlaneSegmentation interface {
	FindPlanes(ctx context.Context) ([]pc.Plane, pc.PointCloud, error)
	FindGroundPlane(ctx context.Context) (pc.Plane, pc.PointCloud, error)
}

PlaneSegmentation is an interface used to find geometric planes in a 3D space.

func NewPointCloudGroundPlaneSegmentation added in v0.7.0

func NewPointCloudGroundPlaneSegmentation(cloud pc.PointCloud, distanceThreshold float64, minPoints int,
	angleThreshold float64, normalVec r3.Vector,
) PlaneSegmentation

NewPointCloudGroundPlaneSegmentation initializes the plane segmentation with the necessary parameters to find ground like planes, meaning they are less than angleThreshold away from the plane corresponding to normaLVec distanceThreshold is the float64 value for the maximum allowed distance to the found plane for a point to belong to it. minPoints is the minimum number of points necessary to be considered a plane.

func NewPointCloudPlaneSegmentation

func NewPointCloudPlaneSegmentation(cloud pc.PointCloud, threshold float64, minPoints int) PlaneSegmentation

NewPointCloudPlaneSegmentation initializes the plane segmentation with the necessary parameters to find the planes threshold is the float64 value for the maximum allowed distance to the found plane for a point to belong to it. minPoints is the minimum number of points necessary to be considered a plane.

func NewVoxelGridPlaneSegmentation

func NewVoxelGridPlaneSegmentation(vg *pc.VoxelGrid, config VoxelGridPlaneConfig) PlaneSegmentation

NewVoxelGridPlaneSegmentation initializes the necessary parameters needed to do plane segmentation on a voxel grid.

type RadiusClusteringConfig

type RadiusClusteringConfig struct {
	resource.TriviallyValidateConfig
	MinPtsInPlane      int       `json:"min_points_in_plane"`
	MaxDistFromPlane   float64   `json:"max_dist_from_plane_mm"`
	NormalVec          r3.Vector `json:"ground_plane_normal_vec"`
	AngleTolerance     float64   `json:"ground_angle_tolerance_degs"`
	MinPtsInSegment    int       `json:"min_points_in_segment"`
	ClusteringRadiusMm float64   `json:"clustering_radius_mm"`
	MeanKFiltering     int       `json:"mean_k_filtering"`
	Label              string    `json:"label,omitempty"`
}

RadiusClusteringConfig specifies the necessary parameters to apply the radius based clustering algo.

func (*RadiusClusteringConfig) CheckValid

func (rcc *RadiusClusteringConfig) CheckValid() error

CheckValid checks to see in the input values are valid.

func (*RadiusClusteringConfig) ConvertAttributes

func (rcc *RadiusClusteringConfig) ConvertAttributes(am utils.AttributeMap) error

ConvertAttributes changes the AttributeMap input into a RadiusClusteringConfig.

func (*RadiusClusteringConfig) RadiusClustering added in v0.1.0

func (rcc *RadiusClusteringConfig) RadiusClustering(ctx context.Context, src camera.VideoSource) ([]*vision.Object, error)

RadiusClustering applies the radius clustering algorithm directly on a given point cloud.

type RadiusClusteringVoxelConfig

type RadiusClusteringVoxelConfig struct {
	VoxelSize          float64 `json:"voxel_size"`
	Lambda             float64 `json:"lambda"` // clustering parameter for making voxel planes
	MinPtsInPlane      int     `json:"min_points_in_plane"`
	MaxDistFromPlane   float64 `json:"max_dist_from_plane"`
	MinPtsInSegment    int     `json:"min_points_in_segment"`
	ClusteringRadiusMm float64 `json:"clustering_radius_mm"`
	WeightThresh       float64 `json:"weight_threshold"`
	AngleThresh        float64 `json:"angle_threshold_degs"`
	CosineThresh       float64 `json:"cosine_threshold"` // between -1 and 1, the value after evaluating Cosine(theta)
	DistanceThresh     float64 `json:"distance_threshold_mm"`
	Label              string  `json:"label,omitempty"`
}

RadiusClusteringVoxelConfig specifies the necessary parameters for 3D object finding.

func (*RadiusClusteringVoxelConfig) CheckValid

func (rcc *RadiusClusteringVoxelConfig) CheckValid() error

CheckValid checks to see in the input values are valid.

func (*RadiusClusteringVoxelConfig) ConvertAttributes

func (rcc *RadiusClusteringVoxelConfig) ConvertAttributes(am utils.AttributeMap) error

ConvertAttributes changes the AttributeMap input into a RadiusClusteringVoxelConfig.

func (*RadiusClusteringVoxelConfig) RadiusClusteringVoxels added in v0.1.0

func (rcc *RadiusClusteringVoxelConfig) RadiusClusteringVoxels(ctx context.Context, src camera.VideoSource) ([]*vision.Object, error)

RadiusClusteringVoxels turns the cloud into a voxel grid and then does radius clustering to segment it.

type SegmentedImage

type SegmentedImage struct {
	// contains filtered or unexported fields
}

SegmentedImage TODO.

func PointCloudSegmentsToMask

func PointCloudSegmentsToMask(params transform.PinholeCameraIntrinsics, segments []pc.PointCloud) (*SegmentedImage, error)

PointCloudSegmentsToMask takes in an instrinsic camera matrix and a slice of pointclouds and projects each pointcloud down to an image.

func ShapeWalk

func ShapeWalk(img *rimage.Image, dm *rimage.DepthMap, start image.Point, options ShapeWalkOptions, logger logging.Logger,
) (*SegmentedImage, error)

ShapeWalk TODO.

func ShapeWalkEntireDebug

func ShapeWalkEntireDebug(img *rimage.Image, dm *rimage.DepthMap, options ShapeWalkOptions, logger logging.Logger,
) (*SegmentedImage, error)

ShapeWalkEntireDebug TODO.

func ShapeWalkMultiple

func ShapeWalkMultiple(
	img *rimage.Image, dm *rimage.DepthMap,
	starts []image.Point,
	options ShapeWalkOptions,
	logger logging.Logger,
) (*SegmentedImage, error)

ShapeWalkMultiple TODO.

func (*SegmentedImage) At

func (si *SegmentedImage) At(x, y int) color.Color

At TODO.

func (*SegmentedImage) Bounds

func (si *SegmentedImage) Bounds() image.Rectangle

Bounds TODO.

func (*SegmentedImage) ColorModel

func (si *SegmentedImage) ColorModel() color.Model

ColorModel TODO.

func (*SegmentedImage) GetSegment

func (si *SegmentedImage) GetSegment(p image.Point) int

GetSegment TODO.

func (*SegmentedImage) Height

func (si *SegmentedImage) Height() int

Height TODO.

func (*SegmentedImage) NumInAnyCluster

func (si *SegmentedImage) NumInAnyCluster() int

NumInAnyCluster TODO.

func (*SegmentedImage) PixelsInSegmemnt

func (si *SegmentedImage) PixelsInSegmemnt(segment int) int

PixelsInSegmemnt TODO.

func (*SegmentedImage) Width

func (si *SegmentedImage) Width() int

Width TODO.

type Segmenter

type Segmenter func(ctx context.Context, src camera.VideoSource) ([]*vision.Object, error)

A Segmenter is a function that takes images/pointclouds from an input source and segments them into objects.

func ColorObjects

func ColorObjects(params utils.AttributeMap) (Segmenter, error)

ColorObjects returns a Segmenter that turns the bounding boxes found by the ColorDetector into 3D objects.

func DetectionSegmenter

func DetectionSegmenter(detector objectdetection.Detector, meanK int, sigma, confidenceThresh float64) (Segmenter, error)

DetectionSegmenter will take an objectdetector.Detector and turn it into a Segementer. The params for the segmenter are "mean_k" and "sigma" for the statistical filter on the point clouds.

func NewERCCLClustering added in v0.8.0

func NewERCCLClustering(params utils.AttributeMap) (Segmenter, error)

NewERCCLClustering returns a Segmenter that removes the ground plane and returns a segmentation of the objects in a point cloud using a connected components clustering algo described in the paper "A Fast Spatial Clustering Method for Sparse LiDAR Point Clouds Using GPU Programming" by Tian et al. 2020.

func NewRadiusClustering added in v0.1.0

func NewRadiusClustering(params utils.AttributeMap) (Segmenter, error)

NewRadiusClustering returns a Segmenter that removes the planes (if any) and returns a segmentation of the objects in a point cloud using a radius based clustering algo described in the paper "A Clustering Method for Efficient Segmentation of 3D Laser Data" by Klasing et al. 2008.

func NewRadiusClusteringFromVoxels added in v0.1.0

func NewRadiusClusteringFromVoxels(params utils.AttributeMap) (Segmenter, error)

NewRadiusClusteringFromVoxels removes the planes (if any) and returns a segmentation of the objects in a point cloud.

type Segments

type Segments struct {
	Objects []*vision.Object
	Indices map[r3.Vector]int
}

Segments is a struct for keeping track of the individual objects of a point cloud as they are being built. Objects is a slice of all the objects, and Indices is a map that assigns each point to the object index it is a part of.

func NewSegments

func NewSegments() *Segments

NewSegments creates an empty new Segments struct.

func NewSegmentsFromSlice

func NewSegmentsFromSlice(clouds []pc.PointCloud, label string) (*Segments, error)

NewSegmentsFromSlice creates a Segments struct from a slice of point clouds.

func (*Segments) AssignCluster

func (c *Segments) AssignCluster(point r3.Vector, data pc.Data, index int) error

AssignCluster assigns the given point to the cluster with the given index.

func (*Segments) MergeClusters

func (c *Segments) MergeClusters(from, to int) error

MergeClusters moves all the points in index "from" to the segment at index "to".

func (*Segments) N

func (c *Segments) N() int

N gives the number of objects in the partition of the point cloud.

func (*Segments) PointClouds

func (c *Segments) PointClouds() []pc.PointCloud

PointClouds returns the underlying array of pointclouds.

func (*Segments) SelectPointCloudFromPoint

func (c *Segments) SelectPointCloudFromPoint(x, y, z float64) (pc.PointCloud, error)

SelectPointCloudFromPoint takes a 3D point as input and outputs the point cloud of the segment that the point belongs to.

type ShapeWalkOptions

type ShapeWalkOptions struct {
	Debug        bool
	MaxRadius    int // 0 means no max
	SkipCleaning bool
	ThresholdMod float64 // 0 means no modification > 0 means more things will match
	Diffs        *rimage.ColorDiffs
}

ShapeWalkOptions TODO.

type VoxelGridPlaneConfig

type VoxelGridPlaneConfig struct {
	WeightThresh   float64 `json:"weight_threshold"`
	AngleThresh    float64 `json:"angle_threshold_degs"`
	CosineThresh   float64 `json:"cosine_threshold"` // between -1 and 1, the value after evaluating Cosine(theta)
	DistanceThresh float64 `json:"distance_threshold_mm"`
}

VoxelGridPlaneConfig contains the parameters needed to create a Plane from a VoxelGrid.

func (*VoxelGridPlaneConfig) CheckValid

func (vgpc *VoxelGridPlaneConfig) CheckValid() error

CheckValid checks to see in the inputs values are valid.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL