diff --git a/core.go b/core.go index 07fe80f4..79a49188 100644 --- a/core.go +++ b/core.go @@ -355,6 +355,11 @@ func (m *Mat) Empty() bool { return isEmpty != 0 } +// Closed determines if the Mat is closed or not. +func (m *Mat) Closed() bool { + return m.p == nil +} + // IsContinuous determines if the Mat is continuous. // // For further details, please see: diff --git a/core_test.go b/core_test.go index a4f8cfc5..1c6fa7a2 100644 --- a/core_test.go +++ b/core_test.go @@ -19,6 +19,14 @@ func TestMat(t *testing.T) { } } +func TestMatClosed(t *testing.T) { + mat := NewMat() + mat.Close() + if !mat.Closed() { + t.Error("Closed Mat should be closed") + } +} + func TestMatWithSizes(t *testing.T) { t.Run("create mat with multidimensional array", func(t *testing.T) { sizes := []int{100, 100, 100} diff --git a/cuda/cuda.go b/cuda/cuda.go index 79b1ccf0..9271523e 100644 --- a/cuda/cuda.go +++ b/cuda/cuda.go @@ -85,6 +85,11 @@ func (g *GpuMat) Close() error { return nil } +// Closed determines if the GpuMat is closed or not. +func (g *GpuMat) Closed() bool { + return g.p == nil +} + // NewGpuMat returns a new empty GpuMat func NewGpuMat() GpuMat { return newGpuMat(C.GpuMat_New()) diff --git a/cuda/cuda_test.go b/cuda/cuda_test.go index bbec8813..0995ad1c 100644 --- a/cuda/cuda_test.go +++ b/cuda/cuda_test.go @@ -15,6 +15,15 @@ func TestNewGpuMat(t *testing.T) { } } +func TestGpuMatClosed(t *testing.T) { + mat := NewGpuMat() + mat.Close() + + if !mat.Closed() { + t.Error("Closed GpuMat should be closed") + } +} + func TestNewGpuMatFromMat(t *testing.T) { mat := gocv.NewMat() defer mat.Close()