Ask Your Question

Revision history [back]

As reported in the bug report this behaviours is completely normal.

AFAIK copyTo only couples the header of the new Mat element with the header of the original file. In memory they are still pointing to the same data. The clone() operation makes a deep copy and ensures that a pointer to new memory is created.

So basically it is normal that your code produces two different results. The first Sobel is on the original data, however the second Sobel is applied on an already Sobel applied image and thus the end result will be different.

I suggest adjusting this line

orig.copyTo(copy);

to

copy = orig.clone();

And the result will be as expected.

The logic behind is the use of smart pointers in OpenCV which try to minimize the memory print of an application but which can lead to very unexpected behaviour.