diff --git a/image_recognition_face_recognition/README.md b/image_recognition_face_recognition/README.md index 33e31446..fde94d30 100644 --- a/image_recognition_face_recognition/README.md +++ b/image_recognition_face_recognition/README.md @@ -1,34 +1,32 @@ # image_recognition_face_recognition -NEEDS WORK +TO DO -Face recognition with use of Openpose (https://cmusatyalab.github.io/openface/) +Face recognition with use of Facenet (https://github.com/timesler/facenet-pytorch/tree/master) +Paper can be found: [paper](https://arxiv.org/pdf/1503.03832.pdf) ## Installation See https://github.com/tue-robotics/image_recognition -Make sure that openface is correctly installed. Installation instructions can be found here: https://cmusatyalab.github.io/openface/setup/. Make sure you have installed **CUDA8**. CUDA10 is not working: https://github.com/torch/torch7/issues/1180 +Make sure you have installed **CUDA8**. -```bash -export TORCH_INSTALL_PATH=~/torch -export OPENFACE_INSTALL_PATH=~/openface -git clone https://github.com/torch/distro.git ~/torch --recursive && \ -cd $TORCH_INSTALL_PATH && bash install-deps && ./install.sh && \ -for NAME in dpnn nn optim optnet csvigo cutorch cunn fblualib torchx tds; do $TORCH_INSTALL_PATH/install/bin/luarocks install $NAME; done && \ -sudo -H pip install dlib && \ -git clone https://github.com/cmusatyalab/openface.git $OPENFACE_INSTALL_PATH && \ -cd $OPENFACE_INSTALL_PATH && sudo -H python setup.py install && \ -./models/get-models.sh -``` +bash commends will be available when merged ## How-to +### Run Face Recognition Node + +Run the command why using your camera as an input (use roscamera node): + + rosrun cv_camera cv_camera_node + rosrun image_recognition_face_recognition face_recognition_node image:=/cv_camera/image_raw + ### ROS Node -Run the image_recognition_openface node in one terminal (Specify the dlib and openface_net path as ROS parameter): +Run the image_recognition_face_detection node in one terminal (Specify the dlib and openface_net path as ROS parameter): - rosrun image_recognition_openface face_recognition_node + rosrun image_recognition_face_detection face_recognition_node Run the rqt annotation client (https://github.com/tue-robotics/image_recognition_rqt) @@ -58,6 +56,7 @@ Again configure the service you want to call with the gear-wheel in the top-righ You will see that the result of the detection will prompt in a dialog combo box. Also the detections will be drawn on the image. + ### Command line Command line interface to test the detection / recognition based on an image: @@ -66,14 +65,6 @@ Command line interface to test the detection / recognition based on an image: Run the command on an example image: - rosrun image_recognition_openface get_face_recognition `rospack find image_recognition_openface`/doc/example.png - -This will lookup this image in the image_recognition_openface/doc folder and perform recognitions - -![Example](doc/example.png) - -Output: - - [RecognizedFace(roi=(374, 188, 108, 123), l2_distances=[]), RecognizedFace(roi=(72, 147, 88, 105), l2_distances=[]), RecognizedFace(roi=(377, 95, 74, 86), l2_distances=[]), RecognizedFace(roi=(149, 26, 74, 86), l2_distances=[]), RecognizedFace(roi=(52, 47, 75, 86), l2_distances=[]), RecognizedFace(roi=(246, 115, 88, 102), l2_distances=[]), RecognizedFace(roi=(0, 0, 42, 60), l2_distances=[]), RecognizedFace(roi=(336, 33, 74, 86), l2_distances=[]), RecognizedFace(roi=(228, 0, 62, 60), l2_distances=[])] + rosrun image_recognition_face_recognition get_face_recognition `rospack find image_recognition_face_recognition`/doc/example.png -Since no faces were trained, the l2_distances will not be calculated of-course. +![Example](doc/example.png) \ No newline at end of file diff --git a/image_recognition_face_recognition/scripts/get_face_recognition b/image_recognition_face_recognition/scripts/get_face_recognition index c2982e14..b34c6e2a 100755 --- a/image_recognition_face_recognition/scripts/get_face_recognition +++ b/image_recognition_face_recognition/scripts/get_face_recognition @@ -5,8 +5,9 @@ import argparse import cv2 from image_recognition_msgs.msg import Recognition -from image_recognition_openface.face_recognizer import FaceRecognizer +from image_recognition_face_recognition.facenet_recognition import Facenet_recognition # Assign description to the help doc +import math from sensor_msgs.msg import RegionOfInterest from image_recognition_util import image_writer @@ -28,20 +29,26 @@ args = parser.parse_args() img = cv2.imread(args.image) # Create openface interface -face_recognizer = FaceRecognizer(args.align_path, args.net_path) +face_recognizer = Facenet_recognition() if args.db: face_recognizer.restore_trained_faces(args.db) -recognized_faces = face_recognizer.recognize(img) +recognized_faces = face_recognizer.face_detection(img) print(recognized_faces) -annotated_original_image = image_writer.get_annotated_cv_image(img, [Recognition( - roi=RegionOfInterest( - x_offset=f.roi.x_offset, - y_offset=f.roi.y_offset, - width=f.roi.width, - height=f.roi.height + +recognitions = [] +for fr in recognized_faces: + face_recognition = [math.floor(xi) for xi in fr] + recognitions.append(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], + ) ) -) for f in recognized_faces]) +) + annotated_original_image = image_writer.get_annotated_cv_image(img, recognitions) cv2.imshow("result", annotated_original_image) cv2.waitKey()