Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clone an image in cv2 python

Tags:

python

opencv

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?

like image 618
tintin Avatar asked May 14 '13 00:05

tintin


People also ask

How do I copy an image on cv2?

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.

How do you duplicate an image in Python?

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.

How do I mirror an image in cv2?

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.

What is cv2 Imread ()?

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.


1 Answers

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.

like image 65
Ash Ketchum Avatar answered Sep 24 '22 23:09

Ash Ketchum