piCamera

package module
v0.0.0-...-e88c363 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2017 License: BSD-3-Clause Imports: 16 Imported by: 0

README

piCamera GoDoc

This package is a wrapper for the raspivid command on the Raspberry Pi. To make development easier on a PC, there is are different Start() methods depending on what is compiled. One is for the Raspberry Pi and the other is for everything else.

Installation

Since this package depends on a Raspberry Pi only command there is an extra flag needed to build this package for the Raspberry Pi.

env GOOS=linux GOARCH=arm GOARM=7 go build -tags pi -a .

Make note of the -tags pi on build. Any main package that has any dependency to this package should have that flag so that this package is built correctly for the Raspberry Pi.

Documentation

Overview

Package piCamera is a simple wrapper for raspivid.

There is a non-RaspberryPi version that is used for local development. This can become handy when the IDE does not know how to handle certain features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AWBGains

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

AWBGains sets the blue and red gains to be applied when AWBOff is set.

func NewAWBGains

func NewAWBGains(blue, red float32) *AWBGains

NewAWBGains creates gains to set to Red and Blue. Values are multiplied to the values so 1.5 is 150% and .5 is 50%.

func (*AWBGains) Convert

func (t *AWBGains) Convert() string

Convert takes the type and returns the string representation of that value.

type AWBType

type AWBType int

AWBType is for setting the Automatic White Balance setting.

const (
	//AwbAuto is for automatic white balance
	AwbAuto AWBType = iota
	//AwbOff is for turning automatic white balance off
	AwbOff
	//AwbSun is for sunny mode
	AwbSun
	//AwbCloud is for cloudy mode
	AwbCloud
	//AwbShade is for shade mode
	AwbShade
	//AwbTungsten tungsten lighting mode
	AwbTungsten
	//AwbFluorescent fluorescent lighting mode
	AwbFluorescent
	//AwbIncandescent incandescent lighting mode
	AwbIncandescent
	//AwbFlash flash mode
	AwbFlash
	//AwbHorizon horizon mode
	AwbHorizon
)

func (AWBType) Convert

func (t AWBType) Convert() (string, bool)

Convert takes the type and returns the string representation of that value. Returns true as well if it is the default value.

type ColourEffect

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

ColourEffect is used fo setting which color effect one wants.

func NewColourEffect

func NewColourEffect(u, v int) *ColourEffect

NewColourEffect creates a colour effect of the U and Y channel of the image. Values should be in the range from (0, 255).

func (*ColourEffect) Convert

func (t *ColourEffect) Convert() string

Convert takes the type and returns the string representation of that value.

type DRCType

type DRCType int

DRCType is to set the dynamic range compression

const (
	//DRCNone is so this package can use whatever the default is
	DRCNone DRCType = iota
	//DRCOff turns of DRC
	DRCOff
	//DRCLow compress the range slightly
	DRCLow
	//DRCMedium compress the range more
	DRCMedium
	//DRCHigh compress the range even more
	DRCHigh
)

func (DRCType) Convert

func (t DRCType) Convert() (string, bool)

Convert takes the type and returns the string representation of that value. Returns true as well if it is the default value.

type ExposureType

type ExposureType int

ExposureType is for setting the exposure mode.

const (
	//ExpNone is used to tell this package to use whatever the default is.
	ExpNone ExposureType = iota
	//ExpAuto use automatic exposure mode
	ExpAuto
	//ExpNight select setting for night shooting
	ExpNight
	//ExpBacklight select setting for backlit subject
	ExpBacklight
	//ExpSpotlight select setting for spotlit subject
	ExpSpotlight
	//ExpSports select setting for sports
	ExpSports
	//ExpSnow select setting optimised for snowy scenery
	ExpSnow
	//ExpBeach select setting optimised for beach
	ExpBeach
	//ExpVerylong select setting for long exposures
	ExpVerylong
	//ExpFixedfps constrain fps to a fixed value
	ExpFixedfps
	//ExpAntishake turns on antishake mode
	ExpAntishake
	//ExpFireworks select setting optimised for fireworks
	ExpFireworks
)

func (ExposureType) Convert

func (t ExposureType) Convert() (string, bool)

Convert takes the type and returns the string representation of that value. Returns true as well if it is the default value.

type ImgEffectType

type ImgEffectType int

ImgEffectType is used for setting the image effect to use.

const (
	//ImfxNone no effect
	ImfxNone ImgEffectType = iota
	//ImfxNegative invert the image colours
	ImfxNegative
	//ImfxSolarise solarise the image
	ImfxSolarise
	//ImfxPosterise posterise the image
	ImfxPosterise
	//ImfxWhiteboard whiteboard effect
	ImfxWhiteboard
	//ImfxBlackboard blackboard effect
	ImfxBlackboard
	//ImfxSketch sketch effect
	ImfxSketch
	//ImfxDenoise denoise the image
	ImfxDenoise
	//ImfxEmboss the image
	ImfxEmboss
	//ImfxOilpaint oil paint effect
	ImfxOilpaint
	//ImfxHatch hatch sektch effect
	ImfxHatch
	//ImfxGPen graphite sketch effect
	ImfxGPen
	//ImfxPastel pastel effect
	ImfxPastel
	//ImfxWatercolour watercolour effect
	ImfxWatercolour
	//ImfxFilm film grain effect
	ImfxFilm
	//ImfxBlur blur the image
	ImfxBlur
	//ImfxSaturation colour saturate the image
	ImfxSaturation
)

