objectdetection

package
v0.2.41 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: AGPL-3.0 Imports: 14 Imported by: 6

Documentation

Overview

Package objectdetection defines a functional way to create object detection pipelines by feeding in images from a gostream.VideoSource source.

Index

Constants

View Source
const WaitForMs = 2000

WaitForMs tells us the number of milliseconds to wait on the channel for.

Variables

This section is empty.

Functions

func Overlay

func Overlay(img image.Image, dets []Detection) (image.Image, error)

Overlay returns a color image with the bounding boxes overlaid on the original image.

func OverlayText

func OverlayText(img image.Image, text string) image.Image

OverlayText writes a string in the top of the image.

Types

type ColorDetectorConfig

type ColorDetectorConfig struct {
	resource.TriviallyValidateConfig
	SegmentSize       int     `json:"segment_size_px"`
	HueTolerance      float64 `json:"hue_tolerance_pct"`
	SaturationCutoff  float64 `json:"saturation_cutoff_pct,omitempty"`
	ValueCutoff       float64 `json:"value_cutoff_pct,omitempty"`
	DetectColorString string  `json:"detect_color"` // hex string "#RRGGBB"
	Label             string  `json:"label,omitempty"`
}

ColorDetectorConfig specifies the fields necessary for creating a color detector.

type Detection

type Detection interface {
	BoundingBox() *image.Rectangle
	Score() float64
	Label() string
}

Detection returns a bounding box around the object and a confidence score of the detection.

func NewDetection

func NewDetection(boundingBox image.Rectangle, score float64, label string) Detection

NewDetection creates a simple 2D detection.

type Detector

type Detector func(context.Context, image.Image) ([]Detection, error)

Detector returns a slice of object detections from an input image.

func Build

func Build(prep Preprocessor, det Detector, post Postprocessor) (Detector, error)

Build zips up a preprocessor-detector-postprocessor stream into a detector.

func NewColorDetector

func NewColorDetector(cfg *ColorDetectorConfig) (Detector, error)

NewColorDetector is a detector that identifies objects based on color. It takes in a hue value between 0 and 360, and then defines a valid range around the hue of that color based on the tolerance. The color is considered valid if the pixel is between (hue - tol) <= color <= (hue + tol) and if the saturation and value level are above their cutoff points.

type Postprocessor

type Postprocessor func([]Detection) []Detection

Postprocessor defines a function that filters/modifies on an incoming array of Detections.

func NewAreaFilter

func NewAreaFilter(area int) Postprocessor

NewAreaFilter returns a function that filters out detections below a certain area.

func NewScoreFilter

func NewScoreFilter(conf float64) Postprocessor

NewScoreFilter returns a function that filters out detections below a certain confidence.

func SortByArea

func SortByArea() Postprocessor

SortByArea returns a function that sorts the list of detections by area (largest first).

type Preprocessor

type Preprocessor func(image.Image) image.Image

Preprocessor will apply processing to an input image before feeding it into the detector.

func ComposePreprocessors

func ComposePreprocessors(pSlice []Preprocessor) Preprocessor

ComposePreprocessors takes in a slice of Preprocessors and returns one Preprocessor function.

func RemoveColorChannel

func RemoveColorChannel(col string) (Preprocessor, error)

RemoveColorChannel will set the requested channel color to 0 in every picture. only "R", "G", and "B" are allowed.

type Result

type Result struct {
	OriginalImage image.Image
	Detections    []Detection
	Release       func()
	Err           error
}

Result holds all useful information for the detector: contains the original image, the preprocessed image, and the final detections.

type Source

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

Source pulls an image from src and applies the detector pipeline to it, resulting in an image overlaid with detections. Fulfills gostream.VideoReader interface.

func NewSource

func NewSource(src gostream.VideoSource, det Detector) (*Source, error)

NewSource builds the pipeline from an input VideoSource and Detector.

func (*Source) Close

func (s *Source) Close()

Close closes all the channels and threads.

func (*Source) NextResult

func (s *Source) NextResult(ctx context.Context) (*Result, error)

NextResult returns all the components required to build the overlaid image, but is useful if you only want the Detections.

func (*Source) Read added in v0.0.8

func (s *Source) Read(ctx context.Context) (image.Image, func(), error)

Read returns the original image overlaid with the found detections.

Directories

Path Synopsis
cmd
color_detection
Package main is a color detection tool.
Package main is a color detection tool.

Jump to

Keyboard shortcuts

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