Skip to content

Use Go-style return values for gocv functions that have result Mat #137

@willdurand

Description

@willdurand

When reviewing #135, I was like "wait, why is this test actually passing?". The test was about flipping a Mat into a brand new Mat, both passed to a function that looks roughly like this:

func Flip(src Mat, dst Mat, flipCode int) {}

In Go, parameters passed by value (default like above) should not be modified (and in any case, it will never change the value in the parent block). In gocv, this would works though because we manipulate a C pointer under the hood but this is a bit misleading.

Question is: could we agree on a "convention" stating that all arguments modified should be passed by pointer?

If we take the Flip() function as an example:

src := ...
dst := gocv.NewMat()

// wait, how does `dst` can be updated? No return-value either? Hmmm.
gocv.Flip(src, dst, 0);

// versus

// oh right so `Flip` takes a `src` Mat and puts the result in `dst`. Lovely <3
gocv.Flip(src, &dst, 0);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions