Skip to content

Commit 31d39fb

Browse files
authored
Merge pull request #55 from tue-robotics/feature/51_publish_heartbeat
Feature/51 publish heartbeat
2 parents 58af91f + 6fb98ec commit 31d39fb

File tree

14 files changed

+67
-29
lines changed

14 files changed

+67
-29
lines changed

dependencies.rosinstall

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

keras_ros/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
cmake_minimum_required(VERSION 2.8.3)
22
project(keras_ros)
33

4-
find_package(catkin REQUIRED COMPONENTS
5-
rospy
6-
image_recognition_msgs
7-
image_recognition_util
8-
)
4+
find_package(catkin REQUIRED)
95

106
catkin_python_setup()
117

keras_ros/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ See https://github.com/tue-robotics/image_recognition for installation instructi
88

99
## ROS Node (face_properties_node)
1010

11-
Age and gender estimation with use of WideResNet from https://github.com/yu4u/age-gender-estimation. You can download the pre-trained model here: https://github.com/yu4u/age-gender-estimation/releases/download/v0.5/weights.18-4.06.hdf5
11+
Age and gender estimation with use of WideResNet from https://github.com/yu4u/age-gender-estimation. You can download the pre-trained model here: https://github.com/yu4u/age-gender-estimation/releases/download/v0.5/weights.28-3.73.hdf5
1212

1313
```
1414
rosrun keras_ros face_properties_node _weights_file_path:=[path_to_model]
@@ -44,4 +44,4 @@ Output:
4444
An error occurred: softmax() got an unexpected keyword argument 'axis'
4545
```
4646

47-
Make sure you have tensorflow version >= 1.5.
47+
Make sure you have tensorflow version >= 1.5.

keras_ros/package.xml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0"?>
2-
<package>
2+
<package format="2">
33
<name>keras_ros</name>
44
<version>0.0.1</version>
55
<description>The keras_ros package</description>
@@ -9,14 +9,13 @@
99
<license>TODO</license>
1010

1111
<buildtool_depend>catkin</buildtool_depend>
12-
<build_depend>rospy</build_depend>
13-
<build_depend>image_recognition_msgs</build_depend>
14-
<build_depend>image_recognition_util</build_depend>
1512

16-
<run_depend>rospy</run_depend>
17-
<run_depend>image_recognition_msgs</run_depend>
18-
<run_depend>python-keras-pip</run_depend>
19-
<run_depend>python-numpy</run_depend>
20-
<run_depend>python-opencv</run_depend>
21-
<run_depend>python-tensorflow-pip</run_depend>
13+
<exec_depend>diagnostic_updater</exec_depend>
14+
<exec_depend>rospy</exec_depend>
15+
<exec_depend>image_recognition_msgs</exec_depend>
16+
<exec_depend>image_recognition_util</exec_depend>
17+
<exec_depend>python-keras-pip</exec_depend>
18+
<exec_depend>python-numpy</exec_depend>
19+
<exec_depend>python-opencv</exec_depend>
20+
<exec_depend>python-tensorflow-pip</exec_depend>
2221
</package>

keras_ros/scripts/face_properties_node

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import os
44
import sys
55

66
import cv2
7+
import diagnostic_updater
78
import rospy
89
from cv_bridge import CvBridge, CvBridgeError
910
from image_recognition_msgs.msg import FaceProperties
@@ -89,6 +90,10 @@ if __name__ == '__main__':
8990

9091
try:
9192
WideResnetFaceProperties(weights_file_path, img_size, depth, width, save_images_folder)
93+
updater = diagnostic_updater.Updater()
94+
updater.setHardwareID("none")
95+
updater.add(diagnostic_updater.Heartbeat())
96+
rospy.Timer(rospy.Duration(1), lambda event: updater.force_update())
9297
rospy.spin()
9398
except Exception as e:
9499
rospy.logfatal(e)

openface_ros/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@
1919
<run_depend>image_recognition_util</run_depend>
2020
<run_depend>rospy</run_depend>
2121
<run_depend>python-numpy</run_depend>
22+
<run_depend>diagnostic_updater</run_depend>
2223

2324
</package>

openface_ros/scripts/face_recognition_node

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#!/usr/bin/env python
22

