Libraries Required for this
1.numpy
2.Matplotlib
3.opencv
Taking input from the user using
img1 = cv2.imread("imageone.jpg")
img2 = cv2.imread("imagetwo.png")
Converting both the images into RGB format from BGR
img1 = cv2.cvtColor(img1,cv2.COLOR_BGR2RGB)
Showing image using Matplotlib
plt.imshow(imagename)
Make sure that both the images are of same sizes to add them together one can check the shape of the image and confirm whether both image has same size
using
imgname.shape
return (x,y,[RGB])
Cropping the image
cropimg1 = img1[1000:1700 , 400:1300]
plt.imshow(cropimg1)
Resizing the image
cropimg1= cv2.resize(cropimg1,(900,400))
cropimg2= cv2.resize(cropimg2,(900,700))
Swapping the Two part
img1[1000:1700 , 400:1300] = cropimg2
plt.imshow(img1)
Comments