본문 바로가기
Android

[Android][Media Pipe] 인공지능 AI Media Pipe

by sosob 2023. 7. 28.
728x90

Media Pipe 를 이용해 할수 있는 매력적인것들이 많아요.. 

 

 

Media Pipe Framework integration on Android

Media Pipe Framework 를 설치하고, 안드로이드 샘플앱가지 연동하는 과정을 끄적여본다. 

아래 사이트는 한번 읽어보고.. 넘어간다.

https://developers.google.com/mediapipe/framework/getting_started/android

 

MediaPipe Framework on Android  |  Google for Developers

MediaPipe Framework on Android Stay organized with collections Save and categorize content based on your preferences. Please follow instructions below to build Android example apps with MediaPipe Framework. To learn more about these example apps, start fro

developers.google.com

 

 

Media Pipe Framework Install. 

Installing on macOS

- Prework 

 -- Install Homebrew

 -- Install Xcode and its Command Line Tools by xcode-select --install. 

 

- Install Bazelisk.

 -- Follow the official Baze documentation to install Bazelisk. 

 -- https://bazel.build/install/bazelisk?hl=ko 

 

Bazelisk를 사용하여 Bazel 설치 / 업데이트

이 페이지는 Cloud Translation API를 통해 번역되었습니다. Switch to English Bazelisk를 사용하여 Bazel 설치 / 업데이트 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.

bazel.build

-- https://bazel.build/install/os-x?hl=ko 

 

macOS에 Bazel 설치

문제 신고open_in_new 소스 보기open_in_new 이 페이지에서는 macOS에 Bazel을 설치하고 환경을 설정하는 방법을 설명합니다. 다음 방법 중 하나를 사용하여 macOS에 Bazel을 설치할 수 있습니다. Bazel에는 두

bazel.build

 

- Checkout MediaPipe repository. 

$git clone -depth 1 https://github.com/google/mediapipe.git
$cd mediapipe
% git clone --depth 1 https://github.com/google/mediapipe.git
Cloning into 'mediapipe'...
remote: Enumerating objects: 4311, done.
remote: Counting objects: 100% (4311/4311), done.
remote: Compressing objects: 100% (3374/3374), done.
remote: Total 4311 (delta 1442), reused 2311 (delta 842), pack-reused 0
Receiving objects: 100% (4311/4311), 39.61 MiB | 16.87 MiB/s, done.
Resolving deltas: 100% (1442/1442), done.

 

- Install OpenCV and FFmpeg. 

Option 1. Use HomeBrew package manager tool to install the pre-compiled OpenCV 3 libraries. FFmpeg will be installed via OpenCV.

 

