88 lines
2.5 KiB
Go
88 lines
2.5 KiB
Go
// Package vision provides computer vision utilities for game screen analysis.
|
|
//
|
|
// Uses GoCV (OpenCV bindings for Go) for template matching, color detection,
|
|
// and contour analysis. Designed for high-throughput real-time analysis.
|
|
package vision
|
|
|
|
import (
|
|
"image"
|
|
"image/color"
|
|
)
|
|
|
|
// Match represents a detected element on screen.
|
|
type Match struct {
|
|
Position image.Point
|
|
BBox image.Rectangle
|
|
Confidence float64
|
|
Label string
|
|
}
|
|
|
|
// Template is a pre-loaded image template for matching.
|
|
type Template struct {
|
|
Name string
|
|
Image image.Image
|
|
Width int
|
|
Height int
|
|
}
|
|
|
|
// ColorRange defines an HSV color range for detection.
|
|
type ColorRange struct {
|
|
LowerH, LowerS, LowerV int
|
|
UpperH, UpperS, UpperV int
|
|
}
|
|
|
|
// Pipeline processes frames through a series of vision operations.
|
|
type Pipeline struct {
|
|
templates map[string]*Template
|
|
threshold float64
|
|
}
|
|
|
|
// NewPipeline creates a vision pipeline with the given confidence threshold.
|
|
func NewPipeline(threshold float64) *Pipeline {
|
|
return &Pipeline{
|
|
templates: make(map[string]*Template),
|
|
threshold: threshold,
|
|
}
|
|
}
|
|
|
|
// LoadTemplate loads a template image for matching.
|
|
func (p *Pipeline) LoadTemplate(name string, img image.Image) {
|
|
bounds := img.Bounds()
|
|
p.templates[name] = &Template{
|
|
Name: name,
|
|
Image: img,
|
|
Width: bounds.Dx(),
|
|
Height: bounds.Dy(),
|
|
}
|
|
}
|
|
|
|
// FindTemplate searches for a template in the frame.
|
|
// Returns the best match above threshold, or nil.
|
|
func (p *Pipeline) FindTemplate(frame image.Image, templateName string) *Match {
|
|
// TODO: Implement with GoCV matchTemplate
|
|
// This is a stub — actual implementation needs gocv.MatchTemplate
|
|
return nil
|
|
}
|
|
|
|
// FindAllTemplates finds all matches of a template above threshold.
|
|
func (p *Pipeline) FindAllTemplates(frame image.Image, templateName string) []Match {
|
|
// TODO: Implement with GoCV + NMS
|
|
return nil
|
|
}
|
|
|
|
// FindByColor detects regions matching an HSV color range.
|
|
func (p *Pipeline) FindByColor(frame image.Image, colorRange ColorRange, minArea int) []Match {
|
|
// TODO: Implement with GoCV inRange + findContours
|
|
return nil
|
|
}
|
|
|
|
// ReadBarPercentage reads a horizontal bar's fill level (health, mana, xp).
|
|
func (p *Pipeline) ReadBarPercentage(frame image.Image, barRegion image.Rectangle, filledColor ColorRange) float64 {
|
|
// TODO: Implement — scan columns for filled color ratio
|
|
return 0.0
|
|
}
|
|
|
|
// GetPixelColor returns the color at a specific pixel.
|
|
func (p *Pipeline) GetPixelColor(frame image.Image, x, y int) color.Color {
|
|
return frame.At(x, y)
|
|
}
|