element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Bluetooth Unleashed Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Bluetooth Unleashed Design Challenge
  • More
  • Cancel
Bluetooth Unleashed Design Challenge
Blog Bluetooth Unleashed : AAPSAD #5 : Audio and Visuals
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: sakthi.1260
  • Date Created: 2 Jun 2018 4:34 PM Date Created
  • Views 1816 views
  • Likes 8 likes
  • Comments 6 comments
  • rpi 3b+
Related
Recommended

Bluetooth Unleashed : AAPSAD #5 : Audio and Visuals

sakthi.1260
sakthi.1260
2 Jun 2018

Hello guys,

Before I start, apologies for not responding to your comments, although I've been going through them I couldn't reply  to you guys have been running on a tight schedule.

Previously in Bluetooth Unleashed....

With no clue on recognizing facial expressions our hero was struggling to find a good API and finally ended in way to detect smiles and proceeded further.....

 

Now on Bluetooth Unleashed

Still unhappy with results and working with APIs in Parallel, I found out Google Vision to be satisfactory.

They have a very good documentation and found this YouTube Video to be much easier.

 

What I've done here is:

1) I've used OpenCV and a python script to capture an image and save it locally as emo.jpg, and call another python script (the Vision API).

2) This one Upload to the GCloud and returns a json response from which emotions could be fetched.

capture.py

import cv2
import numpy as np
import sys
import time
import os
facePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(facePath)
cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)
sF = 1.05

while True:
  ret, frame = cap.read()
  img = frame
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor= sF,
    minNeighbors=8,
    minSize=(55, 55),
    flags=cv2.CASCADE_SCALE_IMAGE
  )
  if (len(faces)):
     cv2.imwrite(filename = 'emo.jpg', img=frame)
    print('opening API')
    os.system('python emotion.py')
    time.sleep(10)
  c = cv2.waitKey(7) % 0x100
  if c == 27:
        break
cap.release()

This calls for the emotion.py which in turn return emotion values.

image

The next part is to play a soothing visual with a audio according. Will be using omxplayer to run them, I'm yet to find the proper visuals and audios. For now 3 music videos each emotions.

modified the emotion.py to play videos.

emotion.py

import io
import os

# Imports the Google Cloud client library
from google.cloud import vision
from google.cloud.vision import types

# Instantiates a client
client = vision.ImageAnnotatorClient()

# The name of the image file to annotate
file_name = 'emo.jpg'

# Loads the image into memory
with io.open(file_name, 'rb') as image_file:
    content = image_file.read()

image = types.Image(content=content)

# Performs label detection on the image file
response = client.face_detection(image=image)
faces = response.face_annotations
# 0-'UNKNOWN',1-'VERY_UNLIKELY',2-'UNLIKELY',3-'POSSIBLE',4-'LIKELY',5- 'VERY_LIKELY')
for face in faces:
    anger = face.anger_likelihood
    joy = face.joy_likelihood
    sorrow = face.sorrow_likelihood
#print(anger) print(joy) print(sorrow)
if (anger >= joy) and (anger >= sorrow):
   emo = 'a'
elif (joy >= anger) and (joy >= sorrow):
   emo = 'j'
else :
   emo = 's'

if emo == 'a' :
  os.system('omxplayer Anger.mp4')
  os.system('killall omxplayer.bin')
if emo == 'j' :
  os.system('omxplayer Joy.mp4')
  os.system('killall omxplayer.bin')
if emo == 's' :
  os.system('omxplayer Sorrow.mp4')
  os.system('killall omxplayer.bin')

I just ran the capture.py from putty and within 2seconds this came up on the Rpi screen

Here's a short clip on the output...

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • Sign in to reply

Top Comments

  • BigG
    BigG over 7 years ago +3
    Nice update. Have you looked into TensorFlow and their version for embedded systems: https://www.tensorflow.org/mobile/tflite/
  • DAB
    DAB over 7 years ago +3
    Good progress, I look forward to seeing the emotion algorithm in operation. DAB
  • genebren
    genebren over 7 years ago +2
    Nice update to your design challenge project. Looking at your last image and the last results, it looks like you totally nailed the 'joy' emotion, both in your ability to show joy and the programs ability…
  • sakthi.1260
    sakthi.1260 over 7 years ago in reply to genebren

    Hi Gene,

     

    Thanks a lot image, hoping it'd work the way i planned it to, although a few things are cloudy.

     

    Cheers,

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • sakthi.1260
    sakthi.1260 over 7 years ago in reply to DAB

    Hi DAB,

     

    Just to keep a positive vibe just kept the joy, it still finds a lot, will provide a complete video over different emotion on the final blog image

     

    Cheers,

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • sakthi.1260
    sakthi.1260 over 7 years ago in reply to BigG

    Hi,

    That was my first choice of preference had some issues with dependencies and had to use a bigger data set for making it properly work, so had to find something much easier to process, APIs were my first thought but there was a lot of them, had tried a few and finally settled with Google Vision.

     

    Cheers,
    Sakthi

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 7 years ago

    Nice update to your design challenge project.  Looking at your last image and the last results, it looks like you totally nailed the 'joy' emotion, both in your ability to show joy and the programs ability to detect it.  Well done!

     

    I look forward to seeing more of your updates and wish you success on getting the functionality your are hoping for.

    Gene

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 7 years ago

    Good progress,

     

    I look forward to seeing the emotion algorithm in operation.

     

    DAB

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube