Skip to content

Commit

Permalink
added new Mat constructor and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diegohce committed Dec 2, 2024
1 parent 16033cd commit 29b4816
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ Mat Mat_NewFromPoint2fVector(Point2fVector pfv, bool copy_data) {
return new cv::Mat(*pfv, copy_data);
}

Mat Mat_NewFromPointVector(PointVector pv, bool copy_data) {
return new cv::Mat(*pv, copy_data);
}

Mat Eye(int rows, int cols, int type) {
cv::Mat* mat = new cv::Mat(rows, cols, type);
*mat = cv::Mat::eye(rows, cols, type);
Expand Down
6 changes: 6 additions & 0 deletions core.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ func NewMatFromPoint2fVector(pfv Point2fVector, copyData bool) Mat {
return mat
}

// NewMatFromPointVector returns a new Mat from a gocv.PointVector.
func NewMatFromPointVector(pv PointVector, copyData bool) Mat {
mat := newMat(C.Mat_NewFromPointVector(pv.p, C.bool(copyData)))
return mat
}

// Returns an identity matrix of the specified size and type.
//
// The method returns a Matlab-style identity matrix initializer, similarly to Mat::zeros. Similarly to Mat::ones.
Expand Down
1 change: 1 addition & 0 deletions core.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ Mat Mat_NewFromScalar(const Scalar ar, int type);
Mat Mat_NewWithSizeFromScalar(const Scalar ar, int rows, int cols, int type);
Mat Mat_NewFromBytes(int rows, int cols, int type, struct ByteArray buf);
Mat Mat_NewFromPoint2fVector(Point2fVector pfv, bool copy_data);
Mat Mat_NewFromPointVector(PointVector pv, bool copy_data);
Mat Mat_FromPtr(Mat m, int rows, int cols, int type, int prows, int pcols);
void Mat_Close(Mat m);
int Mat_Empty(Mat m);
Expand Down
39 changes: 39 additions & 0 deletions core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3412,3 +3412,42 @@ func TestNewRotatedRect2f(t *testing.T) {
}

}

func TestNewMatFromPointVector(t *testing.T) {

img := NewMatWithSize(320, 200, MatTypeCV32SC1)
defer img.Close()

size := img.Size()

points := []image.Point{
image.Pt(0, 0), image.Pt(0, size[0]-1),
image.Pt(size[1]-1, size[0]-1),
image.Pt(size[1]-1, 0),
}

pv := NewPointVectorFromPoints(points)
defer pv.Close()

m := NewMatFromPointVector(pv, false)
defer m.Close()

if m.Empty() {
t.Error("Mat shlould not be empty")
}

}

func TestNewMatFromPoint2fVector(t *testing.T) {

pv2f := NewPoint2fVectorFromPoints([]Point2f{NewPoint2f(1.1, 2.2)})
defer pv2f.Close()

m := NewMatFromPoint2fVector(pv2f, false)
defer m.Close()

if m.Empty() {
t.Error("Mat shlould not be empty")
}

}

0 comments on commit 29b4816

Please sign in to comment.