% brew install opencv@3
Running `brew update --auto-update`...
==> Homebrew collects anonymous analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics have been recorded yet (nor will be during this `brew` run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
% brew uninstall --ignore-dependencies glog
Uninstalling /opt/homebrew/Cellar/glog/0.6.0... (22 files, 334.8KB)

- Make sure that Python 3 and the Python "six" library are installed.

% brew install python
==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
######################################################################### 100.0%
==> Fetching python@3.11
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.11/manifests/3.11.4_1-
######################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/python/3.11/blobs/sha256:0b34ef
######################################################################### 100.0%
==> Pouring python@3.11--3.11.4_1.arm64_ventura.bottle.1.tar.gz
==> /opt/homebrew/Cellar/python@3.11/3.11.4_1/bin/python3.11 -Im ensurepip
==> /opt/homebrew/Cellar/python@3.11/3.11.4_1/bin/python3.11 -Im pip install -v 
==> Caveats
Python has been installed as
  /opt/homebrew/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /opt/homebrew/opt/python@3.11/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /opt/homebrew/lib/python3.11/site-packages

tkinter is no longer included with this formula, but it is available separately:
  brew install python-tk@3.11

gdbm (`dbm.gnu`) is no longer included in this formula, but it is available separately:
  brew install python-gdbm@3.11
`dbm.ndbm` changed database backends in Homebrew Python 3.11.
If you need to read a database from a previous Homebrew Python created via `dbm.ndbm`,
you'll need to read your database using the older version of Homebrew Python and convert to another format.
`dbm` still defaults to `dbm.gnu` when it is installed.

For more information about Homebrew and Python, see: https://docs.brew.sh/Homebrew-and-Python
==> Summary
🍺  /opt/homebrew/Cellar/python@3.11/3.11.4_1: 3,287 files, 61.9MB
==> Running `brew cleanup python@3.11`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

 

 

sudo ln -s -f /usr/local/bin/python3.7 /usr/local/bin/python

 

 

 % python --version
Python 3.11.2

 

% pip3 install --user six
Requirement already satisfied: six in /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages (1.16.0)

Run the Hello World! in C++ example.

 

% bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/0258a53521cfedf5cb80c2b1d4a66c942615de74.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
ERROR: Skipping 'mediapipe/examples/desktop/hello_world:hello_world': no such package 'mediapipe/examples/desktop/hello_world/mediapipe/examples/desktop/hello_world': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/mediapipe/examples/desktop/hello_world
WARNING: Target pattern parsing failed.
ERROR: no such package 'mediapipe/examples/desktop/hello_world/mediapipe/examples/desktop/hello_world': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/mediapipe/examples/desktop/hello_world
INFO: Elapsed time: 0.074s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
ERROR: Build failed. Not running target
sjmyeong@SJ hello_world % bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world            
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/0258a53521cfedf5cb80c2b1d4a66c942615de74.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
ERROR: Skipping 'mediapipe/examples/desktop/hello_world': no such target '//mediapipe/examples/desktop/hello_world:mediapipe/examples/desktop/hello_world': target 'mediapipe/examples/desktop/hello_world' not declared in package 'mediapipe/examples/desktop/hello_world' defined by /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/BUILD (Tip: use `query "//mediapipe/examples/desktop/hello_world:*"` to see all the targets in that package)
WARNING: Target pattern parsing failed.
ERROR: no such target '//mediapipe/examples/desktop/hello_world:mediapipe/examples/desktop/hello_world': target 'mediapipe/examples/desktop/hello_world' not declared in package 'mediapipe/examples/desktop/hello_world' defined by /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/BUILD (Tip: use `query "//mediapipe/examples/desktop/hello_world:*"` to see all the targets in that package)
INFO: Elapsed time: 0.097s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
ERROR: Build failed. Not running target
sjmyeong@SJ hello_world % bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/0258a53521cfedf5cb80c2b1d4a66c942615de74.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
ERROR: Skipping 'mediapipe/examples/desktop/hello_world:hello_world': no such package 'mediapipe/examples/desktop/hello_world/mediapipe/examples/desktop/hello_world': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/mediapipe/examples/desktop/hello_world
WARNING: Target pattern parsing failed.
ERROR: no such package 'mediapipe/examples/desktop/hello_world/mediapipe/examples/desktop/hello_world': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/mediapipe/examples/desktop/hello_world
INFO: Elapsed time: 0.053s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
ERROR: Build failed. Not running target
sjmyeong@SJ hello_world % bazel run --define MEDIAPIPE_DISABLE_GPU=1 /hello_world:hello_world 
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/0258a53521cfedf5cb80c2b1d4a66c942615de74.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
ERROR: Skipping '/hello_world:hello_world': not a valid absolute pattern (absolute target patterns must start with exactly two slashes): '/hello_world:hello_world'
WARNING: Target pattern parsing failed.
ERROR: not a valid absolute pattern (absolute target patterns must start with exactly two slashes): '/hello_world:hello_world'
INFO: Elapsed time: 0.051s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
ERROR: Build failed. Not running target
sjmyeong@SJ hello_world % bazel run --define MEDIAPIPE_DISABLE_GPU=1 hello_world:hello_world 
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/0258a53521cfedf5cb80c2b1d4a66c942615de74.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
ERROR: Skipping 'hello_world:hello_world': no such package 'mediapipe/examples/desktop/hello_world/hello_world': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/hello_world
WARNING: Target pattern parsing failed.
ERROR: no such package 'mediapipe/examples/desktop/hello_world/hello_world': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/hello_world
INFO: Elapsed time: 0.050s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
ERROR: Build failed. Not running target
sjmyeong@SJ hello_world % bazel run --define MEDIAPIPE_DISABLE_GPU=1 hello_world:hello_world
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/0258a53521cfedf5cb80c2b1d4a66c942615de74.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
ERROR: Skipping 'hello_world:hello_world': no such package 'mediapipe/examples/desktop/hello_world/hello_world': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/hello_world
WARNING: Target pattern parsing failed.
ERROR: no such package 'mediapipe/examples/desktop/hello_world/hello_world': BUILD file not found in any of the following directories. Add a BUILD file to a directory to mark it as a package.
 - /Users/sjmyeong/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world/hello_world
INFO: Elapsed time: 0.052s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)
ERROR: Build failed. Not running target
sjmyeong@SJ hello_world % bazel run --define MEDIAPIPE_DISABLE_GPU=1 hello_world            
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/llvm/llvm-project/archive/0258a53521cfedf5cb80c2b1d4a66c942615de74.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from http://mirror.tensorflow.org/github.com/bazelbuild/rules_closure/archive/cf1e44edb908e9616030cc83d085989b8e6cd6df.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
WARNING: Download from https://storage.googleapis.com/mirror.tensorflow.org/github.com/tensorflow/runtime/archive/7d879c8b161085a4374ea481b93a52adb19c0529.tar.gz failed: class java.io.FileNotFoundException GET returned 404 Not Found
DEBUG: Rule 'rules_cc' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = "691a29db9c336349e48e04c5c2f4873f2890af5cbfa6e51f4de87fefe6169294"
DEBUG: Repository rules_cc instantiated at:
  /Users/sjmyeong/mediapipe/mediapipe/WORKSPACE:40:13: in <toplevel>
