scan

package
v0.0.0-...-20888ae Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2022 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugOut io.Writer
View Source
var NoLineError = errors.New("no line found")

Functions

func CatmullRom

func CatmullRom(a, b, c, d uint8, x float64) uint8

func FindTransform

func FindTransform(sources, dests []FPoint) []float64

FindTransform solves for best-fit affine transform which maps source positions to dest positions.

func ImageBiCatrom

func ImageBiCatrom(im image.Image, x, y float64) color.RGBA

func TransformError

func TransformError(sources, dests []FPoint, t AffineTransform) float64

TransformError returns the sum of squared differences of dests vs sources transformed to dests

func YBiCatrom

func YBiCatrom(im *image.YCbCr, x, y float64) uint8

Types

type AffineTransform

type AffineTransform interface {
	TransformInt(x, y int) (int, int)
	Transform(x, y float64) (float64, float64)
}

type BsData

type BsData struct {
	GpUnitIds []string `json:"GpUnitIds"`

	Bubbles Contest `json:"bubbles"`

	// Header map[page number string][]float64{left, top, right, bottom}
	Header map[string][]float64 `json:"headers"`
}

type BubblesJson

type BubblesJson struct {
	DrawSettings *DrawSettings `json:"draw_settings"`

	// BsData should be preferred in the future
	// .BsData[ballotStyleIndex].GpUnitIds = [gp unit id str, ...]
	// .BsData[ballotStyleIndex].Bubbles[contest id str][selection id str] = [left, bottom, width, height]
	// .BsData[ballotStyleIndex].Headers[page number str] = [left, top, right, bottom]
	BsData []BsData `json:"bsdata"`

	// Bubbles is a list per ballot style, indexed in the same order as the source document ballot styles.
	// .Bubbles[ballotStyleIndex][contest @id][selection @id][x y width height]
	// Deprecated, use .BsData[ballotStyleIndex].Bubbles instead
	Bubbles []Contest `json:"bubbles"`

	// Headers[ballotStyleIndex][page number string][left top right bottom]
	// page coords are (0,0) bottom left, in points (1/72 inch)
	// Deprecated, use .BsData[ballotStyleIndex].Headers instead
	Headers []map[string][]float64 `json:"headers"`
}

func (BubblesJson) Header

func (bj BubblesJson) Header(ballotStyleIndex, page int) (left, top, right, bottom float64, err error)

page is 1-indexed

type Contest

type Contest map[string]ContestSelections

type ContestSelections

type ContestSelections map[string][]float64

{"csel1": [44.2, 491.4000000000001, 22.67716535433071, 8.255859375], "csel2": [44.2, 458.2000000000001, 22.67716535433071, 8.255859375]} []float64 is length 4, [x,y, width,height]

type DrawSettings

type DrawSettings struct {
	// PageSize: [width pt, height pt],
	PageSize   []float64 `json:"pagesize"`
	PageMargin float64   `json:"pageMargin"`
}

type FPoint

type FPoint struct {
	X float64
	Y float64
}

func FPointFromInt

func FPointFromInt(x, y int) FPoint

func (*FPoint) SetInt

func (fp *FPoint) SetInt(x, y int)
type Header struct {
	// contains filtered or unexported fields
}

Header is a little like Scanner, but just a ballot original image header, for matching to an unknown ballot scan

func ExtractHeaders

func ExtractHeaders(bubblesJsonStr []byte, pngbytes [][]byte) (headers []*Header, err error)

func (*Header) CheckPage

func (h *Header) CheckPage(s *ScanContext, it *image.YCbCr, debugi SettableImage) (score float64, err error)

like 'refineTransform' mapping header hotspots to matches in image, keep page with smallest error

func (*Header) DebugImage

func (h *Header) DebugImage() SettableImage

func (*Header) HotspotDebugImage

func (h *Header) HotspotDebugImage() *image.RGBA

Build an image of the found header hotspot regions

func (*Header) HotspotDebugString

func (h *Header) HotspotDebugString() string

func (*Header) Png

func (h *Header) Png() []byte

func (*Header) SetOrigImage

func (h *Header) SetOrigImage(pngbytes []byte) error

type MatrixTransform

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

func (MatrixTransform) Transform

func (mt MatrixTransform) Transform(x, y float64) (float64, float64)

func (MatrixTransform) TransformInt

func (mt MatrixTransform) TransformInt(x, y int) (int, int)

type NopTransform

type NopTransform struct {
}

func (NopTransform) Transform

func (mt NopTransform) Transform(x, y float64) (float64, float64)

func (NopTransform) TransformInt

func (mt NopTransform) TransformInt(x, y int) (int, int)

type ScanContext

type ScanContext struct {
	DebugOut io.Writer

	TargetsPngPath string
	DebugPngPath   string
	BubblesPngPath string
	// contains filtered or unexported fields
}

ScanContext

func (*ScanContext) FindTopLineTransform

func (s *ScanContext) FindTopLineTransform(it *image.YCbCr) error

func (*ScanContext) ProcessScannedImage

func (s *ScanContext) ProcessScannedImage(im image.Image) (marked map[string]map[string]bool, score float64, err error)

return map[contest @id]map[csel @id](bool marked)

func (*ScanContext) ReadScannedImage

func (s *ScanContext) ReadScannedImage(fname string) (marked map[string]map[string]bool, score float64, err error)

return map[contest @id]map[csel @id](bool marked)

type Scanner

type Scanner struct {
	Bj BubblesJson
	// contains filtered or unexported fields
}

Scanner holds an original page Scanner is read-only after setup and can be referenced by multiple threads of ScanContext

func (*Scanner) DebugOrigBubbles

func (s *Scanner) DebugOrigBubbles(outpath string) error

func (*Scanner) NewScanContext

func (s *Scanner) NewScanContext() *ScanContext

func (*Scanner) ReadBubblesJson

func (s *Scanner) ReadBubblesJson(path string) error

func (*Scanner) ReadOrigImage

func (s *Scanner) ReadOrigImage(origname string) error

func (*Scanner) SetOrigImage

func (s *Scanner) SetOrigImage(orig image.Image) error

type SettableImage

type SettableImage interface {
	image.Image
	Set(x, y int, c color.Color)
}

SettableImage is image.Image + Set()

Jump to

Keyboard shortcuts

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