videosource

package module
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 17 Imported by: 6

README

go-videosource

Package videosource provides a set of tools for working with video sources using gocv.

Go Reference Go Report Card

Documentation

Overview

Package videosource provides a set of tools for working with video sources using gocv.

Index

Constants

View Source
const (
	ActivityImage  = 0
	ActivityMotion = 1
	ActivityObject = 2
	ActivityFace   = 3
)

VideoWriter constants

Variables

This section is empty.

Functions

func CorrectRectangle

func CorrectRectangle(i Image, rect image.Rectangle) (result image.Rectangle)

CorrectRectangle will fix a rectangle to fit within the Image i

func GetBaseFilename

func GetBaseFilename(t time.Time, saveDirectory string, name string, title string, percentage string) string

GetBaseFilename will return a formatted base filename with current date time

func GetImageFilename

func GetImageFilename(t time.Time, saveDirectory string, name string, title string, percentage string) string

GetImageFilename will return an image filename

func GetVideoFilename

func GetVideoFilename(t time.Time, saveDirectory string, name string, fileType string, portable bool) (filename string)

GetVideoFilename will return a video filename

func RectAddHeight

func RectAddHeight(i Image, rect image.Rectangle, height int) (result image.Rectangle)

RectAddHeight will add height to the rect as evenly as possible

func RectAddWidth

func RectAddWidth(i Image, rect image.Rectangle, width int) (result image.Rectangle)

RectAddWidth will add width to the rect as evenly as possible

func RectOverlap

func RectOverlap(rect1 image.Rectangle, rect2 image.Rectangle) (percentage1 int, percentage2 int)

RectOverlap returns the rectangle's percentage overlapped by the other

func RectPadded

func RectPadded(i Image, rect image.Rectangle, paddingPercent int) (result image.Rectangle)

RectPadded returns a padded rectangle

func RectRect

func RectRect(i Image, rect image.Rectangle) (result image.Rectangle)

RectRect will return a rectangle that fits within the Image i

func RectRelative

func RectRelative(i Image, child image.Rectangle, parent image.Rectangle) (result image.Rectangle)

RectRelative returns a relative rectangle given child and parent rectangles

func RectScale

func RectScale(i Image, rect image.Rectangle, scale float64) (result image.Rectangle)

RectScale will scale the rect as evenly as possible

func RectSquare

func RectSquare(i Image, rect image.Rectangle) (result image.Rectangle)

RectSquare will return a square that fits within the Image i

func SaveImage

func SaveImage(img Image, t time.Time, saveDirectory string, jpegQuality int, name string, title string, percentage string) (savePath string)

SaveImage will save an Image

func SavePreview

func SavePreview(img Image, t time.Time, saveDirectory string, name string, title string, percentage string) (savePath string)

SavePreview will save a smaller Image

Types

type BaseVideo

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

BaseVideo contains common video source info

func NewBaseVideo

func NewBaseVideo(name string, sourceType SourceType) *BaseVideo

NewBaseVideo creates a new BaseVideo

func (*BaseVideo) Cleanup

func (b *BaseVideo) Cleanup()

Cleanup implements interface

func (*BaseVideo) GetConnectionStatus added in v1.18.0

func (b *BaseVideo) GetConnectionStatus() (status ConnectionStatus)

GetConnectionStatus implements interface

func (*BaseVideo) GetName

func (b *BaseVideo) GetName() string

GetName implements interface

func (*BaseVideo) GetSourceType added in v1.18.0

func (b *BaseVideo) GetSourceType() (sourceType SourceType)

GetSourceType implements interface

func (*BaseVideo) Initialize

func (b *BaseVideo) Initialize() (ok bool)

Initialize implements interface

func (*BaseVideo) ReadImage

func (b *BaseVideo) ReadImage() (done bool, image Image)

ReadImage implements interface

type Color

type Color int

Color represents a color

const (
	Blue Color = iota
	Purple
	Green
	Red
	White
)

Color Constants

func StringToColor

func StringToColor(name string) Color

StringToColor returns a Color

func (Color) GetRGBA

func (c Color) GetRGBA() color.RGBA

GetRGBA returns the color rgba

func (Color) String

func (c Color) String() string

type ColorThickness

type ColorThickness struct {
	Color     Color
	Thickness int
}

func NewColorThickness

func NewColorThickness(color string, thickness int) *ColorThickness

type ConnectionStatus added in v1.18.0

type ConnectionStatus int

ConnectionStatus defines the state of the connection

const (
	Disconnected ConnectionStatus = iota
	Connecting
	Connected
)

type FaceInfo

type FaceInfo struct {
	Rect          image.Rectangle
	Percentage    int
	HighlightInfo ColorThickness
}

FaceInfo contains the face information

func NewFaceInfo

func NewFaceInfo(rect image.Rectangle, colorThickness ColorThickness) *FaceInfo

NewFaceInfo creates a new FaceInfo

func (*FaceInfo) Cleanup

func (f *FaceInfo) Cleanup()

Cleanup will cleanup the FaceInfo

func (*FaceInfo) Clone

func (f *FaceInfo) Clone() *FaceInfo

Clone will clone the FaceInfo

func (*FaceInfo) Ref

func (f *FaceInfo) Ref() *FaceInfo

Ref will create a copy and reference the underlying SharedMat

type FileSource

type FileSource struct {
	BaseVideo
	// contains filtered or unexported fields
}

FileSource is a file source

func NewFileSource

func NewFileSource(name string, filename string) *FileSource

NewFileSource creates a new FileSource

func (*FileSource) Cleanup

func (f *FileSource) Cleanup()

Cleanup implements interface

func (*FileSource) Initialize

func (f *FileSource) Initialize() (ok bool)

Initialize implements interface

func (*FileSource) ReadImage

func (f *FileSource) ReadImage() (done bool, image Image)

ReadImage implements interface

type FrameStats

type FrameStats struct {
	AcceptedTotal     int
	AcceptedPerSecond int
	DroppedTotal      int
	DroppedPerSecond  int
}

func (FrameStats) String added in v1.5.0

func (f FrameStats) String() string

type FrameStatsCombo

type FrameStatsCombo struct {
	In  FrameStats
	Out FrameStats
}

type IPCamSource

type IPCamSource struct {
	BaseVideo
	// contains filtered or unexported fields
}

IPCamSource is a ipcam source

func NewIPCamSource

func NewIPCamSource(name string, url string) *IPCamSource

NewIPCamSource creates a new IPCamSource

func (*IPCamSource) Cleanup

func (i *IPCamSource) Cleanup()

Cleanup implements interface

func (*IPCamSource) Initialize

func (i *IPCamSource) Initialize() (ok bool)

Initialize implements interface

func (*IPCamSource) ReadImage

func (i *IPCamSource) ReadImage() (done bool, image Image)

ReadImage implements interface

func (*IPCamSource) SetCaptureTimeoutMs added in v1.18.0

func (i *IPCamSource) SetCaptureTimeoutMs(captureTimeoutMs int)

type Image

type Image struct {
	SharedMat *sharedmat.SharedMat
	// contains filtered or unexported fields
}

Image contains an image

func NewImage

func NewImage(mat gocv.Mat) *Image

NewImage creates a new Image

func (*Image) ChangeQuality

func (i *Image) ChangeQuality(percent int) Image

ChangeQuality will return a copy of the Image with the quality set to percent

func (*Image) Cleanup

func (i *Image) Cleanup()

Cleanup will cleanup the Image

func (*Image) Clone

func (i *Image) Clone() *Image

Clone will clone the Image

func (*Image) CreatedTime

func (i *Image) CreatedTime() time.Time

func (*Image) EncodedQuality

func (i *Image) EncodedQuality(percent int) []byte

EncodedQuality returns a JPEG byte array with the given quality percentage

func (*Image) GetRegion

func (i *Image) GetRegion(rect image.Rectangle) (region Image)

GetRegion will return a new Image per rectangle parameter

func (*Image) Height

func (i *Image) Height() int

Height returns the Image height or -1

func (*Image) IsFilled

func (i *Image) IsFilled() bool

IsFilled checks the underlying image not empty

func (*Image) Ref

func (i *Image) Ref() *Image

Ref will create a copy and reference the underlying SharedMat

func (*Image) ScaleToWidth

func (i *Image) ScaleToWidth(width int) Image

ScaleToWidth will return a copy of the Image to scale given the width

func (*Image) Width

func (i *Image) Width() int

Width returns the Image width or -1

type ImageByCreatedTime

type ImageByCreatedTime []Image

ImageByCreatedTime sorting ascending order

func (ImageByCreatedTime) Len

func (b ImageByCreatedTime) Len() int

func (ImageByCreatedTime) Less

func (b ImageByCreatedTime) Less(i, j int) bool

func (ImageByCreatedTime) Swap

func (b ImageByCreatedTime) Swap(i, j int)

type MotionInfo

type MotionInfo struct {
	Rect          image.Rectangle
	HighlightInfo ColorThickness
}

MotionInfo contains the motion information

func NewMotionInfo

func NewMotionInfo(rect image.Rectangle, colorThickness ColorThickness) *MotionInfo

NewMotionInfo creates a new MotionInfo

func (*MotionInfo) Cleanup

func (m *MotionInfo) Cleanup()

Cleanup will cleanup the MotionInfo

func (*MotionInfo) Clone

func (m *MotionInfo) Clone() *MotionInfo

Clone will clone the MotionInfo

func (*MotionInfo) Ref

func (m *MotionInfo) Ref() *MotionInfo

Ref will create a copy and reference the underlying SharedMat

type ObjectInfo

type ObjectInfo struct {
	Rect          image.Rectangle
	Description   string
	Percentage    int
	HighlightInfo ColorThickness
}

ObjectInfo contains the object information

func NewObjectInfo

func NewObjectInfo(rect image.Rectangle, colorThickness ColorThickness) *ObjectInfo

NewObjectInfo creates a new ObjectInfo

func (*ObjectInfo) Cleanup

func (o *ObjectInfo) Cleanup()

Cleanup will cleanup the ObjectInfo

func (*ObjectInfo) Clone

func (o *ObjectInfo) Clone() *ObjectInfo

Clone will clone the ObjectInfo

func (*ObjectInfo) Ref

func (o *ObjectInfo) Ref() *ObjectInfo

Ref will create a copy and reference the underlying SharedMat

type ProcessedImage

type ProcessedImage struct {
	Original Image
	Motions  []MotionInfo
	Objects  []ObjectInfo
	Faces    []FaceInfo
}

ProcessedImage is the result of running through the processes

func NewProcessedImage

func NewProcessedImage(original Image) *ProcessedImage

NewProcessedImage creates a new ProcessedImage

func (*ProcessedImage) Cleanup

func (p *ProcessedImage) Cleanup()

Cleanup will cleanup the ProcessedImage

func (*ProcessedImage) Clone

func (p *ProcessedImage) Clone() *ProcessedImage

Clone will clone the ProcessedImage

func (*ProcessedImage) CreatedTime added in v1.9.0

func (p *ProcessedImage) CreatedTime() time.Time

func (ProcessedImage) Face

func (p ProcessedImage) Face(index int) *Image

func (*ProcessedImage) HasFace

func (p *ProcessedImage) HasFace() bool

func (*ProcessedImage) HasMotion

func (p *ProcessedImage) HasMotion() bool

func (*ProcessedImage) HasObject

func (p *ProcessedImage) HasObject() bool

func (*ProcessedImage) HighlightedAll

func (p *ProcessedImage) HighlightedAll() *Image

func (*ProcessedImage) HighlightedFace

func (p *ProcessedImage) HighlightedFace() *Image

func (*ProcessedImage) HighlightedMotion

func (p *ProcessedImage) HighlightedMotion() *Image

func (*ProcessedImage) HighlightedObject

func (p *ProcessedImage) HighlightedObject() *Image

func (ProcessedImage) Motion

func (p ProcessedImage) Motion(index int) *Image

func (ProcessedImage) Object

func (p ProcessedImage) Object(index int) *Image

func (*ProcessedImage) Ref

func (p *ProcessedImage) Ref() *ProcessedImage

Ref will create a copy and reference the underlying SharedMat

type ProcessedImageByCreatedTime

type ProcessedImageByCreatedTime []ProcessedImage

ProcessedImageByCreatedTime sorting ascending order

func (ProcessedImageByCreatedTime) Len

func (ProcessedImageByCreatedTime) Less

func (b ProcessedImageByCreatedTime) Less(i, j int) bool

func (ProcessedImageByCreatedTime) Swap

func (b ProcessedImageByCreatedTime) Swap(i, j int)

type ProcessedImageByFaceLen

type ProcessedImageByFaceLen []ProcessedImage

ProcessedImageByFaceLen sorting descending order

func (ProcessedImageByFaceLen) Len

func (b ProcessedImageByFaceLen) Len() int

func (ProcessedImageByFaceLen) Less

func (b ProcessedImageByFaceLen) Less(i, j int) bool

func (ProcessedImageByFaceLen) Swap

func (b ProcessedImageByFaceLen) Swap(i, j int)

type ProcessedImageByFacePercent

type ProcessedImageByFacePercent []ProcessedImage

ProcessedImageByFacePercent sorting descending order

func (ProcessedImageByFacePercent) Len

func (ProcessedImageByFacePercent) Less

func (b ProcessedImageByFacePercent) Less(i, j int) bool

func (ProcessedImageByFacePercent) Swap

func (b ProcessedImageByFacePercent) Swap(i, j int)

type ProcessedImageByObjLen

type ProcessedImageByObjLen []ProcessedImage

ProcessedImageByObjLen sorting descending order

func (ProcessedImageByObjLen) Len

func (b ProcessedImageByObjLen) Len() int

func (ProcessedImageByObjLen) Less

func (b ProcessedImageByObjLen) Less(i, j int) bool

func (ProcessedImageByObjLen) Swap

func (b ProcessedImageByObjLen) Swap(i, j int)

type ProcessedImageByObjPercent

type ProcessedImageByObjPercent []ProcessedImage

ProcessedImageByObjPercent sorting descending order

func (ProcessedImageByObjPercent) Len

func (ProcessedImageByObjPercent) Less

func (b ProcessedImageByObjPercent) Less(i, j int) bool

func (ProcessedImageByObjPercent) Swap

func (b ProcessedImageByObjPercent) Swap(i, j int)

type SourceType added in v1.18.0

type SourceType int

SourceType defines the type of the source

const (
	UnknownType SourceType = iota
	FileSourceType
	IPCamSourceType
)

type VideoReader

type VideoReader struct {
	MaxSourceFps  int
	MaxOutputFps  int
	Quality       int
	Speed         float64
	DropTimeoutMs int
	// contains filtered or unexported fields
}

VideoReader reads a VideoSource

func NewVideoReader

func NewVideoReader(videoSource VideoSource, maxSourceFps int, maxOutputFps int) *VideoReader

NewVideoReader creates a new VideoReader

func (*VideoReader) GetConnectionStatus added in v1.18.0

func (v *VideoReader) GetConnectionStatus() ConnectionStatus

func (*VideoReader) GetFrameStatsOutput added in v1.5.0

func (v *VideoReader) GetFrameStatsOutput() (result *FrameStats)

GetFrameStatsOutput returns the FrameStats directly

func (*VideoReader) GetFrameStatsSource added in v1.5.0

func (v *VideoReader) GetFrameStatsSource() (result *FrameStats)

GetFrameStatsSource returns the FrameStats directly

func (*VideoReader) GetOutputStatsSub added in v1.1.1

func (v *VideoReader) GetOutputStatsSub() (result *pubsubmutex.Subscriber[*FrameStats])

GetOutputStatsSub returns the subscriber

func (*VideoReader) GetSourceStatsSub added in v1.1.1

func (v *VideoReader) GetSourceStatsSub() (result *pubsubmutex.Subscriber[*FrameStats])

GetSourceStatsSub returns the subscriber

func (*VideoReader) GetSourceType added in v1.18.0

func (v *VideoReader) GetSourceType() SourceType

