Calibrate orb detection from botty reference: vertical slice method, correct HSV ranges
- Add ReadOrbSlicePercentage: thin vertical strip method for accurate fill reading - Support HSV hue wrapping in colorInRange (for red hues crossing 360°) - Health HSV: H 350-370 (wrapping), S 60+, V 20+ (calibrated from screenshot) - Mana HSV: H 226-240, S 100+, V 20+ (calibrated from screenshot) - Add health_slice/mana_slice regions (10px wide vertical strips through orb centers) - Update health_globe/mana_globe to full botty-referenced regions - Verified: health 96.3%, mana 100% on testdata/d2r_1080p.png (both at 100% fill)
This commit is contained in:
parent
0716aeb5e1
commit
35a1944179
8 changed files with 117 additions and 44 deletions
|
|
@ -33,36 +33,62 @@ func main() {
|
|||
debugDir := "testdata/debug"
|
||||
os.MkdirAll(debugDir, 0755)
|
||||
|
||||
// Define regions for 1080p (from config.go — calibrated from real screenshot)
|
||||
// Define regions for 1080p (from config.go — calibrated from botty reference)
|
||||
regions := map[string]image.Rectangle{
|
||||
"health_orb": image.Rect(370, 945, 460, 1030),
|
||||
"mana_orb": image.Rect(1580, 910, 1670, 1000),
|
||||
"xp_bar": image.Rect(0, 1058, 1920, 1080),
|
||||
"belt": image.Rect(500, 990, 900, 1040),
|
||||
"minimap": image.Rect(1600, 0, 1920, 320),
|
||||
"inventory": image.Rect(960, 330, 1490, 770),
|
||||
"stash": image.Rect(430, 330, 960, 770),
|
||||
"skill_left": image.Rect(200, 1030, 250, 1078),
|
||||
"skill_right": image.Rect(1670, 1030, 1730, 1078),
|
||||
"health_globe": image.Rect(240, 870, 600, 1080),
|
||||
"mana_globe": image.Rect(1330, 870, 1690, 1080),
|
||||
"health_slice": image.Rect(415, 915, 425, 1060),
|
||||
"mana_slice": image.Rect(1505, 915, 1515, 1060),
|
||||
"health_orb": image.Rect(240, 870, 600, 1080),
|
||||
"mana_orb": image.Rect(1330, 870, 1690, 1080),
|
||||
"xp_bar": image.Rect(0, 1058, 1920, 1080),
|
||||
"belt": image.Rect(500, 990, 900, 1040),
|
||||
"minimap": image.Rect(1600, 0, 1920, 320),
|
||||
"inventory": image.Rect(960, 330, 1490, 770),
|
||||
"stash": image.Rect(430, 330, 960, 770),
|
||||
"skill_left": image.Rect(200, 1030, 250, 1078),
|
||||
"skill_right": image.Rect(1670, 1030, 1730, 1078),
|
||||
}
|
||||
|
||||
fmt.Println("\n=== REGION ANALYSIS ===")
|
||||
|
||||
// Analyze health orb
|
||||
analyzeRegion(img, "health_orb", regions["health_orb"], config.Colors.HealthFilled, debugDir)
|
||||
// Analyze health globe (full region)
|
||||
analyzeRegion(img, "health_globe", regions["health_globe"], config.Colors.HealthFilled, debugDir)
|
||||
|
||||
// Analyze mana orb
|
||||
analyzeRegion(img, "mana_orb", regions["mana_orb"], config.Colors.ManaFilled, debugDir)
|
||||
// Analyze mana globe (full region)
|
||||
analyzeRegion(img, "mana_globe", regions["mana_globe"], config.Colors.ManaFilled, debugDir)
|
||||
|
||||
// Analyze slices
|
||||
analyzeRegion(img, "health_slice", regions["health_slice"], config.Colors.HealthFilled, debugDir)
|
||||
analyzeRegion(img, "mana_slice", regions["mana_slice"], config.Colors.ManaFilled, debugDir)
|
||||
|
||||
// Use the vertical slice method for accurate orb reading
|
||||
fmt.Println("\n=== ORB SLICE READING (vertical strip method) ===")
|
||||
pipeline := vision.NewPipeline(0.5)
|
||||
healthSliceColor := vision.ColorRange{
|
||||
LowerH: config.Colors.HealthFilled.LowerH, LowerS: config.Colors.HealthFilled.LowerS, LowerV: config.Colors.HealthFilled.LowerV,
|
||||
UpperH: config.Colors.HealthFilled.UpperH, UpperS: config.Colors.HealthFilled.UpperS, UpperV: config.Colors.HealthFilled.UpperV,
|
||||
}
|
||||
manaSliceColor := vision.ColorRange{
|
||||
LowerH: config.Colors.ManaFilled.LowerH, LowerS: config.Colors.ManaFilled.LowerS, LowerV: config.Colors.ManaFilled.LowerV,
|
||||
UpperH: config.Colors.ManaFilled.UpperH, UpperS: config.Colors.ManaFilled.UpperS, UpperV: config.Colors.ManaFilled.UpperV,
|
||||
}
|
||||
healthPct := pipeline.ReadOrbSlicePercentage(img, regions["health_slice"], healthSliceColor)
|
||||
manaPct := pipeline.ReadOrbSlicePercentage(img, regions["mana_slice"], manaSliceColor)
|
||||
fmt.Printf("Health orb (slice): %.1f%%\n", healthPct*100)
|
||||
fmt.Printf("Mana orb (slice): %.1f%%\n", manaPct*100)
|
||||
|
||||
// Sample some specific pixels in the orbs for detailed analysis
|
||||
fmt.Println("\n=== PIXEL SAMPLING ===")
|
||||
samplePixelsInRegion(img, "health_orb", regions["health_orb"])
|
||||
samplePixelsInRegion(img, "mana_orb", regions["mana_orb"])
|
||||
samplePixelsInRegion(img, "health_globe", regions["health_globe"])
|
||||
samplePixelsInRegion(img, "mana_globe", regions["mana_globe"])
|
||||
samplePixelsInRegion(img, "health_slice", regions["health_slice"])
|
||||
samplePixelsInRegion(img, "mana_slice", regions["mana_slice"])
|
||||
|
||||
// Suggest new HSV ranges based on analysis
|
||||
fmt.Println("\n=== RECOMMENDATIONS ===")
|
||||
recommendHealthRange(img, regions["health_orb"])
|
||||
recommendManaRange(img, regions["mana_orb"])
|
||||
recommendHealthRange(img, regions["health_globe"])
|
||||
recommendManaRange(img, regions["mana_globe"])
|
||||
|
||||
fmt.Printf("\nDebug images saved to: %s\n", debugDir)
|
||||
fmt.Println("Run this tool after implementing the fixes to verify detection works correctly.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue