Permalink
Browse files

Add face message

  • Loading branch information...
wenwei-dev committed Dec 21, 2016
1 parent c47edd3 commit 76a70185ca9f0121549043f4cefac4085508e817
Showing with 29 additions and 19 deletions.
  1. +9 −9 CMakeLists.txt
  2. +6 −0 msg/Face.msg
  3. +1 −0 msg/Faces.msg
  4. +13 −10 scripts/face_recognizer.py
@@ -45,11 +45,11 @@ catkin_python_setup()
## * add every package in MSG_DEP_SET to generate_messages(DEPENDENCIES ...)

## Generate messages in the 'msg' folder
# add_message_files(
# FILES
# Message1.msg
# Message2.msg
# )
add_message_files(
FILES
Face.msg
Faces.msg
)

## Generate services in the 'srv' folder
# add_service_files(
@@ -66,10 +66,10 @@ catkin_python_setup()
# )

## Generate added messages and services with any dependencies listed here
# generate_messages(
# DEPENDENCIES
# std_msgs # Or other packages containing msgs
# )
generate_messages(
DEPENDENCIES
std_msgs # Or other packages containing msgs
)

################################################
## Declare ROS dynamic reconfigure parameters ##
@@ -0,0 +1,6 @@
string faceid
uint16 left
uint16 top
uint16 right
uint16 bottom
float32 confidence
@@ -0,0 +1 @@
Face[] faces
@@ -42,6 +42,7 @@
import dynamic_reconfigure.client
from face_recognition.cfg import FaceRecognitionConfig
from face_recognition.utils import get_3d_point
from face_recognition.msg import Face, Faces
from std_msgs.msg import String

CWD = os.path.dirname(os.path.abspath(__file__))
@@ -87,10 +88,12 @@ def __init__(self):
self.training_job = None
self.stop_training = threading.Event()
self.faces = []
self.pub = rospy.Publisher(
self.event_pub = rospy.Publisher(
'face_training_event', String, latch=True, queue_size=1)
self.faces_pub = rospy.Publisher(
'~faces', Faces, latch=True, queue_size=1)
self.imgpub = rospy.Publisher(
'image', Image, latch=True, queue_size=1)
'~image', Image, latch=True, queue_size=1)
self._lock = threading.RLock()
self.colors = [ (255, 0, 0), (0, 255, 0), (0, 0, 255),
(255, 255, 0), (255, 0, 255), (0, 255, 255) ]
@@ -190,7 +193,7 @@ def collect_face(self, image, crop=False):
cv2.imwrite(fname, image)
logger.info("Write face image to {}".format(fname))
self.face_count += 1
self.pub.publish('{}/{}'.format(self.face_count, self.max_face_count))
self.event_pub.publish('{}/{}'.format(self.face_count, self.max_face_count))
print "Write face image to {}".format(fname)

def prepare(self):
@@ -201,7 +204,7 @@ def prepare(self):

def train_model(self):
with self._lock:
self.pub.publish('training')
self.event_pub.publish('training')
self.prepare()
label_fname = "{}/labels.csv".format(self.aligned_dir)
reps_fname = "{}/reps.csv".format(self.aligned_dir)
@@ -213,7 +216,7 @@ def train_model(self):

if labels is None or embeddings is None:
logger.error("No labels or representations are found")
self.pub.publish('abort')
self.event_pub.publish('abort')
return

# append the existing data
@@ -236,7 +239,7 @@ def train_model(self):
clf.fit(embeddings_data, labelsNum)
except ValueError as ex:
logger.error(ex)
self.pub.publish('abort')
self.event_pub.publish('abort')
return

if not self.stop_training.is_set():
@@ -251,9 +254,9 @@ def train_model(self):
logger.info("Model saved to {}".format(classifier_fname))

self.load_classifier(classifier_fname)
self.pub.publish('end')
self.event_pub.publish('end')
else:
self.pub.publish('abort')
self.event_pub.publish('abort')

def infer(self, img):
if self.clf is None or self.le is None:
@@ -399,12 +402,12 @@ def reconfig(self, config, level):
logger.info("Stopping")
self.train = False
self.stop_training.set()
self.pub.publish('abort')
self.event_pub.publish('abort')
self.face_name = config.face_name
self.train = config.train
if self.train:
if self.face_name:
self.pub.publish('start')
self.event_pub.publish('start')
self.stop_training.clear()
self.face_count = 0
else:

0 comments on commit 76a7018

Please sign in to comment.