A lot of OpenCV functions are defined as
function(InputArray src, OutputArray dst, otherargs..)
So if I want to process and overwrite the s
Yes, in OpenCV it is safe.
Internally, a function like:
void somefunction(InputArray _src, OutputArray _dst);
will do something like:
Mat src = _src.getMat();
_dst.create( src.size(), src.type() );
Mat dst = _dst.getMat();
// dst filled with values
So, if src
and dst
are:
create
won't actually do anything, and the modifications are effectively in-place. Some functions may clone
the src
image internally if the operation cannot be in-place (e.g. findConturs
in OpenCV > 3.2) to guarantee the correct behavior.create
will create a new matrix dst
without modifying src
.Documentation states where this default behavior doesn't hold.
A notable example is findContours
, that modify the src
matrix. You cope with this usually passing src.clone()
in input, so that only the cloned matrix is modified, but not the one you cloned from.
From OpenCV 3.2, findContours
doesn't modify the input image.
Thanks to Fernando Bertoldi for reviewing the answer