👨‍💻Image Processing using Python Library OpenCV

Let’s start

Install OpenCV

pip install opencv-python
import cv2
import numpy as np
l = np.zeros((500,600,3))
l[60:120,120:180]=1
l[60:120,600-180:600-120]=1
l[220:280,270:320]=[0,255,255]
l[340:380,140:470]=1
l[10:12]=1
l[-12:-10]=1
l[:,10:12]=1
l[:,-12:-10]=1
def showImg(data):
cv2.imshow("new",data)
cv2.waitKey()
cv2.destroyAllWindows()
#part 1 taking co-ordinates of faces.
j=newimg[:,:295]
jfinal=cv2.resize(j,(320,320))
i=newimg[190:,295:]
ifinal=cv2.resize(i,(320,320))
jcrop=jfinal[10:105,70:-50]
icrop=ifinal[30:160,:230]
#part 2 creating same dimensions.
width = int(jcrop.shape[1] * 230/200) # here dividing the column of jerrys face shape by the column of tom's face to make
height = int(jcrop.shape[0] * 130/95) # same shape of boy inorder to swap it
dim = (width, height)
final_crp = cv2.resize(jcrop, dim, interpolation=cv2.INTER_AREA)
#part 3 flip image horizontally
final_crp = cv2.flip(final_crp,1)
final_image=np.concatenate((j,i),1) # final=np.hstack((img1,img2))
showImg(final_image)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store