diff --git a/cuda/imgproc_test.go b/cuda/imgproc_test.go index 6009a486..455e6200 100644 --- a/cuda/imgproc_test.go +++ b/cuda/imgproc_test.go @@ -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() @@ -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) } }