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?
If you use
cv2, correct method is to use
.copy() method in Numpy. It will create a copy of the array you need. Otherwise it will produce only a view of that object.
In : import numpy as np In : x = np.arange(10*10).reshape((10,10)) In : y = x[3:7,3:7].copy() In : y[2,2] = 1000 In : 1000 in x Out: False # see, 1000 in y doesn't change values in x, parent array.
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.