https://drive.google.com/file/d/1v0JBqhe5Xg15vDe2HPmWNa6ovpBqELEv/view?usp=sharing
here is my code
How to put glasses and mustache on the picture
Hey @Ajitverma1503, this would help
x,y,w,h=eyes[0]
overlay=cv2.imread("Train/glasses.png",cv2.IMREAD_UNCHANGED)
overlay=cv2.cvtColor(overlay,cv2.COLOR_BGRA2RGBA)
overlay=cv2.resize(overlay,(w,h))
for i in range(overlay.shape[0]):
for j in range(overlay.shape[1]):
if(overlay[i,j,3]>0):
fullimg[y+i,x+j,:]=overlay[i,j,:-1]
Simalarly do this for nose.
Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section.
I am unable to the glasses on the correct position.Can you explain me how to find the coordinate and put the glasses on that coordinate.
here is my code : https://ide.codingblocks.com/s/200187
Hey @Ajitverma1503, make sure you have opencv versoin 3.4, if it is not than
pip install opencv-python==3.4.0.18 or any other version that appears in the list.
Also I have already shared the complete code for glasses to be placed, you need not to make any single change, in that.
Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts.
I think you got me wrong my question is I am unable to put the glasses on the correct position. Can you explain me how to find the coordinate and put the glasses on that coordinate.
Hey @Ajitverma1503, yes i was saying that only, here is the code
import cv2
import matplotlib.pyplot as plt
img = cv2.imread('./Train/Jamie_Before.jpg')
glasses = cv2.imread("./Train/glasses.png",cv2.IMREAD_UNCHANGED)
glasses = cv2.cvtColor(glasses,cv2.COLOR_BGRA2RGBA)
face_cascade = cv2.CascadeClassifier('./Train/third-party/haarcascade_frontalface_alt.xml')
eye_cascade = cv2.CascadeClassifier('./Train/third-party/frontalEyes35x16.xml')
nose_cascade = cv2.CascadeClassifier('./Train/third-party/Nose18x15.xml')
# plt.imshow(img)
eyes = eye_cascade.detectMultiScale(img,1.3,5)
noses = nose_cascade.detectMultiScale(img,1.3,5)
(x,y,w,h) = eyes[0]
glasses = cv2.resize(glasses,(w,h))
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
for i in range(glasses.shape[0]):
for j in range(glasses.shape[1]):
if(glasses[i,j,3]>0):
img[y+i, x+j,:]=glasses[i,j,:-1]
for (nx,ny,nw,nh) in noses:
cv2.rectangle(img,(nx,ny),(nx+nw,ny+nh),(0,255,0),2)
# cv2.imshow("Img",img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()
plt.imshow(img)
plt.show()
Hope this resolved your doubt.
Plz mark the doubt as resolved in my doubts section.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.