vision

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vision finds a picture on a screenshot and reads text with Tesseract. Both run on the PC; the phone only sends the screenshot.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooBig = errors.New("the image is larger than the screen")
	ErrFlat   = errors.New("the image is a single flat color, so there is nothing to match")
)
View Source
var ErrNoTesseract = errors.New("Tesseract is not installed")

ErrNoTesseract means OCR was asked for but Tesseract is not installed.

View Source
var ErrRegion = errors.New("region must be four numbers, left, top, right and bottom, inside the screen")

Functions

func Tesseract

func Tesseract(configured string) (string, error)

Tesseract finds the tesseract program: the configured path, then PATH, then the Windows installer's default folder.

Types

type Line

type Line struct {
	Text   string
	Bounds [4]int
	Conf   float64
	Words  []Word
}

Line is one line of text Tesseract read, in screenshot pixels.

func FindText

func FindText(lines []Line, text string) (Line, bool)

FindText returns the bounds of text: a word equal to it first, else a line that contains it.

func OCR

func OCR(bin string, png []byte, lang string, timeout time.Duration) ([]Line, error)

OCR runs Tesseract on a PNG and groups its words into lines.

func ParseTSV

func ParseTSV(tsv string) []Line

ParseTSV turns Tesseract's tsv output into lines of words.

type Match

type Match struct {
	Bounds [4]int  // left, top, right, bottom
	Score  float64 // normalised cross-correlation, 1 is a perfect match
}

Match is where a template was found, in screenshot pixels.

func Find

func Find(screen, template image.Image, threshold float64) (m Match, ok bool, err error)

Find looks for template on screen at the same scale. The best match is returned even below threshold, with ok false.

func FindAll added in v0.1.11

func FindAll(screen, template image.Image, threshold float64, o Options, limit int) ([]Match, error)

FindAll returns every place the template matches at or above threshold, best first, without overlaps, at most limit of them.

func FindWith added in v0.1.11

func FindWith(screen, template image.Image, threshold float64, o Options) (m Match, ok bool, err error)

FindWith is Find with a region, other sizes of the template, or a color check.

func (Match) Center

func (m Match) Center() (int, int)

type Options added in v0.1.11

type Options struct {
	Region []int     // left, top, right, bottom in screenshot pixels; empty means the whole screen
	Scales []float64 // template sizes to try, 1 being the size it was cut at; empty means just 1
	Color  bool      // also require the average color to agree, so a red and a green button differ
}

Options narrow or widen a search. The zero value searches the whole screen, at the size the template was cut, comparing brightness only.

type Word

type Word struct {
	Text   string
	Bounds [4]int
	Conf   float64
}

Jump to

Keyboard shortcuts

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