Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/code_compiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: code_compiles

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch: {}

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v3

- name: Install prerequired packages
# To compile and run the code we require cmake, ninja and opencv
run: sudo apt-get update && sudo apt-get install build-essential cmake ninja-build libopencv-dev

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -B ${{github.workspace}}/build -G Ninja

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build
38 changes: 38 additions & 0 deletions .github/workflows/ros2_code_compiles.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: ros_code_compiles

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
workflow_dispatch: {}

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v3
- uses: ros-tooling/setup-ros@v0.7
with:
required-ros-distributions: jazzy

- name: Install prerequired packages
# To compile and run the code we require cmake, ninja and opencv
run: sudo apt-get update && sudo apt-get install build-essential cmake ninja-build libopencv-dev

- name: Install dependencies
working-directory: ${{ github.workspace }}
run: |
sudo rosdep init || true
rosdep update
rosdep install --from-paths src -y --ignore-src

- name: Colcon build
working-directory: ${{ github.workspace }}
run: |
source /opt/ros/jazzy/setup.bash
colcon build --packages-select face_detector
124 changes: 103 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,59 @@ else()
SOURCE_SUBDIR tensorflow/lite
)
FetchContent_MakeAvailable(tensorflow_rel_package)
else()
else()
# Check if we can use any of the precompiled tensorflow lite packages
# https://github.com/CLFML/TensorFlow_Lite_Compiled
include(FetchContent)
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64")
FetchContent_Declare(
tensorflow_compiled_rel_package
URL https://github.com/CLFML/TensorFlow_Lite_Compiled/releases/download/v2.16.1/tensorflow_linux_generic_aarch64.zip
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/external/tensorflow
)
tensorflow_compiled_rel_package
URL https://github.com/CLFML/TensorFlow_Lite_Compiled/releases/download/v2.16.1/tensorflow_linux_generic_aarch64.zip
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/external/tensorflow
)
else()
FetchContent_Declare(
tensorflow_compiled_rel_package
URL https://github.com/CLFML/TensorFlow_Lite_Compiled/releases/download/v2.16.1/tensorflow_linux_generic_x86_64.zip
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/external/tensorflow
)
endif()
FetchContent_MakeAvailable(tensorflow_compiled_rel_package)
if(CLFML_ROS2_PACKAGE_BUILD)
install(FILES external/tensorflow/lib/libtensorflowlite.so DESTINATION lib/${PROJECT_NAME})
# Get the CPU compatible instructionset(s)
execute_process(
COMMAND lscpu
OUTPUT_VARIABLE CLFML_FACE_MESH_CPU_INFO
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(CLFML_FACE_MESH_CPU_INFO MATCHES "avx2")
message(STATUS "CLFML Face_Mesh.Cpp: CPU supports AVX2")
# Download the AVX2 compatible precompiled tensorflow lite package
FetchContent_Declare(
tensorflow_compiled_rel_package
URL https://github.com/CLFML/TensorFlow_Lite_Compiled/releases/download/v2.16.1/tensorflow_linux_avx2_x86_64.zip
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/external/tensorflow
)
FetchContent_MakeAvailable(tensorflow_compiled_rel_package)
if(CLFML_ROS2_PACKAGE_BUILD)
install(FILES external/tensorflow/lib/libtensorflowlite.so DESTINATION lib/${PROJECT_NAME})
endif()

elseif(CLFML_FACE_MESH_CPU_INFO MATCHES "avx")
message(STATUS "CLFML Face_Mesh.Cpp: CPU supports AVX")
# Download the AVX compatible precompiled tensorflow lite package
FetchContent_Declare(
tensorflow_compiled_rel_package
URL https://github.com/CLFML/TensorFlow_Lite_Compiled/releases/download/v2.16.1/tensorflow_linux_generic_x86_64.zip
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/external/tensorflow
)
FetchContent_MakeAvailable(tensorflow_compiled_rel_package)
if(CLFML_ROS2_PACKAGE_BUILD)
install(FILES external/tensorflow/lib/libtensorflowlite.so DESTINATION lib/${PROJECT_NAME})
endif()
else()
message(STATUS "CLFML Face_Mesh.Cpp: CPU doesn't support AVX or AVX2; Compiling from source...")
# Download and build from source
FetchContent_Declare(
tensorflow_rel_package
URL https://github.com/tensorflow/tensorflow/archive/refs/tags/v2.16.1.zip
SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/external/tensorflow
SOURCE_SUBDIR tensorflow/lite
)
FetchContent_MakeAvailable(tensorflow_rel_package)
endif()
endif()
endif()
target_link_libraries(${PROJECT_NAME} tensorflow-lite)
Expand All @@ -76,14 +111,61 @@ target_compile_definitions(${PROJECT_NAME} PUBLIC -DCLFML_FACE_MESH_CPU_MODEL_PA

set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 17)

if (CLFML_ROS2_PACKAGE_BUILD)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(std_srvs REQUIRED)
find_package(cv_bridge REQUIRED)
target_link_libraries(${PROJECT_NAME} ${cv_bridge_LIBRARIES})
add_executable(face_mesh_node ${CMAKE_CURRENT_LIST_DIR}/bindings/ros2/face_mesh_node.cpp)
ament_target_dependencies(face_mesh_node
rclcpp
sensor_msgs
cv_bridge
std_msgs
geometry_msgs
std_srvs
OpenCV
)
target_link_libraries(face_mesh_node face_mesh)
install(TARGETS
face_mesh_node
DESTINATION lib/${PROJECT_NAME})
endif()


if(CLFML_FACE_MESH_BUILD_EXAMPLE_PROJECTS)
FetchContent_Declare(
face_detector.cpp
GIT_REPOSITORY https://github.com/CLFML/Face_Detector.Cpp.git
GIT_TAG main
)
FetchContent_MakeAvailable(face_detector.cpp)
FetchContent_Declare(
face_detector.cpp
GIT_REPOSITORY https://github.com/CLFML/Face_Detector.Cpp.git
GIT_TAG main
)
FetchContent_MakeAvailable(face_detector.cpp)
if (CLFML_ROS2_PACKAGE_BUILD)
add_executable(face_mesh_viewer ${CMAKE_CURRENT_LIST_DIR}/example/ros2/face_mesh_viewer.cpp)
ament_target_dependencies(face_mesh_viewer
rclcpp
sensor_msgs
cv_bridge
std_msgs
geometry_msgs
std_srvs
OpenCV
)
install(TARGETS
face_mesh_viewer
DESTINATION lib/${PROJECT_NAME})
else ()
add_executable(face_mesh_demo ${CMAKE_CURRENT_LIST_DIR}/example/face_mesh_demo/demo.cpp)
target_link_libraries(face_mesh_demo PUBLIC CLFML::${PROJECT_NAME} CLFML::face_detector)

endif()
endif()


if (CLFML_ROS2_PACKAGE_BUILD)
install(FILES bindings/ros2/set_ld_path.sh DESTINATION lib/${PROJECT_NAME})
ament_package()
endif()
53 changes: 52 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,65 @@ add_subdirectory(Face_Mesh.Cpp)
...
target_link_libraries(YOUR_EXECUTABLE CLFML::face_mesh)
```

## Building a ROS2 package with Colcon
Before using this library you will need the following packages installed:
- OpenCV
- ROS2
- ROS CV bridge
- Working C++ compiler (GCC or Clang)
- CMake

### Running the examples (Ubuntu, CPU)

1. Clone this repo:
```
git clone https://github.com/CLFML/Face_Mesh.Cpp.git
```

2. Source your ROS2 installation:

```bash
source /opt/ros/jazzy/setup.bash
```

3. Install the dependencies:
```bash
rosdep install --from-paths src -y --ignore-src
```

4. Build the package:

```bash
colcon build --packages-select face_mesh
```

5. Set up the environment:

```bash
source install/setup.bash
```

6. Run the camera node:

```bash
ros2 run v4l2_camera v4l2_camera_node
```

7. In another terminal, run the nodes

```bash
ros2 launch example/ros2/launch.py
```


## Aditional documentation
See our [wiki](https://clfml.github.io/Face_Mesh.Cpp/)...

## Todo
- Add language bindings for Python, C# and Java
- Add support for MakeFiles and Bazel
- Add Unit-tests
- Add ROS2 package support
- Add support for the [Face Mesh V2 model](https://storage.googleapis.com/mediapipe-assets/Model%20Card%20MediaPipe%20Face%20Mesh%20V2.pdf)

## License
Expand Down
Loading