images

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: MIT Imports: 12 Imported by: 0

README

images

图像处理类库,基于模板的图片匹配

函数

  • Decode png解码
  • SubImage 获取图片局部
  • Distance 图片距离

结构

  • Dot 点距离
  • Dots 点距离数组
  • DotSet 点Set集合
  • Match 图片模板匹配

用法

go run cmd/match/main.go -s 12 -d 7 i1.png i2.png out.png
2021/02/06 11:40:18 开始识别图片 [ i1.png ] 中的 [ i2.png ]
2021/02/06 11:40:20 找到匹配: 11 处
2021/02/06 11:40:20 坐标: 658,155,      差距: 0
2021/02/06 11:40:20 坐标: 658,181,      差距: 0
2021/02/06 11:40:20 坐标: 658,207,      差距: 0
2021/02/06 11:40:20 坐标: 658,233,      差距: 0
2021/02/06 11:40:20 坐标: 658,259,      差距: 0
2021/02/06 11:40:20 坐标: 658,285,      差距: 0
2021/02/06 11:40:20 坐标: 658,311,      差距: 0
2021/02/06 11:40:20 坐标: 658,337,      差距: 0
2021/02/06 11:40:20 坐标: 658,77,       差距: 3
2021/02/06 11:40:20 坐标: 658,129,      差距: 6
2021/02/06 11:40:20 坐标: 658,104,      差距: 7
2021/02/06 11:40:20 保存图片:  out.png

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorNotFound = errors.New("没找到")

ErrorNotFound 没找到.

View Source
var ErrorSize = errors.New("目标图片小于模板图片")

ErrorSize 图片尺寸错误.

View Source
var ErrorType = errors.New("不支持的图片类型")

ErrorType 不支持的图片类型.

Functions

func Abs

func Abs(i int) int

Abs 绝对值.

func Decode

func Decode(file string) (image.Image, error)

Decode 图片解码.

func DecodeBytes added in v1.0.1

func DecodeBytes(bs []byte) (image.Image, error)

DecodeBytes 字节转换图片.

func Distance

func Distance(a image.Image, b image.Image) (int, error)

Distance 图片距离.

func Rect

func Rect(img draw.Image, r image.Rectangle, c color.Color)

Rect 绘制矩形.

func Save

func Save(img image.Image, file string) error

Save 保存图片.

func SubImage

func SubImage(img image.Image, r image.Rectangle) (image.Image, error)

SubImage 局部.

func ToGray added in v1.0.2

func ToGray(img image.Image) image.Image

ToGray 转换成灰度.

Types

type Dot

type Dot struct {
	X        int
	Y        int
	Distance int
}

Dot 点.

func (*Dot) Space

func (d *Dot) Space(o *Dot) int

Space 距离.

func (*Dot) String

func (d *Dot) String() string

String 点.

type DotSet

type DotSet map[int64]struct{}

DotSet 点集合.

func (DotSet) Add

func (d DotSet) Add(x, y int)

Add 增加.

func (DotSet) Has

func (d DotSet) Has(x, y int) (h bool)

Has 包含.

type Dots

type Dots []*Dot

Dots 点组.

func (Dots) Len

func (d Dots) Len() int

Len 长度.

func (Dots) Less

func (d Dots) Less(i, j int) bool

Less 比较.

func (Dots) Match

func (d Dots) Match(size, distance int) Dots

Match 匹配.

func (Dots) String

func (d Dots) String() string

String 点组.

func (Dots) Swap

func (d Dots) Swap(i, j int)

Swap 交换.

func (Dots) Top

func (d Dots) Top(size, distance int) Dots

Top 前几个.

type Match

type Match struct {
	Ratio     int
	Distance  int
	Size      int
	FuzzySize int
	// contains filtered or unexported fields
}

Match 匹配.

func NewFastMatch added in v1.0.2

func NewFastMatch(target image.Image, template image.Image) (*Match, error)

NewFastMatch 快速匹配.

func NewMatch

func NewMatch(target image.Image, template image.Image) (*Match, error)

NewMatch 新建匹配.

func (*Match) Match

func (m *Match) Match() ([]*Dot, error)

Match 匹配.

type StringSet

type StringSet map[string]struct{}

StringSet 字符串集合.

func (StringSet) Add

func (s StringSet) Add(str string)

Add 增加.

func (StringSet) Has

func (s StringSet) Has(str string) (h bool)

Has 包含.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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