segmentation

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2022 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package segmentation implements object segmentation algorithms.

Index

Constants

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 ApplyRadiusClusteringVoxels

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

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

func ColorObjects

func ColorObjects(ctx context.Context, cam camera.Camera, params config.AttributeMap) ([]*vision.Object, error)

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

func GetPointCloudPositions

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

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

func RadiusClustering

func RadiusClustering(ctx context.Context, c camera.Camera, params config.AttributeMap) ([]*vision.Object, error)

RadiusClustering is 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 RadiusClusteringFromVoxels

func RadiusClusteringFromVoxels(ctx context.Context, c camera.Camera, params config.AttributeMap) ([]*vision.Object, error)

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

func RadiusClusteringOnPointCloud

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

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

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 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 {
	Tolerance      float64 `json:"tolerance"`
	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"`
}

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 config.AttributeMap) error

ConvertAttributes changes the AttributeMap input into a ColorObjectsConfig.

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)
}

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

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 {
	MinPtsInPlane      int     `json:"min_points_in_plane"`
	MinPtsInSegment    int     `json:"min_points_in_segment"`
	ClusteringRadiusMm float64 `json:"clustering_radius_mm"`
	MeanKFiltering     int     `json:"mean_k_filtering"`
}

RadiusClusteringConfig specifies the necessary parameters for 3D object finding.

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 config.AttributeMap) error

ConvertAttributes changes the AttributeMap input into a RadiusClusteringConfig.

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"`
	MinPtsInSegment    int     `json:"min_points_in_segment"`
	ClusteringRadiusMm float64 `json:"clustering_radius_mm"`
	WeightThresh       float64 `json:"weight_threshold"`
	AngleThresh        float64 `json:"angle_threshold"` // in degrees
	CosineThresh       float64 `json:"cosine_threshold"`
	DistanceThresh     float64 `json:"distance_threshold"`
}

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 config.AttributeMap) error

ConvertAttributes changes the AttributeMap input into a RadiusClusteringVoxelConfig.

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 golog.Logger,
) (*SegmentedImage, error)

ShapeWalk TODO.

func ShapeWalkEntireDebug

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

ShapeWalkEntireDebug TODO.

func ShapeWalkMultiple

func ShapeWalkMultiple(
	img *rimage.Image, dm *rimage.DepthMap,
	starts []image.Point,
	options ShapeWalkOptions,
	logger golog.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, c camera.Camera, parameters config.AttributeMap) ([]*vision.Object, error)

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

func DetectionSegmenter

func DetectionSegmenter(detector objectdetection.Detector) (Segmenter, []utils.TypedName, 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.

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) (*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"` // in degrees
	CosineThresh   float64 `json:"cosine_threshold"`
	DistanceThresh float64 `json:"distance_threshold"`
}

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