Python cv2.findContour from OpenCV

Try:

img = uint8([[0,255,255,0],[0,255,255,0],[0,255,255,0],[0,255,255,0]])
contours, hierarchy = cv2.findContours( img,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE )
img

And you will probbably get:

array([[  0,   0,   0,   0],
        [  0,   2, 130,   0],
        [  0,   2, 130,   0],
        [  0,   0,   0,   0]], dtype=uint8)

This does not seem to be the expected behavior, as the input image has changed. However it is documented_ that img is InputOutputArray (at least for C++), and since python uses cv2.so library this is probbably inherited behavior. However, there is a simple workaround this, by simply using: img.copy()