Does a += 20 act differently to a = a + 20 for openCV?

it has flags we can check:

>>> a=np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> b = a[1:,1:]
>>> b.flags # a slice
  C_CONTIGUOUS : False
  OWNDATA : False
   ....
>>> b += 20 # still slice
  C_CONTIGUOUS : False
  OWNDATA : False
>>> (b+20).flags # no more
  C_CONTIGUOUS : True
  OWNDATA : True

so, already the result of the addition is no more a slice (unless its in-place !)
clearly a pitfall (and again not like the opencv c++ api does it)

1 Like