Monday, December 06, 2021

Want to know if a person is happy or sad just by looking at their pic? Here's how you can do it.

 Many a times you look at a person and you don't know if they are happy or sad. Here's a way by which you can tell if they are happy or not just by using their photo. You can also tell their Age, Race, Gender just by following these steps . It will take just a few minutes. 

  • First of all, You need to go to google and search for google collaboration. Click Here.


  • Then you need to create a notebook just by entering any name you want and clicking new notebook.
  • On the left side you will find an upload button to upload files on this platform. Click on it and upload a picture which you want to test. Don't worry the photo is automatically deleted after you leave the site.


  • Then you will see a block in which you can write text/code. You have to write  " pip install deepface " and then press the play or Run cell button. Wait for a few seconds for the code to run.


  • Then copy and paste the given below text/code in the editor.
from deepface import deepFace
from PIL import Image
import cv2
import matplotlib.pyplot as plt
list_path = "Paste the Path here"
img = cv2.imread(list_path)
plt.imshow(img[:, :, ::-1])
image = Image.open(list_path)
image.show()
demography = DeepFace.analyze(list_path)
print("Age: ", demography["age"])
print("Gender: ", demography["gender"])
print("Emotion: ", demography["dominant_emotion"]
print("Race: ", demography["dominant_race"])

  • Go and copy the path of the photo you just uploaded on the notebook. For this move your cursor to the photo you just uploaded and right click on it and select the copy path option.


  • Paste this path in the line 5 of the above text/code where it is written "Paste the path here".
  • Hit the Play or run cell button, wait for a few seconds and You are done.


In this we used a simple python code and a deepface library by serengil to check for emotions and other things in a photo. You can use this code and create your very own first Python project and become a programmer.

Comment on this post and tell us if you like it and if you want another similar projects. It will help us to stay motivated and upload similar content for you. Follow the blog if you liked this post and check out our other posts too. Thank you for reading.



No comments:

Post a Comment

Popular Posts