<br />

Please follow instructions below to build C++ command-line example apps with
MediaPipe Framework. To learn more about these example apps, start from [Hello
World! in C++](https://developers.google.com/edge/mediapipe/framework/getting_started/hello_world_cpp).

## Building C++ command-line example apps

You can compile and run desktop MediaPipe graphs using either CPU execution or
GPU acceleration.

### Option 1: Running on CPU

1. To build, for example, the C++ hand tracking example graph on CPU, run:

   ```bash
   bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 \
   mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu
   ```
2. To run the application:

   ```bash
   GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/hand_tracking/hand_tracking_cpu \
     --calculator_graph_config_file=mediapipe/graphs/hand_tracking/hand_tracking_desktop_live.pbtxt
   ```

   This will open up your webcam as long as it is connected and on. Any errors
   is likely due to your webcam being not accessible.

### Option 2: Running on GPU

#### For Linux

First follow [OpenGL ES Setup on Linux Desktop](https://developers.google.com/edge/mediapipe/framework/getting_started/gpu_support.md.txt#opengl-es-setup-on-linux-desktop).

1. To build, for example, the hand tracking GPU example, run:

   ```bash
   bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \
     mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu
   ```

#### For macOS

1. To build, for example, the hand tracking GPU example, run:

   ```bash
   bazel build -c opt \
     --copt=-DMEDIAPIPE_METAL_ENABLED=1 \
     --copt=-DMEDIAPIPE_DISABLE_GPU=0 \
     --copt=-DMEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER=1 \
     --copt=-DOSX_ENABLE_3_2_CORE \
     mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu
   ```

#### Running the application

1. To run the application:

   ```bash
   GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/hand_tracking/hand_tracking_gpu \
     --calculator_graph_config_file=mediapipe/graphs/hand_tracking/hand_tracking_desktop_live_gpu.pbtxt
   ```

   This will open up your webcam as long as it is connected and on. Any errors
   is likely due to your webcam being not accessible, or GPU drivers not setup
   properly.