Skip to content

Commit

Permalink
core, cuda: add Closed() function to Mat/GpuMat
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Sep 15, 2024
1 parent e5d4cb3 commit 88c11e5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
5 changes: 5 additions & 0 deletions cuda/cuda.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
9 changes: 9 additions & 0 deletions cuda/cuda_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 88c11e5

Please sign in to comment.