Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mat.ElemSize #964

Merged
merged 2 commits into from Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions core.cpp
Expand Up @@ -210,6 +210,10 @@ int Mat_Total(Mat m) {
return m->total();
}

int Mat_ElemSize(Mat m){
return m->elemSize();
}

void Mat_Size(Mat m, IntVector* res) {
cv::MatSize ms(m->size);
int* ids = new int[ms.dims()];
Expand Down
5 changes: 5 additions & 0 deletions core.go
Expand Up @@ -668,6 +668,11 @@ func (m *Mat) Step() int {
return int(C.Mat_Step(m.p))
}

// ElemSize returns the matrix element size in bytes.
func (m *Mat) ElemSize() int {
return int(C.Mat_ElemSize(m.p))
}

// GetUCharAt returns a value from a specific row/col
// in this Mat expecting it to be of type uchar aka CV_8U.
func (m *Mat) GetUCharAt(row int, col int) uint8 {
Expand Down
1 change: 1 addition & 0 deletions core.h
Expand Up @@ -304,6 +304,7 @@ int Mat_Cols(Mat m);
int Mat_Channels(Mat m);
int Mat_Type(Mat m);
int Mat_Step(Mat m);
int Mat_ElemSize(Mat m);
Mat Eye(int rows, int cols, int type);
Mat Zeros(int rows, int cols, int type);
Mat Ones(int rows, int cols, int type);
Expand Down
27 changes: 27 additions & 0 deletions core_test.go
Expand Up @@ -3017,3 +3017,30 @@ func TestNewPoints3fVector(t *testing.T) {
t.Fatal("unable to append to Points3fVector")
}
}

func TestElemSize(t *testing.T) {
m1 := NewMat()
defer m1.Close()
if m1.ElemSize() != 0 {
t.Error("incorrect element size")
}

m2 := NewMatWithSize(2, 2, MatTypeCV16S)
defer m2.Close()
if m2.ElemSize() != 2 {
t.Error("incorrect element size of MatTypeCV16S")
}

m3 := NewMatWithSize(2, 2, MatTypeCV16SC3)
defer m3.Close()
if m3.ElemSize() != 6 {
t.Error("incorrect element size of MatTypeCV16SC3")
}

m4 := NewMatWithSize(2, 2, MatTypeCV32SC4)
defer m4.Close()
if m4.ElemSize() != 16 {
t.Error("incorrect element size of MatTypeCV32SC4")
return
}
}