1 | initial version |
You are getting a copy of the Mat object, but not a copy of the data. The explanation is simple, just look at the Mat class:
class CV_EXPORTS Mat
{
public:
// ... a lot of methods ...
...
/*! includes several bit-fields:
- the magic signature
- continuity flag
- depth
- number of channels
*/
int flags;
//! the array dimensionality, >= 2
int dims;
//! the number of rows and columns or (-1, -1) when the array has more than 2 dimensions
int rows, cols;
//! pointer to the data
uchar* data;
//! pointer to the reference counter;
// when array points to user-allocated data, the pointer is NULL
int* refcount;
// other members
...
};
You have a uchar pointer to the data. So what happens in your function is that you simply copy the pointer (and of course the rest). The copy of the pointer is still pointing to the original data, so when you modify the Mat, you also modify the input Mat.