Clone an image in cv2 python

tintin picture tintin · May 14, 2013 · Viewed 136.7k times · Source

I'm new to opencv, here is a question, what is the python function which act the same as cv::clone() in cpp? I just try to get a rect by

    rectImg = img[10:20, 10:20]

but when I draw a line on it ,I find the line appear both on img and the rectImage,so , how can I get this done?

Answer

Ash Ketchum picture Ash Ketchum · Feb 27, 2016

The first answer is correct but you say that you are using cv2 which inherently uses numpy arrays. So, to make a complete different copy of say "myImage":

newImage = myImage.copy()

The above is enough. No need to import numpy.