Skip to content

Commit

Permalink
small visual updates of face_recognition_node and uncomment exception
Browse files Browse the repository at this point in the history
  • Loading branch information
iasonth95 committed Feb 20, 2024
1 parent 4a21701 commit eb2ba11
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions image_recognition_openface/scripts/face_recognition_node
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import os
import sys

import diagnostic_updater
import rospy
from cv_bridge import CvBridge, CvBridgeError
from image_recognition_openface.face_recognizer import FaceRecognizer
from sensor_msgs.msg import RegionOfInterest, Image
from std_srvs.srv import Empty

from image_recognition_msgs.msg import Recognition, Recognitions, CategoryProbability, CategoricalDistribution
from image_recognition_msgs.srv import Recognize, Annotate
from image_recognition_util import image_writer
sys.path.append('/home/iason/ros/noetic/repos/github.com/tue-robotics/image_recognition/image_recognition_openface/src/image_recognition_openface')
from facenet_recognition import Facenet_recognition


class OpenfaceROS:
def __init__(self, align_path, net_path, save_images_folder, topic_save_images,
service_save_images, topic_publish_result_image, service_publish_result_image):
Expand All @@ -32,7 +31,7 @@ class OpenfaceROS:

# Openface ROS
self._face_recognizer = Facenet_recognition()
#self._face_recognizer = FaceRecognizer(align_path, net_path)
# self._face_recognizer = FaceRecognizer(align_path, net_path)
self._save_images_folder = save_images_folder
self._topic_save_images = topic_save_images
self._service_save_images = service_save_images
Expand Down Expand Up @@ -118,18 +117,18 @@ class OpenfaceROS:
# Write raw image
if save_images:
image_writer.write_raw(self._save_images_folder, bgr_image)

images = []
labels = []
# Call openface
face_recognitions = self._face_recognizer.face_detection(bgr_image)
dist, face_labelling = self._face_recognizer.detection_recognition(bgr_image ,images, labels, self._save_images_folder,train = True)
dist, face_labelling = self._face_recognizer.detection_recognition(bgr_image, images, labels, self._save_images_folder, train = True)
# Fill recognitions
recognitions = []

rospy.loginfo("Face recognitions: %s", face_recognitions)
i = 0

i = 0
for fr in face_recognitions:
import math
face_recognition = [math.floor(xi) for xi in fr]
Expand All @@ -146,20 +145,18 @@ class OpenfaceROS:
recognitions.append(Recognition(
categorical_distribution=CategoricalDistribution(
unknown_probability=0.0, # TODO: When is it unknown?
probabilities=[CategoryProbability(label=label, probability=1.0 / (disti+0.001))
probabilities=[CategoryProbability(label=label, probability=1.0 / (disti + 0.001))
for l2 in face_recognition]
),
roi=RegionOfInterest(
x_offset=face_recognition[0],
y_offset=face_recognition[1],
width=face_recognition[2] - face_recognition[0],
height=face_recognition[3] - face_recognition[1]
height=face_recognition[3] - face_recognition[1]
)
))
i = i+1
# print(face_recognition)


i = i + 1

annotated_original_image = image_writer.get_annotated_cv_image(bgr_image, recognitions)
if save_images:
image_writer.write_estimations(self._save_images_folder, images, labels, annotated_original_image,
Expand All @@ -172,13 +169,13 @@ class OpenfaceROS:
return recognitions

def _image_callback(self, image_msg):
#UNCOMMENT THOSE LINES NOW ITS COMMENTED FOR DEBUGGING
#try:
recognitions = self._get_recognitions(image_msg, save_images=self._topic_save_images,
publish_images=self._topic_publish_result_image)
#except Exception as e:
#rospy.logerr(str(e))
#return
# UNCOMMENT THOSE LINES NOW ITS COMMENTED FOR DEBUGGING
try:
recognitions = self._get_recognitions(image_msg, save_images=self._topic_save_images,
publish_images=self._topic_publish_result_image)
except Exception as e:
rospy.logerr(str(e))
return

self._recognitions_publisher.publish(Recognitions(
header=image_msg.header,
Expand Down Expand Up @@ -219,7 +216,7 @@ if __name__ == '__main__':
except KeyError as e:
rospy.logerr("Parameter %s not found" % e)
sys.exit(1)

image_recognition_openface = OpenfaceROS(dlib_shape_predictor_path, openface_neural_network_path,
save_images_folder, topic_save_images, service_save_images,
topic_publish_result_image,
Expand Down

0 comments on commit eb2ba11

Please sign in to comment.