diff --git a/src/AndroidApp/.idea/codeStyles/Project.xml b/src/AndroidApp/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..fb22c1d --- /dev/null +++ b/src/AndroidApp/.idea/codeStyles/Project.xml @@ -0,0 +1,164 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+
+
\ No newline at end of file diff --git a/src/AndroidApp/.idea/dbnavigator.xml b/src/AndroidApp/.idea/dbnavigator.xml new file mode 100644 index 0000000..59b34bd --- /dev/null +++ b/src/AndroidApp/.idea/dbnavigator.xml @@ -0,0 +1,458 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/AndroidApp/.idea/vcs.xml b/src/AndroidApp/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/src/AndroidApp/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/AndroidApp/Tbot/.idea/caches/build_file_checksums.ser b/src/AndroidApp/Tbot/.idea/caches/build_file_checksums.ser index c0e65f9..7012f9a 100644 Binary files a/src/AndroidApp/Tbot/.idea/caches/build_file_checksums.ser and b/src/AndroidApp/Tbot/.idea/caches/build_file_checksums.ser differ diff --git a/src/AndroidApp/Tbot/app/src/main/java/me/wshuo/tbot/Settings.java b/src/AndroidApp/Tbot/app/src/main/java/me/wshuo/tbot/Settings.java index d89e882..1cfac2b 100644 --- a/src/AndroidApp/Tbot/app/src/main/java/me/wshuo/tbot/Settings.java +++ b/src/AndroidApp/Tbot/app/src/main/java/me/wshuo/tbot/Settings.java @@ -166,7 +166,6 @@ public class Settings extends AppCompatPreferenceActivity { return true; */ - return PreferenceFragment.class.getName().equals(fragmentName) || GeneralPreferenceFragment.class.getName().equals(fragmentName) || DataSyncPreferenceFragment.class.getName().equals(fragmentName) diff --git a/src/Robot/emotion_detector/Emotion.py b/src/Robot/emotion_detector/Emotion.py new file mode 100644 index 0000000..643154e --- /dev/null +++ b/src/Robot/emotion_detector/Emotion.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Mar 26 09:03:33 2021 + +@author: 59866 +""" + +import urllib2 +import urllib +import time +import sys +import rospy +import cv2 +from std_msgs.msg import String +from sensor_msgs.msg import Image +from cv_bridge import CvBridge, CvBridgeError +class TakePhoto: + def __init__(self): + + self.bridge = CvBridge() + self.image_received = False + + # Connect image topic + img_topic = "/camera/rgb/image_raw" + self.image_sub = rospy.Subscriber(img_topic, Image, self.callback) + + # Allow up to two second to connection, + # The initial one second is too short for the camera. + # rospy.sleep(1) + # by lcp + rospy.sleep(2) + + def callback(self, data): + + # Convert image to OpenCV format + try: + cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8") + except CvBridgeError as e: + print(e) + + self.image_received = True + self.image = cv_image + + def take_picture(self, img_title): + if self.image_received: + # Save an image + cv2.imwrite(img_title, self.image) + return True + else: + return False + +# Initialize +rospy.init_node('take_photo', anonymous=False) +camera = TakePhoto() #构造出TakePhoto类的一个对象, + +# Take a photo + +# Use '_image_title' parameter from command line +# Default value is 'photo.jpg' +# 照片的名字默认为'photo.jpg' +img_title = rospy.get_param('~image_title', 'photo.jpg') + +if camera.take_picture(img_title): #调用camera的成员函数take_picture, +# 如果拍照成功,打印日志"Saved image photo.jpg" + rospy.loginfo("Saved image " + img_title) +else: +# 如果拍照失败,打印日志"No images received" + rospy.loginfo("No images received") + +# Sleep to give the last log messages time to be sent +rospy.sleep(1) +http_url='https://api-cn.faceplusplus.com/facepp/v3/detect' +key = "HNd4d3TEbl5oFy2cV9qFM2gNhRQ6UuvG" +secret = "ZpCtE9pCnMLTwgPiXAV5RZdNW_ftliLC" +filepath = r"/home/turtlebot/catkin_ws/src/emotion_detector/src/photo.jpg" + +boundary = '----------%s' % hex(int(time.time() * 1000)) +data = [] +data.append('--%s' % boundary) +data.append('Content-Disposition: form-data; name="%s"\r\n' % 'api_key') +data.append(key) +data.append('--%s' % boundary) +data.append('Content-Disposition: form-data; name="%s"\r\n' % 'api_secret') +data.append(secret) +data.append('--%s' % boundary) +#用'rb'方式读取文件 +fr=open(filepath,'rb') +data.append('Content-Disposition: form-data; name="%s"; filename=" "' % 'image_file') +data.append('Content-Type: %s\r\n' % 'application/octet-stream') +data.append(fr.read()) + +fr.close() +data.append('--%s' % boundary) +data.append('Content-Disposition: form-data; name="%s"\r\n' % 'return_landmark') +#人脸特征点:'2'返回106个,'1'返回83个,'0'不返回 +data.append('0') +data.append('--%s' % boundary) +data.append('Content-Disposition: form-data; name="%s"\r\n' % 'return_attributes') +#请求的数据集(字符串) +data.append("gender,headpose,emotion,eyegaze") +data.append('--%s--\r\n' % boundary) +#python2中data不用decode、encode + +http_body='\r\n'.join(data) + +#buld http request +req=urllib2.Request(http_url) + +#header +req.add_header('Content-Type', 'multipart/form-data; boundary=%s' % boundary) +req.add_data(http_body) + +try: + #req.add_header('Referer','http://remotserver.com/') + #post data to server + resp = urllib2.urlopen(req, timeout=5) + #get response + qrcont=resp.read() + print qrcont + +except urllib2.HTTPError as e: + print e.read() \ No newline at end of file