diff --git a/scripts/Eye.py b/scripts/Eye.py index 3d5d3394d8d7133f594dc6536372e677d7d0641a..4906aea1f445bf8a4fef5af50235316b5a1a4cdb 100755 --- a/scripts/Eye.py +++ b/scripts/Eye.py @@ -11,9 +11,8 @@ import rospy class Eye: - def __init__(self): - self.robot_gender = rospy.get_param("/gender") - self.eyes = Image.open("test/pupil.png") # eye image + def __init__(self, file): + self.eyes = Image.open(file) # eye image self.positionX = 0 # keeps the x position as a coordinate self.positionY = 0 # keeps the y position as a coordinate diff --git a/scripts/Eyebrow.py b/scripts/Eyebrow.py index 237f36ad96507134550f962627c8387b8a7489f6..274ff441bb9f6ffef7cc9d168d5dc6f310b6a6e0 100755 --- a/scripts/Eyebrow.py +++ b/scripts/Eyebrow.py @@ -13,12 +13,13 @@ class Eyebrow: indexOfEyebrow = 0 # choosen element of the array def __init__(self, initEyebrow): - self.robot_gender = rospy.get_param("/gender") # This array keeps the diffirent shape of eyebrow self.eyebrows = [ + Image.open("test/eye_brow_neutral.png"), Image.open("test/eye_brow_happy.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_4.png") ] diff --git a/scripts/Eyelid.py b/scripts/Eyelid.py index bb8c4288afadd2a72758ca78d82e07e21def4bd3..3d8befe8a260dfb1036540c042dd424606921de5 100755 --- a/scripts/Eyelid.py +++ b/scripts/Eyelid.py @@ -11,7 +11,6 @@ import rospy class Eyelid: def __init__(self): - self.robot_gender = rospy.get_param("/gender") self.eyelid = Image.open("test/eyelid.png") # eyelid image self.position = 0 # y position, we don't need x position because of vertical movment. diff --git a/scripts/Face.py b/scripts/Face.py index ee922249ac4f846b1596f827aa6fd7b05ef58fbb..ad563204b9785cd28231e60c1123b11401aa94a1 100755 --- a/scripts/Face.py +++ b/scripts/Face.py @@ -54,17 +54,16 @@ import rospy class Face: def __init__(self): - self.robot_gender = rospy.get_param("/gender") # 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())) ''' 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 + self.eye = Eye.Eye("test/pupil.png") self.skin = Skin.Skin(5) # range: [0, 5] self.mouth = Mouth.Mouth(2) # range: [0, 6] self.eyebrow = Eyebrow.Eyebrow(2) # range: [0, 3] - self.eye = Eye.Eye() self.eyelid = Eyelid.Eyelid() self.eyelid.setPosition(-330) self.eyesCoordinateX = self.eye.getPositionX() @@ -72,6 +71,7 @@ class Face: # buildFace function is combining the all face parts together. def buildFace(self): + #self.eye = Eye.Eye("test/pupil.png") # Merging the layers faceImage = self.backgroundImage.copy() faceImage.paste(self.eye.getEyes(), (int(self.eye.getPositionX()), int(self.eye.getPositionY())), self.eye.getEyes()) @@ -82,9 +82,23 @@ class Face: image = array(faceImage) 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): image = self.buildFace() publish(image) + #def show_happy(self, publish): + # image = self.buildFaceHappy() + # publish(image) # Reposition of the eyes of the baxter # This function provide with the eyes' simulation movement @@ -111,7 +125,7 @@ class Face: def lookWithMotionDynamic(self, cv2, destinationX, destinationY, time, publish, wobbler): # if it is not initilized don't applicate the function - if wobbler != None: + if wobbler != None: # taking head position as a coordinate headPositionRadian = wobbler.getPosition() headPositionCoordinate = self.radianToCoordinate(headPositionRadian) @@ -130,7 +144,7 @@ class Face: def lookExactCoordinateDynamic(self, destinationX, destinationY, publish, wobbler): # Looking the given coordinate according to the position of the head. - if wobbler != None: + if wobbler != None: # taking head position as a coordinate headPositionRadian = wobbler.getPosition() headPositionCoordinate = self.radianToCoordinate(headPositionRadian) @@ -139,7 +153,7 @@ class Face: # wobbling -> look at the given coordinates physicly print "Wobbling to: ", destinationX wobbler.wobble(self.coordinateToRadian(destinationX)) - self.eye.lookExactCoordinate(0, destinationY) + self.eye.lookExactCoordinate(0, destinationY) else: # Normal looking with eyes with an animation destinationX = destinationX - headPositionCoordinate @@ -153,6 +167,7 @@ class Face: """ def winkMove(self, cv2, destinationPosition, time, publish): + # Animation initial values startTime = timeit.default_timer() currentTime = timeit.default_timer() @@ -219,7 +234,7 @@ class Face: self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen. self.skin.setSkin(2) mouthIndex = 4#random.choice(mouthArray) - eyebrowIndex = 0#random.choice(eyeBrowArray) + eyebrowIndex = 1#random.choice(eyeBrowArray) self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) def emotion_neutral(self, cv2, publish): @@ -236,7 +251,7 @@ class Face: self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen. self.skin.setSkin(4) mouthIndex = random.choice(mouthArray) - eyebrowIndex = 2#random.choice(eyeBrowArray) + eyebrowIndex = 4#random.choice(eyeBrowArray) self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) def emotion_confused(self, cv2, publish): @@ -245,7 +260,7 @@ class Face: self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen. self.skin.setSkin(3) mouthIndex = random.choice(mouthArray) - eyebrowIndex = random.choice(eyeBrowArray) + eyebrowIndex = 3 self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) def emotion_sad(self, cv2, publish): @@ -254,7 +269,7 @@ class Face: self.winkMove(cv2, -330, 0.3, publish) # Eyelids are not seen. self.skin.setSkin(1) mouthIndex = 1#random.choice(mouthArray) - eyebrowIndex = 1#random.choice(eyeBrowArray) + eyebrowIndex = 2#random.choice(eyeBrowArray) self.showEmotion(mouthIndex, eyebrowIndex, cv2, publish) def emotion_panic(self, cv2, publish): @@ -284,16 +299,6 @@ class Face: eyebrowIndex = random.choice(eyeBrowArray) 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 """ diff --git a/scripts/Mouth.py b/scripts/Mouth.py index e0ecf68e2910d92587bc26e48cd7cc56a4649677..4044b6eb1955bad7265a175088a2710cd5014b6b 100755 --- a/scripts/Mouth.py +++ b/scripts/Mouth.py @@ -13,16 +13,10 @@ class Mouth: indexOfMouth = 0 # choosen element of the array def __init__(self, initMouth): - self.robot_gender = rospy.get_param("/gender") # This array keeps the diffirent shape of mouth 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") ] diff --git a/scripts/Skin.py b/scripts/Skin.py index d2131b50d19c80286d12d51c86f520ca6c8a1386..fc8b532b90896963145b75454f819f7e53466de5 100755 --- a/scripts/Skin.py +++ b/scripts/Skin.py @@ -13,7 +13,6 @@ class Skin: indexOfSkin = 5 # choosen element of the array def __init__(self, initSkin): - self.robot_gender = rospy.get_param("/gender") # This array keeps the diffirent colour version of skin self.skins = [ diff --git a/scripts/screen_listener.py b/scripts/screen_listener.py index b429cd7faee3ad31532df124ba4032bd4d0d06f5..e15ae399825db3b6834067bf077d0ff3105c35a3 100755 --- a/scripts/screen_listener.py +++ b/scripts/screen_listener.py @@ -151,7 +151,7 @@ def callback_Command(data): if msgs[0] == "happy" : face.emotion_happy(cv2, publish_image) print "Emotion happy is applicated" - + elif msgs[0] == "angry" : face.emotion_angry(cv2, publish_image) print "Emotion angry is applicated" @@ -225,7 +225,7 @@ def callback_Command(data): if msgs[0] == "look" : x = int(msgs[1]) 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" : face.lookWithMotion(cv2, 0, 0, 0.5, publish_image) diff --git a/scripts/test/eye_brow_confused.png b/scripts/test/eye_brow_confused.png new file mode 100644 index 0000000000000000000000000000000000000000..a7906857645aebf2fa4fc92dbe7cddf13f2171a2 Binary files /dev/null and b/scripts/test/eye_brow_confused.png differ diff --git a/scripts/test/eye_brow_happy.png b/scripts/test/eye_brow_happy.png index 3f451558b59811c1c4b0fc38405c27e9bce35d5b..d208b43fe81ae53519ecbc08810a694a6a16612d 100644 Binary files a/scripts/test/eye_brow_happy.png and b/scripts/test/eye_brow_happy.png differ diff --git a/scripts/test/eye_brow_neutral.png b/scripts/test/eye_brow_neutral.png new file mode 100644 index 0000000000000000000000000000000000000000..3f451558b59811c1c4b0fc38405c27e9bce35d5b Binary files /dev/null and b/scripts/test/eye_brow_neutral.png differ