livecapture

package
v0.0.0-...-b509ac4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package livecapture provides a way to capture images from a live camera. It is a port of the live-capture script in cmd/.

Index

Constants

This section is empty.

Variables

View Source
var SupportedCameraFormats = []CameraFormat{
	FormatYUYV422,
	FormatMJPG,
}

SupportedCameraFormats is the list of supported camera formats.

View Source
var SupportedImageFormats = []ImageFormat{
	FormatBMP,
	FormatJPG,
	FormatPNG,
}

SupportedImageFormats is the list of supported image formats.

Functions

func IsSupported

func IsSupported[T ~string](s T, supported []T) bool

IsSupported returns whether the given string is a supported camera format.

Types

type Camera

type Camera struct {
	// Path is the path to the camera device.
	Path string
	// Size is the size of the camera image.
	Size image.Point
	// Format is the format of the camera image.
	Format CameraFormat
	// FrameRate is the frame rate of the camera.
	FrameRate int
}

Camera describes the options for a camera.

type CameraFormat

type CameraFormat string

CameraFormat describes the format of a camera image.

const (
	FormatYUYV422 CameraFormat = "yuyv422"
	FormatMJPG    CameraFormat = "mjpg"
)

type Capture

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

Capture describes a live-captured camera.

func NewCapture

func NewCapture(opts CaptureOpts) (*Capture, error)

NewCapture creates a new stopped camera.

func (*Capture) Snapshot

func (c *Capture) Snapshot(ctx context.Context) (image.Image, error)

Snapshot takes a snapshot from the camera and returns it. It is safe to call this method concurrently.

func (*Capture) SnapshotToFile

func (c *Capture) SnapshotToFile(ctx context.Context, dst string) error

SnapshotToFile takes a snapshot from the camera and writes it to the given file.

func (*Capture) Start

func (c *Capture) Start(ctx context.Context) error

Start starts the camera. It will block until the given context is canceled.

func (*Capture) View

func (c *Capture) View(ctx context.Context) error

View opens the camera image in an image viewer.

func (*Capture) WaitForFile

func (c *Capture) WaitForFile(ctx context.Context) error

WaitForFile waits for the image file to be created.

type CaptureOpts

type CaptureOpts struct {
	// Camera is the camera to capture from.
	Camera
	// ImagePath is the path to the image captured by the camera.
	// It will be continuously updated as the camera captures images.
	// It is recommended to use a BMP file in /run/user/1000 so that there's
	// minimum overhead in writing and reading the image.
	ImagePath string
	// FilterArgs are the arguments to pass to FFmpeg to filter the camera
	// image.
	FilterArgs []string
	// Image2Args are the arguments to pass to FFmpeg to add arguments to the
	// written image.
	Image2Args []string
}

CaptureOpts describes the options for a live-captured camera.

type ImageFormat

type ImageFormat string

ImageFormat describes the format of an image.

const (
	FormatBMP ImageFormat = "bmp"
	FormatJPG ImageFormat = "jpg"
	FormatPNG ImageFormat = "png"
)

Jump to

Keyboard shortcuts

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