Creating Image, Swapping Image and Creating Collage
Jun 12, 2021
Task-4.1
Creating an image
import cv2
import numpy as np
img = np.zeros([500,500,3])
img = cv2.rectangle(img,(100,250),(400,475),[0,0,255],-1)
img = cv2.line(img,(100,250),(250,100),[1,1,1],5)
img = cv2.line(img,(400,250),(250,100),[1,1,1],5)img
img = cv2.rectangle(img,(220,300)(280,475),[0,255,0],-1)
cv2.imshow('hi',img)
cv2.waitkey()
cv2.destroyAllWindows()
Task-4.2
Take 2 image crop some part of both image and swap it.
pic1 = cv2.resize(cv2.imread('Dhoni.jpg'),(500,500))
pic2 = cv2.resize(cv2.imread('v.jpg'),(500,500))
The Images are:
Cropping face of 1st image.
p = pic2[10:300,170:290]
cv2.imshow("pic2",p)
cv2.waitkey()
cv2.destroyAllWindows()
Cropping face of 2nd image.
p2 = pic1[10:300,170:290]
cv2.imshow("pic2",p2)
cv2.waitkey()
cv2.destroyAllWindows()
Swapping Face image
pic1[10:300,170:290] = pic2[10:300,170:290]
cv2.imshow("pic1",pic1)
cv2.waitkey()
cv2.destroyAllWindows()
Swapped face images
pic1 = cv2.resize(cv2.imread('Dhoni.jpg'),(500,500))
pic2 = cv2.resize(cv2.imread('v.jpg'),(500,500))
pic2[10:300,170:290] = pic1[10:300,170:290]
cv2.imshow("Task 4.2",pic2)
cv2.waitkey()
cv2.destroyAllWindows()
Task-4.3
Take 2 image and combine it to form a single image.
pic1 = cv2.imread('MS.jpg')
pic2 = cv2.imread('V.jpg')
Making Vertical collage
ab = np.vstack((pic1,pic2))
cv2.imshow('hi',ab)
cv2.Waitkey()
cv2.destroyAllWindows()
Making Horizontal Collage
a = np.hstack((pic1,pic2))
cv2.imshow('hi',a)
cv2.Waitkey()
cv2.destroyAllWindows()
Thank you!!!