import cv2
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
img = cv2.imread(‘C:\Users\abhis\Before.png’)
eye_cascade = cv2.CascadeClassifier(‘frontalEyes35x16.xml’)
specs = cv2.imread(“glasses.png”, -1)
eye = eye_cascade.detectMultiScale(img, 1.3,5)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
i = 0
for (x, y, w, h) in eye:
cv2.rectangle(gray, (x, y), (x + w, y + h), (125, 155, 155), 3)
i = 1
break
if i == 0:
print(“not found”)
exit()
img = cv2.cvtColor(img, cv2.COLOR_BGR2BGRA)
specs = cv2.resize(specs, (w, h))
w, h, c = specs.shape
w = int(w-25)
for i in range(0, w):
for j in range(0, h):
if specs[i, j][3] != 0:
img[y + i, x + j] = specs[i, j]
nose = cv2.imread(“mustache.png”, -1)
mouth_cascade = cv2.CascadeClassifier(‘Nose18x15.xml’)
mouth = mouth_cascade.detectMultiScale(img, 1.3, 5)
i = 0
for (x, y, w, h) in mouth:
cv2.rectangle(gray, (x, y), (x + w, y + h), (125, 255, 125), 3)
i = 1
if i == 0:
print(“not found”)
exit()
mus = cv2.resize(nose,(w+40,h))
w,h,c = mus.shape
y+=int(h/4)
x+=int(w-60)
for i in range(0,w):
for j in range(0,h):
if mus[i,j][3] !=0:
img[y+i,x+j] = mus[i,j]
cv2.imshow(‘image’, img)
frame = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
plt.imshow(frame)
plt.show()
frame = np.array(frame, dtype=“float32”)/255.
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
cv2.imwrite(“img.jpg”, frame)
frame = frame.flatten().reshape((-1,3))
df = pd.DataFrame(frame, columns=[“Channel 1”,“Channel 2”, “Channel 3”])
df.to_csv(“pred.csv”, index=False)
cv2.waitKey(0)
cv2.destroyAllWindows()