3+
import os
4+
import sys
5+
6+
import diagnostic_updater
37
import rospy
48
from cv_bridge import CvBridge, CvBridgeError
5-
6-
from image_recognition_msgs.srv import Recognize, Annotate
79
from image_recognition_msgs.msg import Recognition, Recognitions, CategoryProbability, CategoricalDistribution
10+
from image_recognition_msgs.srv import Recognize, Annotate
11+
from image_recognition_util import image_writer
12+
from openface_ros.face_recognizer import FaceRecognizer
813
from sensor_msgs.msg import RegionOfInterest, Image
914
from std_srvs.srv import Empty
1015

11-
import os
12-
import sys
13-
14-
from image_recognition_util import image_writer
15-
from openface_ros.face_recognizer import FaceRecognizer, RecognizedFace
16-
1716

1817
class OpenfaceROS:
1918
def __init__(self, align_path, net_path, save_images_folder, topic_save_images,
@@ -74,8 +73,8 @@ class OpenfaceROS:
7473
raise Exception("Could not convert to opencv image: %s" % str(e))
7574

7675
for annotation in req.annotations:
77-
roi_image = bgr_image[annotation.roi.y_offset:annotation.roi.y_offset+annotation.roi.height,
78-
annotation.roi.x_offset:annotation.roi.x_offset + annotation.roi.width]
76+
roi_image = bgr_image[annotation.roi.y_offset:annotation.roi.y_offset + annotation.roi.height,
77+
annotation.roi.x_offset:annotation.roi.x_offset + annotation.roi.width]
7978

8079
if self._save_images_folder:
8180
image_writer.write_annotated(self._save_images_folder, roi_image, annotation.label, True)
@@ -183,8 +182,8 @@ class OpenfaceROS:
183182
def restore_trained_faces(self, file_name):
184183
self._face_recognizer.restore_trained_faces(file_name)
185184

186-
if __name__ == '__main__':
187185

186+
if __name__ == '__main__':
188187
rospy.init_node("face_recognition")
189188

190189
try:
@@ -216,4 +215,9 @@ if __name__ == '__main__':
216215
rospy.loginfo('loading face database from %s', db)
217216
openface_ros.restore_trained_faces(db)
218217

218+
updater = diagnostic_updater.Updater()
219+
updater.setHardwareID("none")
220+
updater.add(diagnostic_updater.Heartbeat())
221+
rospy.Timer(rospy.Duration(1), lambda event: updater.force_update())
222+
219223
rospy.spin()

openpose_ros/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ find_package(catkin REQUIRED COMPONENTS
99
cv_bridge
1010
sensor_msgs
1111
image_recognition_msgs
12+
diagnostic_updater
1213
)
1314

1415
catkin_package()

openpose_ros/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
<depend>image_recognition_msgs</depend>
1616

1717
<depend>libopencv-dev</depend>
18+
<depend>diagnostic_updater</depend>
1819

1920
</package>

openpose_ros/src/openpose_ros_node.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "openpose_wrapper.h"
22

3+
#include <diagnostic_updater/update_functions.h>
4+
#include <diagnostic_updater/diagnostic_updater.h>
5+
36
#include <image_recognition_msgs/Recognize.h>
47
#include <ros/node_handle.h>
58

@@ -8,6 +11,7 @@
811
std::shared_ptr<OpenposeWrapper> g_openpose_wrapper;
912
std::string g_save_images_folder = "";
1013
bool g_publish_to_topic = false;
14+
std::shared_ptr<diagnostic_updater::Updater> g_diagnostic_updater;
1115
ros::Publisher g_pub;
1216

1317
//!
@@ -129,6 +133,11 @@ bool detectPosesCallback(image_recognition_msgs::Recognize::Request& req, image_
129133
return detectPoses(image, res.recognitions);
130134
}
131135

136+
void updateDiagnosticsCallback(const ros::TimerEvent &)
137+
{
138+
g_diagnostic_updater->force_update();
139+
}
140+
132141
int main(int argc, char** argv)
133142
{
134143
ros::init(argc, argv, "openpose");
@@ -162,6 +171,14 @@ int main(int argc, char** argv)
162171
g_pub = nh.advertise<sensor_msgs::Image>("result_image", 1);
163172
}
164173

174+
g_diagnostic_updater = std::shared_ptr<diagnostic_updater::Updater>(new diagnostic_updater::Updater());
175+
g_diagnostic_updater->setHardwareID("none");
176+
177+
diagnostic_updater::Heartbeat heartbeat = diagnostic_updater::Heartbeat();
178+
g_diagnostic_updater->add(heartbeat);
179+
180+
ros::Timer t = nh.createTimer(ros::Duration(1.0), updateDiagnosticsCallback);
181+
165182
ros::spin();
166183

167184
return 0;

0 commit comments

Comments
 (0)