Repository rule http_archive defined at:
  /private/var/tmp/_bazel_sjmyeong/dfe6c1cb11887963760080ded44a6de9/external/bazel_tools/tools/build_defs/repo/http.bzl:372:31: in <toplevel>
WARNING: /Users/sjmyeong/mediapipe/mediapipe/mediapipe/framework/tool/BUILD:197:24: in cc_library rule //mediapipe/framework/tool:field_data_cc_proto: target '//mediapipe/framework/tool:field_data_cc_proto' depends on deprecated target '@com_google_protobuf//:cc_wkt_protos': Only for backward compatibility. Do not use.
WARNING: /Users/sjmyeong/mediapipe/mediapipe/mediapipe/framework/BUILD:59:24: in cc_library rule //mediapipe/framework:calculator_cc_proto: target '//mediapipe/framework:calculator_cc_proto' depends on deprecated target '@com_google_protobuf//:cc_wkt_protos': Only for backward compatibility. Do not use.
INFO: Analyzed target //mediapipe/examples/desktop/hello_world:hello_world (92 packages loaded, 2049 targets configured).
INFO: Found 1 target...
INFO: From Compiling src/google/protobuf/stubs/strutil.cc [for tool]:
external/com_google_protobuf/src/google/protobuf/stubs/strutil.cc:506:11: warning: 'sprintf' is deprecated: This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead. [-Wdeprecated-declarations]
          sprintf(dest + used, (use_hex ? "\\x%02x" : "\\%03o"),
          ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/stdio.h:188:1: note: 'sprintf' has been explicitly marked deprecated here
__deprecated_msg("This function is provided for compatibility reasons only.  Due to security concerns inherent in the design of sprintf(3), it is highly recommended that you use snprintf(3) instead.")
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/usr/include/sys/cdefs.h:215:48: note: expanded from macro '__deprecated_msg'
        #define __deprecated_msg(_msg) __attribute__((__deprecated__(_msg)))
                                                      ^
1 warning generated.
Target //mediapipe/examples/desktop/hello_world:hello_world up-to-date:
  bazel-bin/mediapipe/examples/desktop/hello_world/hello_world
INFO: Elapsed time: 84.380s, Critical Path: 51.51s
INFO: 677 processes: 34 internal, 643 darwin-sandbox.
INFO: Build completed successfully, 677 total actions
INFO: Running command line: bazel-bin/mediapipe/examples/desktop/hello_world/hello_world
I20230728 14:00:22.238831 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239416 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239425 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239432 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239439 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239445 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239452 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239459 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239465 13552335 hello_world.cc:57] Hello World!
I20230728 14:00:22.239472 13552335 hello_world.cc:57] Hello World!
% pwd 
/mediapipe/mediapipe/mediapipe/examples/desktop/hello_world

 

샘플의 helloworld 는 돌려봤는데..

매번 이렇게 빌드하고 해야하는건가..

 

728x90