The code img2 = img2 + 20 would not change the img2 part of img1 even though I used shallow copying.
However, if I changed the code to img2 += 20 it would work as I wished.
Does openCV work these operations differently? or am I misunderstanding something?
python has variables and objects. a variable acts like a reference, it points to an object. multiple variables can point to the same object.
the = operator assigns whatever’s on the right, to the variable name on the left. in the case of foo = foo + 20, that changes the reference (variable) to point to a new object.
the += operator calls a method of the object on the left. this can actually change the object.
when you say img2 = img1[200:400, 200:400], that is a slice, and that’s a view of img1, so you change img1 when you change img2.