Skip to content

Commit

Permalink
Add smoke tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelarusso authored and deadprogram committed Oct 17, 2023
1 parent 97afa6f commit 3709676
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
45 changes: 45 additions & 0 deletions calib3d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,48 @@ func TestEstimateAffine2DWithParams(t *testing.T) {
t.Errorf("TestEstimateAffine2DWithParams(): unexpected rows = %v, want = %v", m.Rows(), 2)
}
}

func TestTriangulatePoints(t *testing.T) {
projMat1, projMat2 := NewMatWithSize(3, 4, MatTypeCV64F), NewMatWithSize(3, 4, MatTypeCV64F)
defer projMat1.Close()
defer projMat2.Close()
projPoints1, projPoints2 := NewPoint2fVectorFromPoints([]Point2f{{Y: 1.0, X: 2.0}}), NewPoint2fVectorFromPoints([]Point2f{{Y: 3.0, X: 4.0}})
defer projPoints1.Close()
defer projPoints2.Close()
homogeneous := NewMat()
defer homogeneous.Close()
TriangulatePoints(projMat1, projMat2, projPoints1, projPoints2, &homogeneous)
if homogeneous.Empty() {
t.Errorf("TriangulatePoints(): output homogeneous mat is empty")
}
}

func TestConvertPointsFromHomogeneous(t *testing.T) {
homogeneous := NewMatWithSize(1, 4, MatTypeCV32F)
defer homogeneous.Close()
homogeneous.SetFloatAt(0, 0, 1)
homogeneous.SetFloatAt(0, 1, 2)
homogeneous.SetFloatAt(0, 2, 4)
homogeneous.SetFloatAt(0, 3, 2)
euclidean := NewMat()
defer euclidean.Close()
ConvertPointsFromHomogeneous(homogeneous, &euclidean)
if euclidean.Empty() {
t.Fatalf("ConvertPointsFromHomogeneous(): output euclidean mat is empty")
}
ptsVector := NewPoint3fVectorFromMat(euclidean)
defer ptsVector.Close()
pts := ptsVector.ToPoints()
if len(pts) != 1 {
t.Fatalf("ConvertPointsFromHomogeneous(): euclidean mat converted to points is empty")
}
if pts[0].X != 0.5 {
t.Errorf("ConvertPointsFromHomogeneous(): euclidean X - got %v, want %v", pts[0].X, 0.5)
}
if pts[0].Y != 1 {
t.Errorf("ConvertPointsFromHomogeneous(): euclidean Y - got %v, want %v", pts[0].Y, 1)
}
if pts[0].Z != 2 {
t.Errorf("ConvertPointsFromHomogeneous(): euclidean Z - got %v, want %v", pts[0].Z, 2)
}
}
54 changes: 54 additions & 0 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3142,3 +3142,57 @@ func TestSetThreadNumber(t *testing.T) {

SetNumThreads(original)
}

func TestMinMaxLoc(t *testing.T) {
input := NewMatWithSize(2, 2, MatTypeCV32F)
defer input.Close()
input.SetFloatAt(0, 0, 1)
input.SetFloatAt(0, 1, 2)
input.SetFloatAt(1, 0, 3)
input.SetFloatAt(1, 1, 4)
minVal, maxVal, minLoc, maxLoc := MinMaxLoc(input)

wantMinVal, wantMaxValue := float32(1.0), float32(4.0)
if minVal != wantMinVal {
t.Errorf("minVal got: %v, want %v", minVal, wantMinVal)
}
if maxVal != wantMaxValue {
t.Errorf("maxVal got: %v, want %v", maxVal, wantMaxValue)
}
wantMinLoc, wantMaxLoc := image.Point{Y: 0, X: 0}, image.Point{Y: 1, X: 1}
if minLoc != wantMinLoc {
t.Errorf("minLoc got: %v, want %v", minLoc, wantMinLoc)
}
if maxLoc != wantMaxLoc {
t.Errorf("maxLoc got: %v, want %v", maxLoc, wantMaxLoc)
}
}

func TestMinMaxLocWithMask(t *testing.T) {
input := NewMatWithSize(2, 2, MatTypeCV32F)
defer input.Close()
input.SetFloatAt(0, 0, 1)
input.SetFloatAt(0, 1, 2)
input.SetFloatAt(1, 0, 3)
input.SetFloatAt(1, 1, 4)
mask := NewMatWithSize(2, 2, MatTypeCV8U)
defer mask.Close()
mask.SetUCharAt(1, 0, 1)
mask.SetUCharAt(1, 1, 1)
minVal, maxVal, minLoc, maxLoc := MinMaxLocWithMask(input, mask)

wantMinVal, wantMaxValue := float32(3.0), float32(4.0)
if minVal != wantMinVal {
t.Errorf("minVal got: %v, want %v", minVal, wantMinVal)
}
if maxVal != wantMaxValue {
t.Errorf("maxVal got: %v, want %v", maxVal, wantMaxValue)
}
wantMinLoc, wantMaxLoc := image.Point{Y: 1, X: 0}, image.Point{Y: 1, X: 1}
if minLoc != wantMinLoc {
t.Errorf("minLoc got: %v, want %v", minLoc, wantMinLoc)
}
if maxLoc != wantMaxLoc {
t.Errorf("maxLoc got: %v, want %v", maxLoc, wantMaxLoc)
}
}

0 comments on commit 3709676

Please sign in to comment.