### Install Python Dependencies Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Setup Python 3 and the required six library. ```default $ brew install python $ sudo ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python $ python --version Python 3.7.4 $ pip3 install --user six ``` -------------------------------- ### Build GPU Examples with Custom Copts Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Builds MediaPipe GPU examples on Linux desktop by overriding default GPU disable flags. Use when Mesa GPU libraries are installed. ```bash # To compile with GPU support, replace --define MEDIAPIPE_DISABLE_GPU=1 # with --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 # when building GPU examples. ``` -------------------------------- ### Run YouTube-8M Inference Web Server Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/youtube_8m.md Starts a Python web server for the YouTube-8M inference viewer. Requires 'absl-py' to be installed. ```bash python mediapipe/examples/desktop/youtube8m/viewer/server.py --root `pwd` ``` -------------------------------- ### Configure Custom OpenCV Path Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Example configuration for WORKSPACE and BUILD files when using a custom OpenCV installation path. ```bash new_local_repository( name = "linux_opencv", build_file = "@//third_party:opencv_linux.BUILD", path = "/usr/local", ) cc_library( name = "opencv", srcs = glob( [ "lib/libopencv_core.so", "lib/libopencv_highgui.so", "lib/libopencv_imgcodecs.so", "lib/libopencv_imgproc.so", "lib/libopencv_video.so", "lib/libopencv_videoio.so", ], ), hdrs = glob(["include/opencv4/**/*.h*"]), includes = ["include/opencv4/"], linkstatic = 1, visibility = ["//visibility:public"], ) ``` -------------------------------- ### Build and Install MediaPipe Package Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/python.md Build and install the MediaPipe package from source. ```bash (mp_env)mediapipe$ python3 setup.py install --link-opencv ``` ```bash (mp_env)mediapipe$ python3 setup.py bdist_wheel ``` -------------------------------- ### Run Hello World C++ Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Execute the MediaPipe Hello World example using Bazel with CPU-only configuration. ```bash $ export GLOG_logtostderr=1 # Need bazel flag 'MEDIAPIPE_DISABLE_GPU=1' if you are running on Linux desktop with CPU only $ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \ mediapipe/examples/desktop/hello_world:hello_world # Should print: # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! ``` -------------------------------- ### Start Graph and Camera Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/hello_world_ios.md Initialize the graph and start the camera source after permission is granted. ```objective-c [_cameraSource requestCameraAccessWithCompletionHandler:^void(BOOL granted) { if (granted) { // Start running self.mediapipeGraph. NSError* error; if (![self.mediapipeGraph startWithError:&error]) { NSLog(@"Failed to start graph: %@", error); } else if (![self.mediapipeGraph waitUntilIdleWithError:&error]) { NSLog(@"Failed to complete graph initial run: %@", error); } dispatch_async(_videoQueue, ^{ [_cameraSource start]; }); } }]; ``` -------------------------------- ### Run Hello World C++ Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Executes the MediaPipe Hello World example with GPU support disabled. ```bash username@DESKTOP-TMVLBJ1:~/mediapipe$ export GLOG_logtostderr=1 # Need bazel flag 'MEDIAPIPE_DISABLE_GPU=1' as desktop GPU is currently not supported username@DESKTOP-TMVLBJ1:~/mediapipe$ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \ mediapipe/examples/desktop/hello_world:hello_world # Should print: # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! ``` -------------------------------- ### Build and Run Hello World Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Build the C++ Hello World example using Bazel and execute the resulting binary. ```default C:\Users\Username\mediapipe_repo>bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --action_env PYTHON_BIN_PATH="C://python_36//python.exe" mediapipe/examples/desktop/hello_world C:\Users\Username\mediapipe_repo>set GLOG_logtostderr=1 C:\Users\Username\mediapipe_repo>bazel-bin\mediapipe\examples\desktop\hello_world\hello_world.exe # should print: # I20200514 20:43:12.277598 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.278597 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.279618 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.279618 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.279618 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.279618 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.279618 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.279618 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.279618 1200 hello_world.cc:56] Hello World! # I20200514 20:43:12.280613 1200 hello_world.cc:56] Hello World! ``` -------------------------------- ### Run Hello World C++ Example in Docker Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Executes the desktop Hello World example within the running container. ```bash $ docker run -it --name mediapipe mediapipe:latest root@bca08b91ff63:/mediapipe# GLOG_logtostderr=1 bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world ``` -------------------------------- ### Clone and Run MediaPipe Hello World Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/hello_world_cpp.md Clone the MediaPipe repository and run the 'hello_world' example using Bazel. Ensure GPU is disabled for desktop execution. ```bash $ git clone https://github.com/google/mediapipe.git $ cd mediapipe $ export GLOG_logtostderr=1 # Need bazel flag 'MEDIAPIPE_DISABLE_GPU=1' as desktop GPU is not supported currently. $ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \ mediapipe/examples/desktop/hello_world:hello_world # It should print 10 rows of Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! ``` -------------------------------- ### Run C++ Hello World Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Execute the MediaPipe Hello World example using Bazel with GPU support disabled. ```bash $ export GLOG_logtostderr=1 # Need bazel flag 'MEDIAPIPE_DISABLE_GPU=1' as desktop GPU is currently not supported $ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \ mediapipe/examples/desktop/hello_world:hello_world # Should print: # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! ``` -------------------------------- ### Install OpenCV Core Development Libraries Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Install essential OpenCV development libraries using apt-get. This command installs core, highgui, calib3d, features2d, imgproc, and video modules. ```bash sudo apt-get install -y \ libopencv-core-dev \ libopencv-highgui-dev \ libopencv-calib3d-dev \ libopencv-features2d-dev \ libopencv-imgproc-dev \ libopencv-video-dev ``` -------------------------------- ### Install Bazelisk via Homebrew Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/ios.md Uses Homebrew to install the Bazelisk build tool. ```bash brew install bazelisk ``` -------------------------------- ### Install MediaPipe Package Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/python.md Install the MediaPipe package via pip and launch the Python interpreter. ```bash (mp_env)$ pip install mediapipe (mp_env)$ python3 ``` -------------------------------- ### Install Required Packages Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Installs essential build tools, git, python, zip, adb, and Java JDK. ```bash username@DESKTOP-TMVLBJ1:~$ sudo apt-get update && sudo apt-get install -y build-essential git python zip adb openjdk-8-jdk ``` -------------------------------- ### Install OpenCV Libraries Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Installs pre-compiled OpenCV development libraries using the apt package manager. ```bash username@DESKTOP-TMVLBJ1:~/mediapipe$ sudo apt-get install libopencv-core-dev libopencv-highgui-dev \ libopencv-calib3d-dev libopencv-features2d-dev \ libopencv-imgproc-dev libopencv-video-dev ``` -------------------------------- ### Build Android Example in Docker Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Sets up the Android SDK/NDK and builds the object detection Android application. ```bash $ docker run -it --name mediapipe mediapipe:latest root@bca08b91ff63:/mediapipe# bash ./setup_android_sdk_and_ndk.sh root@bca08b91ff63:/mediapipe# bazel build -c opt --config=android_arm64 mediapipe/examples/android/src/java/com/google/mediapipe/apps/objectdetectiongpu:objectdetectiongpu ``` -------------------------------- ### Build and Install Android Application Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/hello_world_android.md Commands to build the APK using Bazel and install it on a connected device via ADB. ```default bazel build -c opt --config=android_arm64 $APPLICATION_PATH:helloworld ``` ```default adb install bazel-bin/$APPLICATION_PATH/helloworld.apk ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/python.md Create and activate a virtual environment for MediaPipe development. ```bash $ python3 -m venv mp_env && source mp_env/bin/activate ``` -------------------------------- ### Install Dependencies on Debian or Ubuntu Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/python.md Install required system dependencies for building MediaPipe on Debian-based systems. ```bash $ sudo apt install python3-dev $ sudo apt install python3-venv $ sudo apt install -y protobuf-compiler # If you need to build opencv from source. $ sudo apt install cmake ``` -------------------------------- ### Start Camera with Metadata Selection Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/hello_world_android.md Use the retrieved metadata to determine the camera facing direction before starting the camera. ```java CameraHelper.CameraFacing cameraFacing = applicationInfo.metaData.getBoolean("cameraFacingFront", false) ? CameraHelper.CameraFacing.FRONT : CameraHelper.CameraFacing.BACK; cameraHelper.startCamera(this, cameraFacing, /*unusedSurfaceTexture=*/ null); ``` -------------------------------- ### Install MSYS2 Packages Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Install essential build tools using the pacman package manager. ```default C:\> pacman -S git patch unzip ``` -------------------------------- ### Start Graph and Add Packets Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/python_framework.md Start the graph execution and inject data packets into input streams. ```python graph.start_run() graph.add_packet_to_input_stream( 'in_stream', mp.packet_creator.create_string('abc').at(0)) rgb_img = cv2.cvtColor(cv2.imread('/path/to/your/image.png'), cv2.COLOR_BGR2RGB) graph.add_packet_to_input_stream( 'in_stream', mp.packet_creator.create_image_frame(image_format=mp.ImageFormat.SRGB, data=rgb_img).at(1)) ``` -------------------------------- ### Build Objectron Desktop Application Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/objectron.md Command to compile the Objectron CPU example using Bazel. ```bash bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/object_detection_3d:objectron_cpu ``` -------------------------------- ### Install Xcode Command Line Tools Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/ios.md Installs the necessary command line tools for Xcode development. ```bash xcode-select --install ``` -------------------------------- ### Install msvc-runtime package Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/troubleshooting.md Use this command to install the msvc-runtime package if you encounter DLL load failures on Windows. ```bash $ python -m pip install msvc-runtime ``` -------------------------------- ### Verify CUPTI Installation Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/gpu_support.md List the contents of the CUPTI directory to confirm its installation. This is a component required for CUDA. ```bash $ ls /usr/local/cuda/extras/CUPTI /lib64 libcupti.so libcupti.so.10.1.208 libnvperf_host.so libnvperf_target.so libcupti.so.10.1 libcupti_static.a libnvperf_host_static.a ``` -------------------------------- ### Hello World Output Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Expected output when running the MediaPipe C++ Hello World example. ```text # Should print: # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! # Hello World! ``` -------------------------------- ### Build TensorFlow Object Detection Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/object_detection.md Compiles the TensorFlow CPU inference example for desktop. Note that the initial build may take significant time as it builds TensorFlow targets from scratch. ```bash bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 --define no_aws_support=true --linkopt=-s \ mediapipe/examples/desktop/object_detection:object_detection_tensorflow ``` -------------------------------- ### Compile Face Detection Coral Example with Bazel Source: https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/examples/coral/README.md Compiles the MediaPipe face detection example for Coral USB devices using Bazel. Requires libusb to be installed. Sets optimization mode, disables GPU, and specifies Edge TPU type. ```bash bazel build \ --compilation_mode=opt \ --define darwinn_portable=1 \ --define MEDIAPIPE_DISABLE_GPU=1 \ --define MEDIAPIPE_EDGE_TPU=usb \ --linkopt=-l:libusb-1.0.so \ mediapipe/examples/coral:face_detection_tpu build ``` -------------------------------- ### Run YouTube-8M Web Interface Server Source: https://github.com/google-ai-edge/mediapipe/blob/master/mediapipe/examples/desktop/youtube8m/README.md Starts the Python web server for the YouTube-8M inference viewer. Requires 'absl-py' to be installed. Navigate to localhost:8008 in a browser to access the interface. ```bash python mediapipe/examples/desktop/youtube8m/viewer/server.py --root `pwd` ``` -------------------------------- ### Install MediaPipe Holistic with NPM Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/javascript.md Use npm to install the MediaPipe Holistic package locally. This command installs the specified package and its dependencies. ```bash npm install @mediapipe/holistic. ``` -------------------------------- ### Run MediaPipe Hello World (CPU) Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Executes the C++ Hello World example on Linux desktop using CPU only. Sets GLOG to log to stderr. ```bash export GLOG_logtostderr=1 # if you are running on Linux desktop with CPU only $ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \ mediapipe/examples/desktop/hello_world:hello_world ``` -------------------------------- ### Face Effect Mobile iOS Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/face_mesh.md Face effect example for iOS. This example works for a single face and requires a specific build target. ```bash mediapipe/examples/ios/faceeffect ``` -------------------------------- ### Face Effect Mobile Android Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/face_mesh.md Face effect example for Android. This example works for a single face and requires a specific build target. ```bash mediapipe/examples/android/src/java/com/google/mediapipe/apps/faceeffect ``` -------------------------------- ### Build MediaPipe Hands for CPU Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/cpp.md Compiles the hand tracking example for CPU execution using Bazel. ```bash bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hand_tracking:hand_tracking_cpu ``` -------------------------------- ### Face Mesh Desktop CPU Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/face_mesh.md Run Face Mesh on desktop using CPU. The graph file and target build are specified. ```bash mediapipe/examples/desktop/face_mesh:face_mesh_cpu ``` -------------------------------- ### Install Dependencies on macOS Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/python.md Install required system dependencies for building MediaPipe on macOS. ```bash $ brew install protobuf # If you need to build opencv from source. $ brew install cmake ``` -------------------------------- ### Run MediaPipe Hello World (GPU) Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Executes the C++ Hello World example on Linux desktop with GPU support enabled via Mesa drivers. Sets GLOG to log to stderr. ```bash export GLOG_logtostderr=1 # If you are running on Linux desktop with GPU support enabled (via mesa drivers) $ bazel run --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \ mediapipe/examples/desktop/hello_world:hello_world ``` -------------------------------- ### Install Python Six Library Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/ios.md Installs the six library required for TensorFlow compatibility. ```bash pip3 install --user six ``` -------------------------------- ### Face Mesh Desktop GPU Example Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/face_mesh.md Run Face Mesh on desktop using GPU. The graph file and target build are specified. ```bash mediapipe/examples/desktop/face_mesh:face_mesh_gpu ``` -------------------------------- ### Build MediaPipe Hands for GPU Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/cpp.md Compiles the hand tracking example for GPU execution on Linux using Bazel. ```bash bazel build -c opt --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \ mediapipe/examples/desktop/hand_tracking:hand_tracking_gpu ``` -------------------------------- ### Install OpenCV via MacPorts Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Alternative installation method for OpenCV using the MacPorts package manager. ```bash $ port install opencv ``` -------------------------------- ### Initialize and configure CameraXPreviewHelper Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/hello_world_android.md Initialize CameraXPreviewHelper and set a listener to handle camera start events. This listener receives the SurfaceTexture for displaying frames and makes the preview view visible. ```java public void startCamera() { cameraHelper = new CameraXPreviewHelper(); cameraHelper.setOnCameraStartedListener( surfaceTexture -> { previewFrameTexture = surfaceTexture; // Make the display view visible to start showing the preview. previewDisplayView.setVisibility(View.VISIBLE); }); } ``` -------------------------------- ### Install OpenCV via Package Manager Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/install.md Use yum to install the pre-compiled OpenCV development files. ```bash $ sudo yum install opencv-devel ``` -------------------------------- ### Import MediaPipe Solution Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/python.md Import the MediaPipe package and initialize a specific solution. ```python import mediapipe as mp mp_face_mesh = mp.solutions.face_mesh ``` -------------------------------- ### Install Python Requirements Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/getting_started/python.md Install necessary Python packages from the requirements file within the virtual environment. ```bash (mp_env)mediapipe$ pip3 install -r requirements.txt ``` -------------------------------- ### Build Template Matching Index File Source: https://github.com/google-ai-edge/mediapipe/blob/master/docs/solutions/knift.md Builds the template matching application for desktop and generates an index file for template images. Ensure all template images are in a single directory. ```bash bazel build -c opt --define MEDIAPIPE_DISABLE_GPU=1 \ mediapipe/examples/desktop/template_matching:template_matching_tflite ``` ```bash bazel-bin/mediapipe/examples/desktop/template_matching/template_matching_tflite \ --calculator_graph_config_file=mediapipe/graphs/template_matching/index_building.pbtxt \ --input_side_packets="file_directory=