raspicam

package module
v0.0.0-...-60ef25a Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2019 License: BSD-2-Clause Imports: 7 Imported by: 8

README

raspicam Go API

Build Status GoDoc

Provides a simple Go interface to the Raspberry Pi Camera board.

For the moment we call the existing command line tools, though eventually hope to hook directly into the C API.

We aim to create an idiomatic Go API whilst mirroring the functionality of the existing command line tools to allow for the best interoperability.

Status

Implemented:

  • Interface to raspistill
  • Interface to raspiyuv
  • Interface to raspivid

Todo:

  • More tests!

Installation

go get github.com/dhowden/raspicam

Getting Started

Write to a file
package main

import (
	"fmt"
	"log"
	"os"

	"github.com/dhowden/raspicam"
)

func main() {
	f, err := os.Create(os.Args[1])
	if err != nil {
		fmt.Fprintf(os.Stderr, "create file: %v", err)
		return
	}
	defer f.Close()

	s := raspicam.NewStill()
	errCh := make(chan error)
	go func() {
		for x := range errCh {
			fmt.Fprintf(os.Stderr, "%v\n", x)
		}
	}()
	log.Println("Capturing image...")
	raspicam.Capture(s, f, errCh)
}
Simple Raspicam TCP Server
package main

import (
	"log"
	"fmt"
	"net"
	"os"

	"github.com/dhowden/raspicam"
)

func main() {
	listener, err := net.Listen("tcp", "0.0.0.0:6666")
	if err != nil {
		fmt.Fprintf(os.Stderr, "listen: %v", err)
		return
	}
	log.Println("Listening on 0.0.0.0:6666")

	for {
		conn, err := listener.Accept()
		if err != nil {
			fmt.Fprintf(os.Stderr, "accept: %v", err)
			return
		}
		log.Printf("Accepted connection from: %v\n", conn.RemoteAddr())
		go func() {
			s := raspicam.NewStill()
			errCh := make(chan error)
			go func() {
				for x := range errCh {
					fmt.Fprintf(os.Stderr, "%v\n", x)
			}
			}()
			log.Println("Capturing image...")
			raspicam.Capture(s, conn, errCh)
			log.Println("Done")
			conn.Close()
		}()
	}
}

Documentation

Overview

Package raspicam provides basic Go APIs for interacting with the Raspberry Pi camera.

All captures are prepared by first creating a CaptureCommand (Still, StillYUV or Vid structs via calls to the NewStill, NewStillYUV or NewVid functions respectively). The Capture function can then be used to perform the capture.

Index

Constants

This section is empty.

Variables

View Source
var DefaultRaspiStillCommand = "raspistill"

DefaultRaspiStillCommand is the default command for capturing stills.

View Source
var DefaultRaspiStillYUVCommand = "raspiyuv"

DefaultRaspiStillYUVCommand is the default command for capturing YUV stills.

View Source
var DefaultRaspiVidCommmand = "raspivid"

DefaultRaspiVidCommmand is the default command for capturing video.

Functions

func Capture

func Capture(c CaptureCommand, w io.Writer, errCh chan<- error)

Capture runs the given CaptureCommand and writes the result to the given writer. Any errors are sent back on the given error channel, which is closed before the function returns.

Types

type AWBMode

type AWBMode uint

An AWBMode is an enumeration of the auto white balance modes.

const (
	AWBOff AWBMode = iota
	AWBAuto
	AWBSunlight
	AWBCloudy
	AWBShade
	AWBTungsten
	AWBFluorescent
	AWBIncandescent
	AWBFlash
	AWBHorizon
)

func (AWBMode) String

func (a AWBMode) String() string

String returns the command line parameter for the given AWBMode.

type BaseStill

type BaseStill struct {
	CamSelect     int
	Timeout       time.Duration // Delay before image is taken
	Width, Height int           // Image dimensions
	Timelapse     int           // The number of pictures to take in the given timeout interval
	Camera        Camera
	Preview       Preview

	// The command to run when making a still capture.  If left blank, the default
	// command is used.
	Command string

	// Additional arguments.  Default is empty.
	Args []string
}

BaseStill represents the common elements between a Still and StillYUV as described in their equivalents found in RaspiStill.c and RaspiStillYUV.c respectively.

func (*BaseStill) String

func (s *BaseStill) String() string

String returns the parameter string for the given BaseStill.

type Camera

type Camera struct {
	Sharpness            int // -100 to 100
	Contrast             int // -100 to 100
	Brightness           int // 0 to 100
	Saturation           int // -100 to 100
	ISO                  int // TODO: what range? (see RaspiCamControl.h)
	VideoStabilisation   bool
	ExposureCompensation int // -10 to 10? (see RaspiCamControl.h)
	ExposureMode         ExposureMode
	MeteringMode         MeteringMode
	AWBMode              AWBMode
	ImageEffect          ImageFX
	ColourEffects        ColourFX
	Rotation             int // 0 to 359
	HFlip, VFlip         bool
	RegionOfInterest     FloatRect // Assumes Normalised to [0.0,1.0]
	ShutterSpeed         time.Duration
}

Camera represents a camera configuration.

func (*Camera) String

func (c *Camera) String() string

String returns the parameters necessary to construct the equivalent command line arguments for the raspicam tools.

type CaptureCommand

type CaptureCommand interface {
	Cmd() string
	Params() []string
}

CaptureCommand represents a prepared capture command.

type ColourFX

type ColourFX struct {
	Enabled bool
	U, V    int
}

ColourFX represents colour effects parameters.

func (ColourFX) String

func (c ColourFX) String() string

String returns the command parameter for the given ColourFX.

type Encoding

type Encoding uint

Encoding represents an enumeration of the supported encoding types.

const (
	EncodingJPEG Encoding = iota
	EncodingBMP
	EncodingGIF
	EncodingPNG
)

func (Encoding) String

func (s Encoding) String() string

String returns the parameter string for the given encoding.

type ExposureMode

type ExposureMode uint

ExposureMode is an enumeration of supported exposure modes.

const (
	ExposureOff ExposureMode = iota
	ExposureAuto
	ExposureNight
	ExposureNightPreview
	ExposureBacklight
	ExposureSpotlight
	ExposureSports
	ExposureSnow
	ExposureBeach
	ExposureVerylong
	ExposureFixedFPS
	ExposureAntishake
	ExposureFireworks
)

func (ExposureMode) String

func (e ExposureMode) String() string

String returns the command line parameter for the given ExposureMode.

type FloatRect

type FloatRect struct {
	X, Y, W, H float64
}

FloatRect contains the information necessary to construct a rectangle with dimensions in floating point.

func (*FloatRect) String

func (r *FloatRect) String() string

String returns the command parameter for the given FloatRect.

type ImageFX

type ImageFX uint

An ImageFX specifies an image effect for the camera.

const (
	FXNone ImageFX = iota
	FXNegative
	FXSolarize
	FXPosterize
	FXWhiteboard
	FXBlackboard
	FXSketch
	FXDenoise
	FXEmboss
	FXOilpaint
	FXHatch
	FXGpen
	FXPastel
	FXWatercolour
	FXFilm
	FXBlur
	FXSaturation
	FXColourSwap
	FXWashedOut
	FXPosterise
	FXColourPoint
	FXColourBalance
	FXCartoon
)

func (ImageFX) String

func (i ImageFX) String() string

String returns the command-line parameter for the given imageFX.

type MeteringMode

type MeteringMode uint

A MeteringMode specificies an exposure metering mode.

const (
	MeteringAverage MeteringMode = iota
	MeteringSpot
	MeteringBacklit
	MeteringMatrix
)

func (MeteringMode) String

func (m MeteringMode) String() string

String returns the command line parameter for the given MeteringMode.

type Preview

type Preview struct {
	Mode    PreviewMode
	Opacity int  // Opacity of window (0 = transparent, 255 = opaque)
	Rect    Rect // Used when Mode is PreviewWindow
}

Preview contains the settings for the camera previews.

func (*Preview) String

func (p *Preview) String() string

String returns the parameter string for the given Preview.

type PreviewMode

type PreviewMode uint

PreviewMode represents an enumeration of preview modes.

const (
	PreviewFullscreen PreviewMode = iota // Enabled by default
	PreviewWindow
	PreviewDisabled
)

func (PreviewMode) String

func (p PreviewMode) String() string

String returns the parameter string for the given PreviewMode.

type Rect

type Rect struct {
	X, Y, Width, Height uint32
}

Rect represents a rectangle defined by integer parameters.

func (*Rect) String

func (r *Rect) String() string

String returns the parameter string for the given Rect.

type Still

type Still struct {
	BaseStill
	Quality  int  // Quality (for lossy encoding)
	Raw      bool // Want a raw image?
	Encoding Encoding
}

Still represents the configuration necessary to call raspistill.

func NewStill

func NewStill() *Still

NewStill returns a *Still with the default values set by the raspistill command (see userland/linux/apps/raspicam/RaspiStill.c).

func (*Still) Cmd

func (s *Still) Cmd() string

Cmd returns the raspicam command for a Still.

func (*Still) Params

func (s *Still) Params() []string

Params returns the parameters to be used in the command execution.

func (*Still) String

func (s *Still) String() string

String returns the parameter string for the given Still struct.

type StillYUV

type StillYUV struct {
	BaseStill
	UseRGB bool // Output RGB data rather than YUV
}

StillYUV represents the configuration necessary to call raspistillYUV.

func NewStillYUV

func NewStillYUV() *StillYUV

NewStillYUV returns a *StillYUV with the default values set by the raspiyuv command (see userland/linux/apps/raspicam/RaspiStillYUV.c).

func (*StillYUV) Cmd

func (s *StillYUV) Cmd() string

Cmd returns the raspicam command for a StillYUV.

func (*StillYUV) Params

func (s *StillYUV) Params() []string

Params returns the parameters to be used in the command execution.

func (*StillYUV) String

func (s *StillYUV) String() string

String returns the parameter string for the given StillYUV struct.

type Vid

type Vid struct {
	Timeout       time.Duration // Delay before image is taken
	Width, Height int           // Image dimensions
	Bitrate       int           // Requested bitrate
	Framerate     int           // Requested framerate (fps)
	IntraPeriod   int           // Intra-refresh period (key frame rate)

	// Flag to specify whether encoder works in place or creates a new buffer.
	// Result is preview can display either the camera output or the encoder
	// output (with compression artifacts).
	ImmutableInput bool
	Camera         Camera
	Preview        Preview

	// The command to run when making a video capture.  If left blank, the default
	// command is used.
	Command string

	// Additional arguments.  Default is empty.
	Args []string
}

Vid represents the the configuration used to call raspivid.

func NewVid

func NewVid() *Vid

NewVid returns a new *Vid struct setup with the default configuration.

func (*Vid) Cmd

func (v *Vid) Cmd() string

Cmd returns the raspicam command for a Vid.

func (*Vid) Params

func (v *Vid) Params() []string

Params returns the parameters to be used in the command execution.

func (*Vid) String

func (v *Vid) String() string

String returns the parameter string for the given Vid struct.

Jump to

Keyboard shortcuts

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