func (*VideoReader) GetStatsOutput

func (v *VideoReader) GetStatsOutput(timeoutMs int) (result *FrameStats)

GetStatsOutput returns the FrameStats using pubsub

func (*VideoReader) GetStatsSource

func (v *VideoReader) GetStatsSource(timeoutMs int) (result *FrameStats)

GetStatsSource returns the FrameStats using pubsub

func (*VideoReader) SetQuality

func (v *VideoReader) SetQuality(percent int)

SetQuality sets the Image quality

func (*VideoReader) SetSpeed added in v1.16.0

func (v *VideoReader) SetSpeed(speed float64)

SetSpeed sets the speed of playback. Must be set prior to start.

func (*VideoReader) Start

func (v *VideoReader) Start() <-chan Image

Start runs the processes

func (*VideoReader) Stop

func (v *VideoReader) Stop()

Stop will stop the processes

func (*VideoReader) Wait

func (v *VideoReader) Wait()

Wait for done

type VideoSource

type VideoSource interface {
	GetName() string
	Initialize() (ok bool)
	Cleanup()
	ReadImage() (done bool, image Image)
	GetConnectionStatus() (status ConnectionStatus)
	GetSourceType() (sourceType SourceType)
}

VideoSource interface for setting up and reading images

type VideoStats

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

VideoStats contains video statistics

func NewVideoStats

func NewVideoStats() *VideoStats

NewVideoStats creates a new VideoStats

func (*VideoStats) AddAccepted

func (v *VideoStats) AddAccepted()

AddAccepted adds an accepted image

func (*VideoStats) AddDropped

func (v *VideoStats) AddDropped()

AddDropped adds a dropped image

func (*VideoStats) Close added in v1.5.0

func (v *VideoStats) Close()

func (*VideoStats) GetFrameStats added in v1.5.0

func (v *VideoStats) GetFrameStats() *FrameStats

GetFrameStats returns the FrameStats directly

func (*VideoStats) GetStats

func (v *VideoStats) GetStats(timeoutMs int) (result *FrameStats)

GetStats returns the FrameStats using pubsub

func (*VideoStats) GetStatsSub added in v1.5.0

func (v *VideoStats) GetStatsSub() (result *pubsubmutex.Subscriber[*FrameStats])

GetStatsSub returns the subscriber

func (*VideoStats) Start added in v1.5.0

func (v *VideoStats) Start()

type VideoWriter

type VideoWriter struct {
	PortableWidth int
	// contains filtered or unexported fields
}

VideoWriter writes Images

func NewVideoWriter

func NewVideoWriter(name string, saveDirectory string, codec string, fileType string, bufferSeconds int,
	maxPreSec int, timeoutSec int, maxSec int, outFps int, savePreview bool, savePortable bool, saveFull bool, activityType int) *VideoWriter

NewVideoWriter creates a new VideoWriter

func (*VideoWriter) Close

func (v *VideoWriter) Close()

Close notified by caller that input stream is done/closed

func (*VideoWriter) GetFrameStats added in v1.5.0

func (v *VideoWriter) GetFrameStats() (result *FrameStats)

GetFrameStats returns the FrameStats directly

func (*VideoWriter) GetStats

func (v *VideoWriter) GetStats(timeoutMs int) (result *FrameStats)

GetStats returns the FrameStats using pubsub

func (*VideoWriter) GetStatsSub added in v1.5.0

func (v *VideoWriter) GetStatsSub() (result *pubsubmutex.Subscriber[*FrameStats])

GetStatsSub returns the subscriber

func (*VideoWriter) IsDone added in v1.9.0

func (v *VideoWriter) IsDone() bool

func (*VideoWriter) Send

func (v *VideoWriter) Send(img ProcessedImage)

Send Image to write

func (*VideoWriter) Start

func (v *VideoWriter) Start()

Start runs the processes

func (*VideoWriter) Trigger

func (v *VideoWriter) Trigger()

Trigger to start recording

func (*VideoWriter) Wait

func (v *VideoWriter) Wait()

Wait until done

Jump to

Keyboard shortcuts

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