Documentation
¶
Overview ¶
Package picam is a Go API that uses raspiyuv that continuously reads the latests frame from a Raspberry Pi Camera.
Example ¶
package main import ( "fmt" "log" "github.com/cgxeiji/picam" ) func main() { cam, err := picam.New(640, 480, picam.YUV) if err != nil { log.Fatal(err) } defer cam.Close() nFrames := 5 fmt.Println("Reading", nFrames, "frames:") for i := 0; i < nFrames; i++ { // Get an image.Image img := cam.Read() /* do something with img */ fmt.Println("got", img.Bounds().Size()) // Or get a raw []uint8 slice raw := cam.ReadUint8() /* do something with img */ fmt.Println("read", len(raw), "bytes") } }
Output: Reading 5 frames: got (640,480) read 460800 bytes got (640,480) read 460800 bytes got (640,480) read 460800 bytes got (640,480) read 460800 bytes got (640,480) read 460800 bytes
Example (Save) ¶
package main import ( "image/png" "log" "os" "github.com/cgxeiji/picam" ) func main() { cam, err := picam.New(640, 480, picam.YUV) if err != nil { log.Fatal(err) } defer cam.Close() img := cam.Read() f, err := os.Create("./image.png") if err != nil { log.Fatal(err) } defer f.Close() err = png.Encode(f, img) if err != nil { log.Fatal(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Camera ¶
type Camera struct {
// Width sets the width of the image
// Height sets the height of the image
Width, Height int
// contains filtered or unexported fields
}
Camera is a struct that stores camera information.
func (*Camera) Read ¶
Read returns an image.Image interface of the last frame.
cam, _ := picam.New(width, height, format) img := cam.Read()
The type returned depends on the format passed at picam.New():
format type(img) ---------- --------------- picam.YUV -> image.YCbCr 420 picam.RGB -> image.NRGBA picam.Gray -> image.Gray
func (*Camera) ReadUint8 ¶
ReadUint8 returns the raw uint8 values of the last frame.
cam, _ := picam.New(width, height, format) raw := cam.ReadUint8()
The size of the slice returned depends on the format and dimensions passed at picam.New():
format len(raw) ---------- ---------------------------------------------------------- picam.YUV -> roundUpMultiple32(width) * roundUpMultiple16(height) * 1.5 picam.RGB -> (width * height) * 3 picam.Gray -> width * height
Click to show internal directories.
Click to hide internal directories.