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.
Python PIL | copy() method PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. PIL. Image. copy() method copies the image to another image object, this method is useful when we need to copy the image but also retain the original.
Example – 1: Flip the Image Horizontally with cv2.To flip the image horizontally, i.e. along the y-axis we need to pass a positive value of flipCode. In this example, we pass flipCode = 1 along with the image name.
cv2. imread() method loads an image from the specified file. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format) then this method returns an empty matrix.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With