cam

package module
v0.0.0-...-84e1bcd Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2020 License: MIT Imports: 1 Imported by: 0

README

cam

GoDoc Go Report Card

cam is a package for Go that provides a high level api (similar to net/http) and a small set of plugins for working with camera frames. For the device communication, implementing the Device interface, we use GoCV and OpenCV, more can be easily added. Contributions are welcomed.

Dependencies

Installation

go get github.com/mvrilo/cam

Example

package main

import (
	"image"
	"image/color"
	"log"

	"github.com/mvrilo/cam"
	"github.com/mvrilo/cam/middlewares/pixelize"
	"github.com/mvrilo/cam/middlewares/window"
	"gocv.io/x/gocv"

	_ "github.com/mvrilo/cam/gocv"
)

func main() {
	cam.Use(pixelize.New(32))
	cam.Handle(func(f cam.Frame) {
		text := "hello world"
		blue := color.RGBA{0, 0, 255, 0}
		data, ok := f.Data().(gocv.Mat)
		if !ok {
			return
		}
		gocv.PutText(&data, text, image.Pt(200, 200), gocv.FontHersheyPlain, 10, blue, 8)
	})
	cam.Use(window.New("cam example"))
	log.Fatal(cam.ListenAndServe(0, nil))
}

hello world

Author

Murilo Santana <mvrilo@gmail.com>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handle

func Handle(f func(f Frame))

func ListenAndServe

func ListenAndServe(addr interface{}, handler Handler) error

func Register

func Register(device Device)

func Use

func Use(h ...Handler)

Types

type Cam

type Cam struct {
	Addr     interface{}
	Device   Device
	Handlers []Handler
}

Cam struct with the video, device address and a list of handlers

func (*Cam) Close

func (c *Cam) Close() error

func (*Cam) Handle

func (c *Cam) Handle(h func(Frame))

Handle appends to the list of handlers a func with a signature that matches the HandlerFunc

func (*Cam) ListenAndServe

func (c *Cam) ListenAndServe() error

func (*Cam) Register

func (c *Cam) Register(video Device)

Register sets a video device

func (*Cam) Serve

func (c *Cam) Serve()

func (*Cam) Use

func (c *Cam) Use(handlers ...Handler)

Use appends to the list of handlers one or more Handlers

type Device

type Device interface {
	NewFrame() Frame
	Read(data interface{})
	Open(device interface{}) error
	Close() error
}

Device interfaces with the device

type Frame

type Frame interface {
	Storage
	Close()
	Data() interface{}
}

Frame interfaces with the device frame

type Handler

type Handler interface {
	Handle(Frame)
}

Handler interface expects a Handle func that receivs a frame

type HandlerFunc

type HandlerFunc func(Frame)

func (HandlerFunc) Handle

func (h HandlerFunc) Handle(frame Frame)

type Storage

type Storage interface {
	Get(key string) interface{}
	Set(key string, value interface{})
}

Storage interface

type Store

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

Store is a concurrency-safe map[string]interface{} implemntation

func NewStore

func NewStore() *Store

func (*Store) Get

func (s *Store) Get(name string) interface{}

Get returns a value as interface{} from its store

func (*Store) Set

func (s *Store) Set(name string, val interface{})

Set writes a value on its store for a given name

Directories

Path Synopsis
examples
middlewares
ocr

Jump to

Keyboard shortcuts

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