How to copy one part of image & paste it in another part of that image in Python | Using OpenCV library

Table of Contents

Demonstration

You can copy One part of image and paste it in another part of that image in Python. Image is divided into row and column pixels.

We are going to use OpenCV library here , You can download OpenCV library easily , than import it –

import cv2

Now , to load image from the file you can use imread() function of OpenCV library like –

import cv2
img =cv2.imread('assets/logo.jpg',-1)

In imread function in above code , I have given path of image , you can give your image path there.

Now , to copy one part of image & paste it in another part of that image , you could do like –

import cv2
img =cv2.imread('assets/logo.jpg',-1)

tag= img[500:700 , 600:900]
img[100:300 , 650:950]=tag

Full Code

Full Code to copy one part of image & paste it in another part of that image in Python –

import cv2
img =cv2.imread('assets/logo.jpg',-1)

tag= img[500:700 , 600:900]
img[100:300 , 650:950]=tag

cv2.imshow('Image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()