Skip to content

Commit

Permalink
changed ReadME.md and get_face_recognition in order to make it work w…
Browse files Browse the repository at this point in the history
…ith facenet model
  • Loading branch information
iasonth95 committed Mar 11, 2024
1 parent 9ee08e6 commit 1c3d480
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
43 changes: 17 additions & 26 deletions image_recognition_face_recognition/README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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)
27 changes: 17 additions & 10 deletions image_recognition_face_recognition/scripts/get_face_recognition
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

0 comments on commit 1c3d480

Please sign in to comment.