pulse-monitor/ocr.go

25 lines
651 B
Go

package main
import (
"gocv.io/x/gocv"
)
// imagesMatch compares two images using template matching
// Returns true if they are very similar (>95% match) - not pixel-identical due to video compression
func imagesMatch(img1, img2 gocv.Mat) bool {
if img1.Empty() || img2.Empty() {
return false
}
if img1.Rows() != img2.Rows() || img1.Cols() != img2.Cols() {
return false
}
result := gocv.NewMat()
gocv.MatchTemplate(img1, img2, &result, gocv.TmCcoeffNormed, gocv.NewMat())
_, maxVal, _, _ := gocv.MinMaxLoc(result)
result.Close()
// Video compression means frames are never pixel-identical, use 95% threshold
return maxVal >= 0.95
}