Skip to content
Snippets Groups Projects
Commit 1698f68d authored by Antonio Andriella's avatar Antonio Andriella
Browse files

Working version with new eyes

parent 253afd15
No related branches found
No related tags found
No related merge requests found
...@@ -11,9 +11,8 @@ import rospy ...@@ -11,9 +11,8 @@ import rospy
class Eye: class Eye:
def __init__(self): def __init__(self, file):
self.robot_gender = rospy.get_param("/gender") self.eyes = Image.open(file) # eye image
self.eyes = Image.open("test/pupil.png") # eye image
self.positionX = 0 # keeps the x position as a coordinate self.positionX = 0 # keeps the x position as a coordinate
self.positionY = 0 # keeps the y position as a coordinate self.positionY = 0 # keeps the y position as a coordinate
......
...@@ -13,12 +13,13 @@ class Eyebrow: ...@@ -13,12 +13,13 @@ class Eyebrow:
indexOfEyebrow = 0 # choosen element of the array indexOfEyebrow = 0 # choosen element of the array
def __init__(self, initEyebrow): def __init__(self, initEyebrow):
self.robot_gender = rospy.get_param("/gender")
# This array keeps the diffirent shape of eyebrow # This array keeps the diffirent shape of eyebrow
self.eyebrows = [ self.eyebrows = [
Image.open("test/eye_brow_neutral.png"),
Image.open("test/eye_brow_happy.png"), Image.open("test/eye_brow_happy.png"),
Image.open("test/eye_brow_sad.png"), Image.open("test/eye_brow_sad.png"),
Image.open("test/eye_brow_angry.png"), Image.open("test/eye_brow_confused.png"),
Image.open("test/eye_brow_angry.png")
#Image.open("data/"+self.robot_gender+"/eyebrow/baxter_eyebrow_3.png"), #Image.open("data/"+self.robot_gender+"/eyebrow/baxter_eyebrow_3.png"),
#Image.open("data/"+self.robot_gender+"/eyebrow/baxter_eyebrow_4.png") #Image.open("data/"+self.robot_gender+"/eyebrow/baxter_eyebrow_4.png")
] ]
......
...@@ -11,7 +11,6 @@ import rospy ...@@ -11,7 +11,6 @@ import rospy
class Eyelid: class Eyelid:
def __init__(self): def __init__(self):
self.robot_gender = rospy.get_param("/gender")
self.eyelid = Image.open("test/eyelid.png") # eyelid image self.eyelid = Image.open("test/eyelid.png") # eyelid image
self.position = 0 # y position, we don't need x position because of vertical movment. self.position = 0 # y position, we don't need x position because of vertical movment.
......
...@@ -54,17 +54,16 @@ import rospy ...@@ -54,17 +54,16 @@ import rospy
class Face: class Face:
def __init__(self): def __init__(self):
self.robot_gender = rospy.get_param("/gender")
# determine the path and set the default path place # determine the path and set the default path place
os.chdir(r'/home/{}/pal/cognitive_game_ws/src/robot_facial_expression/scripts'.format(getpass.getuser())) os.chdir(r'/home/{}/pal/cognitive_game_ws/src/robot_facial_expression/scripts'.format(getpass.getuser()))
''' Parts of the face of baxter are defined.''' ''' Parts of the face of baxter are defined.'''
self.backgroundImage = Image.open("data/"+self.robot_gender+"/baxter_background.png") # Background behind the eyes self.backgroundImage = Image.open("data/baxter_background.png") # Background behind the eyes
# Face partions objects # Face partions objects
self.eye = Eye.Eye("test/pupil.png")
self.skin = Skin.Skin(5) # range: [0, 5] self.skin = Skin.Skin(5) # range: [0, 5]
self.mouth = Mouth.Mouth(2) # range: [0, 6] self.mouth = Mouth.Mouth(2) # range: [0, 6]
self.eyebrow = Eyebrow.Eyebrow(2) # range: [0, 3] self.eyebrow = Eyebrow.Eyebrow(2) # range: [0, 3]
self.eye = Eye.Eye()
self.eyelid = Eyelid.Eyelid() self.eyelid = Eyelid.Eyelid()
self.eyelid.setPosition(-330) self.eyelid.setPosition(-330)
self.eyesCoordinateX = self.eye.getPositionX() self.eyesCoordinateX = self.eye.getPositionX()
...@@ -72,6 +71,7 @@ class Face: ...@@ -72,6 +71,7 @@ class Face:
# buildFace function is combining the all face parts together. # buildFace function is combining the all face parts together.
def buildFace(self): def buildFace(self):
#self.eye = Eye.Eye("test/pupil.png")
# Merging the layers # Merging the layers
faceImage = self.backgroundImage.copy() faceImage = self.backgroundImage.copy()
faceImage.paste(self.eye.getEyes(), (int(self.eye.getPositionX()), int(self.eye.getPositionY())), self.eye.getEyes()) faceImage.paste(self.eye.getEyes(), (int(self.eye.getPositionX()), int(self.eye.getPositionY())), self.eye.getEyes())
...@@ -82,9 +82,23 @@ class Face: ...@@ -82,9 +82,23 @@ class Face:
image = array(faceImage) image = array(faceImage)
return image return image
# def buildFaceHappy(self):
# self.eye = Eye.Eye("test/pupil_happy.png")
# # Merging the layers
# faceImage = self.backgroundImage.copy()
# faceImage.paste(self.eye.getEyes(), (int(self.eye.getPositionX()), int(self.eye.getPositionY())), self.eye.getEyes())
# faceImage.paste(self.eyelid.getEyelid(), (0, self.eyelid.getPosition()), self.eyelid.getEyelid())
# faceImage.paste(self.skin.getSkin(), (0, 0), self.skin.getSkin())
# #faceImage.paste(self.mouth.getMouth(), (0, 0), self.mouth.getMouth())
# faceImage.paste(self.eyebrow.getEyebrow(), (0, 0), self.eyebrow.getEyebrow())
# image = array(faceImage)
# return image
def show(self, publish): def show(self, publish):
image = self.buildFace() image = self.buildFace()
publish(image) publish(image)
#def show_happy(self, publish):
# image = self.buildFaceHappy()
# publish(image)
# Reposition of the eyes of the baxter # Reposition of the eyes of the baxter
# This function provide with the eyes' simulation movement # This function provide with the eyes' simulation movement
...@@ -111,7 +125,7 @@ class Face: ...@@ -111,7 +125,7 @@ class Face:
def lookWithMotionDynamic(self, cv2, destinationX, destinationY, time, publish, wobbler): def lookWithMotionDynamic(self, cv2, destinationX, destinationY, time, publish, wobbler):
# if it is not initilized don't applicate the function # if it is not initilized don't applicate the function
if wobbler != None: if wobbler != None:
# taking head position as a coordinate # taking head position as a coordinate
headPositionRadian = wobbler.getPosition() headPositionRadian = wobbler.getPosition()
headPositionCoordinate = self.radianToCoordinate(headPositionRadian) headPositionCoordinate = self.radianToCoordinate(headPositionRadian)
...@@ -130,7 +144,7 @@ class Face: ...@@ -130,7 +144,7 @@ class Face:
def lookExactCoordinateDynamic(self, destinationX, destinationY, publish, wobbler): def lookExactCoordinateDynamic(self, destinationX, destinationY, publish, wobbler):
# Looking the given coordinate according to the position of the head. # Looking the given coordinate according to the position of the head.
if wobbler != None: if wobbler != None:
# taking head position as a coordinate # taking head position as a coordinate
headPositionRadian = wobbler.getPosition() headPositionRadian = wobbler.getPosition()
headPositionCoordinate = self.radianToCoordinate(headPositionRadian) headPositionCoordinate = self.radianToCoordinate(headPositionRadian)
...@@ -139,7 +153,7 @@ class Face: ...@@ -139,7 +153,7 @@ class Face:
# wobbling -> look at the given coordinates physicly # wobbling -> look at the given coordinates physicly
print "Wobbling to: ", destinationX print "Wobbling to: ", destinationX
wobbler.wobble(self.coordinateToRadian(destinationX)) wobbler.wobble(self.coordinateToRadian(destinationX))
self.eye.lookExactCoordinate(0, destinationY) self.eye.lookExactCoordinate(0, destinationY)
else: else:
# Normal looking with eyes with an animation # Normal looking with eyes with an animation
destinationX = destinationX - headPositionCoordinate destinationX = destinationX - headPositionCoordinate
...@@ -153,6 +167,7 @@ class Face: ...@@ -153,6 +167,7 @@ class Face:
""" """
def winkMove(self, cv2, destinationPosition, time, publish): def winkMove(self, cv2, destinationPosition, time, publish):
# Animation initial values # Animation initial values
startTime = timeit.default_timer() startTime = timeit.default_timer()
currentTime = timeit.default_timer() currentTime = timeit.default_timer()
...@@ -219,7 +234,7 @@ class Face: ...@@ -219,7 +234,7 @@ class Face:
self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen. self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen.
self.skin.setSkin(2) self.skin.setSkin(2)
mouthIndex = 4#random.choice(mouthArray) mouthIndex = 4#random.choice(mouthArray)
eyebrowIndex = 0#random.choice(eyeBrowArray) eyebrowIndex = 1#random.choice(eyeBrowArray)
self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish)
def emotion_neutral(self, cv2, publish): def emotion_neutral(self, cv2, publish):
...@@ -236,7 +251,7 @@ class Face: ...@@ -236,7 +251,7 @@ class Face:
self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen. self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen.
self.skin.setSkin(4) self.skin.setSkin(4)
mouthIndex = random.choice(mouthArray) mouthIndex = random.choice(mouthArray)
eyebrowIndex = 2#random.choice(eyeBrowArray) eyebrowIndex = 4#random.choice(eyeBrowArray)
self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish)
def emotion_confused(self, cv2, publish): def emotion_confused(self, cv2, publish):
...@@ -245,7 +260,7 @@ class Face: ...@@ -245,7 +260,7 @@ class Face:
self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen. self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen.
self.skin.setSkin(3) self.skin.setSkin(3)
mouthIndex = random.choice(mouthArray) mouthIndex = random.choice(mouthArray)
eyebrowIndex = random.choice(eyeBrowArray) eyebrowIndex = 3
self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish)
def emotion_sad(self, cv2, publish): def emotion_sad(self, cv2, publish):
...@@ -254,7 +269,7 @@ class Face: ...@@ -254,7 +269,7 @@ class Face:
self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen. self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen.
self.skin.setSkin(1) self.skin.setSkin(1)
mouthIndex = 1#random.choice(mouthArray) mouthIndex = 1#random.choice(mouthArray)
eyebrowIndex = 1#random.choice(eyeBrowArray) eyebrowIndex = 2#random.choice(eyeBrowArray)
self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish)
def emotion_panic(self, cv2, publish): def emotion_panic(self, cv2, publish):
...@@ -284,16 +299,6 @@ class Face: ...@@ -284,16 +299,6 @@ class Face:
eyebrowIndex = random.choice(eyeBrowArray) eyebrowIndex = random.choice(eyeBrowArray)
self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish)
def testAllImages(self, cv2, publish):
for index in range(6):
self.skin.setSkin(index)
self.show(publish)
for index in range(7):
self.showEmotion(index, 0, cv2, publish)
time.sleep(0.1)
for index in range(5):
self.showEmotion(1, index, cv2, publish)
time.sleep(0.1)
""" Head Joint move calculations """ """ Head Joint move calculations """
......
...@@ -13,16 +13,10 @@ class Mouth: ...@@ -13,16 +13,10 @@ class Mouth:
indexOfMouth = 0 # choosen element of the array indexOfMouth = 0 # choosen element of the array
def __init__(self, initMouth): def __init__(self, initMouth):
self.robot_gender = rospy.get_param("/gender")
# This array keeps the diffirent shape of mouth # This array keeps the diffirent shape of mouth
self.mouths = [ self.mouths = [
Image.open("data/"+self.robot_gender+"/mouth/baxter_mouth_angry.png"),
Image.open("data/"+self.robot_gender+"/mouth/baxter_mouth_boring.png"),
Image.open("data/"+self.robot_gender+"/mouth/baxter_mouth_confused.png"),
Image.open("data/"+self.robot_gender+"/mouth/baxter_mouth_sad.png"),
Image.open("data/"+self.robot_gender+"/mouth/baxter_mouth_smile_open.png"),
Image.open("data/"+self.robot_gender+"/mouth/baxter_mouth_neutral.png")
#Image.open("data/mouth/baxter_mouth_smile_open.png") #Image.open("data/mouth/baxter_mouth_smile_open.png")
] ]
......
...@@ -13,7 +13,6 @@ class Skin: ...@@ -13,7 +13,6 @@ class Skin:
indexOfSkin = 5 # choosen element of the array indexOfSkin = 5 # choosen element of the array
def __init__(self, initSkin): def __init__(self, initSkin):
self.robot_gender = rospy.get_param("/gender")
# This array keeps the diffirent colour version of skin # This array keeps the diffirent colour version of skin
self.skins = [ self.skins = [
......
...@@ -151,7 +151,7 @@ def callback_Command(data): ...@@ -151,7 +151,7 @@ def callback_Command(data):
if msgs[0] == "happy" : if msgs[0] == "happy" :
face.emotion_happy(cv2, publish_image) face.emotion_happy(cv2, publish_image)
print "Emotion happy is applicated" print "Emotion happy is applicated"
elif msgs[0] == "angry" : elif msgs[0] == "angry" :
face.emotion_angry(cv2, publish_image) face.emotion_angry(cv2, publish_image)
print "Emotion angry is applicated" print "Emotion angry is applicated"
...@@ -225,7 +225,7 @@ def callback_Command(data): ...@@ -225,7 +225,7 @@ def callback_Command(data):
if msgs[0] == "look" : if msgs[0] == "look" :
x = int(msgs[1]) x = int(msgs[1])
y = int(msgs[2]) y = int(msgs[2])
face.lookWithMotion(cv2, x, y, 0.5, publish_image) face.lookWithMotion(cv2, x, y, 0.8, publish_image)
elif msgs[0] == "human" and msgs[1] == "follow" and msgs[2] == "on" : elif msgs[0] == "human" and msgs[1] == "follow" and msgs[2] == "on" :
face.lookWithMotion(cv2, 0, 0, 0.5, publish_image) face.lookWithMotion(cv2, 0, 0, 0.5, publish_image)
......
scripts/test/eye_brow_confused.png

18.7 KiB

scripts/test/eye_brow_happy.png

17.6 KiB | W: | H:

scripts/test/eye_brow_happy.png

24 KiB | W: | H:

scripts/test/eye_brow_happy.png
scripts/test/eye_brow_happy.png
scripts/test/eye_brow_happy.png
scripts/test/eye_brow_happy.png
  • 2-up
  • Swipe
  • Onion skin
scripts/test/eye_brow_neutral.png

17.6 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment