https://google.github.io/mediapipe/getting_started/install.html
1. bazel 설치하기(from repositopy)
// Step 1: Add Bazel distribution URI as a package source
$ sudo apt install apt-transport-https curl gnupg
$ curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
$ sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
$ echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
// optional
$ sudo apt-get install openjdk-11-jdk
// Install and update Bazel
$ sudo apt update && sudo apt install bazel
$ sudo apt-get upgrade bazel
$ bazel --version
bazel 3.7.2
2. OpenCV 라이브러리 설치(없다면)
$ sudo apt-get install -y \
libopencv-core-dev \
libopencv-highgui-dev \
libopencv-calib3d-dev \
libopencv-features2d-dev \
libopencv-imgproc-dev \
libopencv-video-dev
3. mediapipe 소스 다운로드
$ git clone https://github.com/google/mediapipe.git
$ cd mediapipe
파이선 기본 툴 설치하기
$ sudo apt install python3-dev
$ sudo apt install python3-venv
$ sudo apt install -y protobuf-compiler
WORKSPACE 수정
new_local_repository(
name = "linux_opencv",
build_file = "@//third_party:opencv_linux.BUILD",
path = "/usr/local",
)
new_local_repository(
name = "linux_ffmpeg",
build_file = "@//third_party:ffmpeg_linux.BUILD",
path = "/usr"
)
new_local_repository(
name = "macos_opencv",
build_file = "@//third_party:opencv_macos.BUILD",
path = "/usr/local/opt/opencv@3",
)
new_local_repository(
name = "macos_ffmpeg",
build_file = "@//third_party:ffmpeg_macos.BUILD",
path = "/usr/local/opt/ffmpeg",
)
new_local_repository(
name = "windows_opencv",
build_file = "@//third_party:opencv_windows.BUILD",
path = "C:\\opencv\\build",
)
/mediapipe/third_party 에서 opencv_linux.BUILD파일 수정
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([
# For OpenCV 4.x
#"include/aarch64-linux-gnu/opencv4/opencv2/cvconfig.h",
#"include/arm-linux-gnueabihf/opencv4/opencv2/cvconfig.h",
#"include/x86_64-linux-gnu/opencv4/opencv2/cvconfig.h",
"include/opencv4/opencv2/**/*.h*",
]),
includes = [
# For OpenCV 4.x
#"include/aarch64-linux-gnu/opencv4/",
#"include/arm-linux-gnueabihf/opencv4/",
#"include/x86_64-linux-gnu/opencv4/",
"include/opencv4/",
],
linkopts = [
"-l:libopencv_core.so",
"-l:libopencv_calib3d.so",
"-l:libopencv_features2d.so",
"-l:libopencv_highgui.so",
"-l:libopencv_imgcodecs.so",
"-l:libopencv_imgproc.so",
"-l:libopencv_video.so",
"-l:libopencv_videoio.so",
],
visibility = ["//visibility:public"],
)
/mediapipe/third_party 에서 ffmpeg_linux.BUILD파일 수정
cc_library(
name = "libffmpeg",
srcs = glob(
[
"lib/x86_64-linux-gnu/libav*.so",
],
),
hdrs = glob(["include/x86_64-linux-gnu/libav*/*.h"]),
includes = ["include"],
linkopts = [
"-lavcodec",
"-lavformat",
"-lavutil",
],
linkstatic = 1,
visibility = ["//visibility:public"],
)
Hello World 예제 실행하기
- CPU 또는 GPU로 실행할 수 있음
$ export GLOG_logtostderr=1
// based on CPU
$ bazel run --define MEDIAPIPE_DISABLE_GPU=1 \
mediapipe/examples/desktop/hello_world:hello_world
// based on GPU
$ bazel run --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \
mediapipe/examples/desktop/hello_world:hello_world
실행결과
swift@swift-System-Product-Name:~/workspace/ComputerVision/mediapipe$ export GLOG_logtostderr=1
swift@swift-System-Product-Name:~/workspace/ComputerVision/mediapipe$ bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'com_google_absl' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'com_google_protobuf' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'com_google_googletest' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'com_github_gflags_gflags' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'build_bazel_rules_apple' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'build_bazel_rules_swift' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'build_bazel_apple_support' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'bazel_skylib' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'pybind11' because it already exists.
INFO: Analyzed target //mediapipe/examples/desktop/hello_world:hello_world (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //mediapipe/examples/desktop/hello_world:hello_world up-to-date:
bazel-bin/mediapipe/examples/desktop/hello_world/hello_world
INFO: Elapsed time: 0.106s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Build completed successfully, 1 total action
I20210904 00:48:27.768654 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768708 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768718 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768724 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768759 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768784 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768812 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768838 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768864 113944 hello_world.cc:57] Hello World!
I20210904 00:48:27.768891 113944 hello_world.cc:57] Hello World!
swift@swift-System-Product-Name:~/workspace/ComputerVision/mediapipe$ bazel run --copt -DMESA_EGL_NO_X11_HEADERS --copt -DEGL_NO_X11 \
> mediapipe/examples/desktop/hello_world:hello_world
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'com_google_absl' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'com_google_protobuf' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'com_google_googletest' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'com_github_gflags_gflags' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'build_bazel_rules_apple' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'build_bazel_rules_swift' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'build_bazel_apple_support' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'bazel_skylib' because it already exists.
DEBUG: /home/swift/.cache/bazel/_bazel_swift/c826c44859fcfa1053ecac283c09bf0c/external/org_tensorflow/third_party/repo.bzl:109:14:
Warning: skipping import of repository 'pybind11' because it already exists.
INFO: Build options --copt and --define have changed, discarding analysis cache.
INFO: Analyzed target //mediapipe/examples/desktop/hello_world:hello_world (0 packages loaded, 1441 targets configured).
INFO: Found 1 target...
INFO: From ProtoCompile mediapipe/gpu/gl_context_options.pb.h:
bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src: warning: directory does not exist.
Target //mediapipe/examples/desktop/hello_world:hello_world up-to-date:
bazel-bin/mediapipe/examples/desktop/hello_world/hello_world
INFO: Elapsed time: 37.491s, Critical Path: 24.10s
INFO: 289 processes: 2 internal, 287 linux-sandbox.
INFO: Build completed successfully, 289 total actions
INFO: Build completed successfully, 289 total actions
I20210904 00:52:32.325080 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325129 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325220 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325237 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325305 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325318 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325325 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325331 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325409 114256 hello_world.cc:57] Hello World!
I20210904 00:52:32.325421 114256 hello_world.cc:57] Hello World!
swift@swift-System-Product-Name:~/workspace/ComputerVision/mediapipe$
728x90
'엔지니어링 > 인공지능' 카테고리의 다른 글
[ 머신러닝 예제 ] MacOS에 python 텐서플로우 설치환경 구축 (0) | 2021.12.17 |
---|---|
Google Mediapipe Python 환경설정 및 제스쳐 인식 예제 실행 (2) | 2021.09.04 |
[ YOLO ] Windows 버전 설치 환경 구성하기 (0) | 2021.06.17 |
[ OpenCV ] Ubuntu 18.04 에 CUDA11.1 + CUDNN 8.2.1 설치하기 (0) | 2021.06.13 |
[ OpenCV] USB 카메라를 이용한 Object Detection( YOLO ) (0) | 2021.06.12 |
댓글