Skip to content

Commit

Permalink
TestTemplateMatching_Match
Browse files Browse the repository at this point in the history
  • Loading branch information
dwchoo authored and deadprogram committed Apr 2, 2024
1 parent f5bba45 commit ef6abd1
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions cuda/imgproc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,17 @@ func TestHoughSegment_CalcWithStream(t *testing.T) {
}

func TestTemplateMatching_Match(t *testing.T) {
src := gocv.IMRead("../images/face-detect.jpg", gocv.IMReadGrayScale)
if src.Empty() {
t.Error("Invalid read of Mat in TemplateMatching test")
imgScene := gocv.IMRead("../images/face.jpg", gocv.IMReadGrayScale)
if imgScene.Empty() {
t.Error("Invalid read of face.jpg in MatchTemplate test")
}
defer src.Close()
defer imgScene.Close()

imgTemplate := gocv.IMRead("../images/toy.jpg", gocv.IMReadGrayScale)
if imgTemplate.Empty() {
t.Error("Invalid read of toy.jpg in MatchTemplate test")
}
defer imgTemplate.Close()

cimg, timg, dimg := NewGpuMat(), NewGpuMat(), NewGpuMat()
defer cimg.Close()
Expand All @@ -300,18 +306,13 @@ func TestTemplateMatching_Match(t *testing.T) {
matcher := NewTemplateMatching(gocv.MatTypeCV8U, gocv.TmSqdiff)
defer matcher.Close()

cimg.Upload(src)
timg.Upload(src)
cimg.Upload(imgScene)
timg.Upload(imgTemplate)
matcher.Match(cimg, timg, &dimg)
dimg.Download(&dest)

if dest.Empty() {
t.Error("Empty TemplateMatching test")
}
if src.Rows() != dest.Rows() {
t.Error("Invalid TemplateMatching test rows")
}
if src.Cols() != dest.Cols() {
t.Error("Invalid TemplateMatching test cols")
_, maxConfidence, _, _ := gocv.MinMaxLoc(dest)
if maxConfidence < 0.95 {
t.Errorf("Max confidence of %f is too low. MatchTemplate could not find template in scene.", maxConfidence)
}
}

0 comments on commit ef6abd1

Please sign in to comment.