func (ImgEffectType) Convert

func (t ImgEffectType) Convert() (string, bool)

Convert takes the type and returns the string representation of that value. Returns true as well if it is the default value.

type MeteringType

type MeteringType int

MeteringType is used for setting the Metering Mode.

const (
	//MeterNone tell this package to use whatever the default is
	MeterNone MeteringType = iota
	//MeterAverage average the whole frame for metering
	MeterAverage
	//MeterSpot use spot metering
	MeterSpot
	//MeterBacklit will assume a backlit image
	MeterBacklit
	//MeterMatrix use matrix metering
	MeterMatrix
)

func (MeteringType) Convert

func (t MeteringType) Convert() (string, bool)

Convert takes the type and returns the string representation of that value. Returns true as well if it is the default value.

type PiCamera

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

PiCamera creates a way for code to be able to pull images from the camera live. You must start eh raspivid explicitly first but once started, PiCamera will have the latest image available to view.

PiCamera is thread safe so many calls to GetFrame() will not break. Be careful as the more calls to GetFrame() the slower GetFrame() may become due to all the read locks.

func New

func New(parentCtx context.Context, args *RaspividArgs) (*PiCamera, error)

New creates an instance of PiCamera. Width and Height are for the image size. ctx is the parent context. If nil a background context will be created.

This creates the command raspivid with the appropriate settings. The stdErr of the command is redirected to os.Stderr so that one may see why the command may have failed.

func (*PiCamera) GetFrame

func (pc *PiCamera) GetFrame() ([]byte, error)

GetFrame returns the latest frame from raspivid. If there is no frame available it will throw an error.

func (*PiCamera) Start

func (pc *PiCamera) Start() error

Start raspivid in the background. Also logs the PID to os.stdOut.

This is the function that is built seperatly depending on if you are building for the Raspberry Pi or not.

func (*PiCamera) Stop

func (pc *PiCamera) Stop()

Stop the raspivid command. Safely stop all the commands and routines with this.

type ProfileType

type ProfileType int

ProfileType sets the H264 profile to be used for the encoding.

const (
	//ProfileNone tells this package to use whatever the default is.
	ProfileNone ProfileType = iota
	//ProfileBaseline is for the baseline profile
	ProfileBaseline
	//ProfileMain is for the main profile
	ProfileMain
	//ProfileHigh is for a high profile
	ProfileHigh
)

func (ProfileType) Convert

func (t ProfileType) Convert() (string, bool)

Convert takes the type and returns the string representation of that value. Returns true as well if it is the default value.

type RaspividArgs

type RaspividArgs struct {
	HorizFlip     bool             // flip the image horizontally
	VertFlip      bool             // flip the camera vertically
	VideoStable   bool             // try to stableize the video
	InsertHeaders bool             // insert pps, sps headers to every I-Frame
	Width         int              // width of the image
	Height        int              // height of the image
	Sharpness     int              // change the sharpness of the camera (-100 , 100 DEF 0)
	Contrast      int              // change the contrast of the camera (-100 , 100 DEF 0)
	Brightness    int              // change the brightness of the camera (0 , 100 DEF 50)
	Saturation    int              // change the saturation of the camera (-100 , 100 DEF 0)
	ISO           int              // change the sensitivity the camera is to light (100 , 800 DEF 100)
	EV            int              // Slightly under or over expose the camera (-10 , 10 DEF 0)
	Bitrate       int              // set the bitrate in bits per second. Max is 25000000
	FPS           int              // set the frames per second (2 , 30)
	IntraRate     int              // set number of frames before next intra frame
	Quantization  int              // set Quantization parameter
	Mode          int              // set the mode of the camera by checking the documentation
	ShutterSpeed  int              // set the shutter speed in microseconds (Max 6000000)
	Rotation      int              // set the rotation of the image. (0, 90, 180, 270)
	Annotate      string           // annotate the image according to the documentation
	AnnotateExtra string           // annotate the image according to the documentation
	ExposureMode  ExposureType     // set which mode to use for exposure
	AWB           AWBType          // set the automatic white balance mode
	ImageFx       ImgEffectType    // set the image effect
	Metering      MeteringType     // ste the metering mode
	DRC           DRCType          // set the dynamic range compression
	AWBGains      *AWBGains        // set the AWBGains when AWB is off
	ROI           *RegionOfIntrest // set the cameras region of interest
	ColourFx      *ColourEffect    // set the color effects to an image

	Profile ProfileType // set the profile type
}

RaspividArgs are arguments used to set camera settings for the desired output https://www.raspberrypi.org/documentation/raspbian/applications/camera.md

func NewArgs

func NewArgs() *RaspividArgs

NewArgs returns a RaspividArgs with the default settings

type RegionOfIntrest

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

RegionOfIntrest is used to set the cameras area to be used as the source.

func NewROI

func NewROI(tlx, tly, w, h float32) *RegionOfIntrest

NewROI creates a new Region of Interest. tlx and tly are the top left x and y of ROI. w and h are the width and height of the ROI. All points should be normalized from 0.0 - 1.0.

func (*RegionOfIntrest) Convert

func (t *RegionOfIntrest) Convert() string

Convert takes the type and returns the string representation of that value.

Jump to

Keyboard shortcuts

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