From 7b579386997c12d5de217028c99ce3504a66f0c1 Mon Sep 17 00:00:00 2001 From: Jules Youngberg Date: Tue, 26 Jul 2022 17:43:21 -0700 Subject: [PATCH] fix build and instructions for apple m1 --- .gitignore | 2 ++ Cargo.toml | 8 ++--- README.md | 33 ++++++++++++------- build.rs | 2 +- .../multi_person_pose_tracking_cpu.pbtxt | 20 ++++++++--- 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index cd90079..fb41120 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ Cargo.lock **/*.rs.bk /refs/ /mediapipe/ +/logs/ +.DS_Store diff --git a/Cargo.toml b/Cargo.toml index cbe10d4..1f9e85b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,10 @@ edition = "2018" name = "mediapipe" [dependencies] -cgmath = "0.18.0" -libc = "0.2.0" -opencv = { version = "0.63", features = ["clang-runtime"] } -protobuf = "2.23.0" +cgmath = "0.18" +libc = "0.2" +opencv = "0.66" +protobuf = "2.23" [build-dependencies] bindgen = "*" diff --git a/README.md b/README.md index 822f59a..ee6cc9d 100644 --- a/README.md +++ b/README.md @@ -12,31 +12,46 @@ And heavily based on this example: https://github.com/asprecic/mediapipe-qt-inte ## setup +To run the examples clone this project. + +```shell +git clone https://github.com/julesyoungberg/mediapipe-rs.git +``` + Mediapipe is a framework for building AI-powered computer vision applications. It provides high level libraries exposing some of its solutions for common problems. This package makes some of these solutions available in Rust. In order to use it we must build a custom mediapipe C++ library. -Clone the modified Mediapipe repo. +Clone the modified Mediapipe repo next to `mediapipe-rs` or a project that uses `mediapipe-rs`. ```shell git clone https://github.com/julesyoungberg/mediapipe.git cd mediapipe ``` +### building mediapipe + Build & install the mediagraph library. -### mac os +#### mac os ```shell bazel build --define MEDIAPIPE_DISABLE_GPU=1 mediapipe:libmediagraph.dylib sudo cp bazel-bin/mediapipe/libmediagraph.dylib /usr/local/lib/libmediagraph.dylib -cp mediapipe/mediagraph.h /usr/local/include/mediagraph.h ``` -### linux (untested) +#### linux (untested) ```shell bazel build --define MEDIAPIPE_DISABLE_GPU=1 mediapipe:mediagraph cp bazel-bin/mediapipe/libmediagraph.so /usr/local/lib/libmediagraph.so -cp mediapipe/mediagraph.h /usr/local/include/mediagraph.h +``` + +### linking & building + +Navigate to the project directory and create a symbolic link to the `../mediapipe/mediapipe`. + +```shell +cd ../mediapipe-rs # or the path to your project +ln -s ../mediapipe/mediapipe . ``` ## usage @@ -47,13 +62,7 @@ Add the following to your dependencies list in `Cargo.toml`: mediapipe = { git = "https://github.com/julesyoungberg/mediapipe-rs" } ``` -Mediapipe relies on tflite files which must be available at `./mediapipe/modules/`. The easiest way to satisfy this is by creating a symbolic link to mediapipe. Run the following command from the project directory. - -```shell -ln -s ../mediapipe/mediapipe . -``` - -The path to mediapipe may be different depending on where you have cloned it to. +Mediapipe relies on tflite files which must be available at `./mediapipe/modules/`. The easiest way to satisfy this is by creating a symbolic link to mediapipe as explained in the `linking & building` section above. ## examples diff --git a/build.rs b/build.rs index a34f8ed..67488ac 100644 --- a/build.rs +++ b/build.rs @@ -10,7 +10,7 @@ fn main() { .clang_arg("-std=c++14") .clang_arg("-I/usr/local/include/opencv4") .generate_comments(true) - .header("/usr/local/include/mediagraph.h") + .header("./mediapipe/mediagraph.h") .allowlist_function("mediagraph.*") .allowlist_type("mediagraph.*") .allowlist_var("mediagraph.*") diff --git a/src/graphs/multi_person_pose_tracking_cpu.pbtxt b/src/graphs/multi_person_pose_tracking_cpu.pbtxt index cb7f87a..5577f99 100644 --- a/src/graphs/multi_person_pose_tracking_cpu.pbtxt +++ b/src/graphs/multi_person_pose_tracking_cpu.pbtxt @@ -1,3 +1,10 @@ +profiler_config { + trace_enabled: true + # enable_profiler: true + trace_log_interval_count: 200 + trace_log_path: "/Users/jules/workspace/mediapipe-rs/logs/" +} + # MediaPipe graph that performs pose tracking with TensorFlow Lite on CPU. # CPU buffer. (ImageFrame) @@ -6,17 +13,19 @@ input_stream: "input_video" # Output image with rendered results. (ImageFrame) output_stream: "multi_pose_landmarks" -output_stream: "pose_detections" +# output_stream: "pose_detections" output_stream: "roi_from_landmarks" # Generates side packet to enable segmentation. node { calculator: "ConstantSidePacketCalculator" - output_side_packet: "PACKET:enable_segmentation" + output_side_packet: "PACKET:0:enable_segmentation" + output_side_packet: "PACKET:1:num_poses" node_options: { [type.googleapis.com/mediapipe.ConstantSidePacketCalculatorOptions]: { - packet { bool_value: true } + packet { bool_value: false } + packet { int_value: 2 } } } } @@ -34,7 +43,7 @@ node { node { calculator: "FlowLimiterCalculator" input_stream: "input_video" - input_stream: "FINISHED:output_video" + input_stream: "FINISHED:roi_from_landmarks" input_stream_info: { tag_index: "FINISHED" back_edge: true @@ -47,7 +56,8 @@ node { calculator: "MultiPoseLandmarkCpu" input_side_packet: "ENABLE_SEGMENTATION:enable_segmentation" input_stream: "IMAGE:throttled_input_video" + input_side_packet: "NUM_POSES:num_poses" output_stream: "LANDMARKS:multi_pose_landmarks" - output_stream: "DETECTION:pose_detections" + # output_stream: "DETECTION:pose_detections" output_stream: "ROI_FROM_LANDMARKS:roi_from_landmarks" }