반응형

Mediapipe의 Hello_World  예제 사용방법을 소개합니다. 



2021. 7. 24 최초작성 



Mediapipe를 Ubuntu에 설치하는 방법을 먼저 진행하세요.



MediaPipe를 Ubuntu에 설치하는 방법

https://webnautes.tistory.com/1404




다음 위치에 Hello World 예제가 존재합니다.

 

webnautes@webnautes-PC:~/mediapipe$ pwd

/home/webnautes/mediapipe

 

webnautes@webnautes-PC:~/mediapipe$ find . | grep hello_world.cc

./mediapipe/examples/desktop/hello_world/hello_world.cc




해당 파일을 열어 출력할 문자를 안녕하세요로 변경한 후

 

    MP_RETURN_IF_ERROR(graph.AddPacketToInputStream(
        "in", MakePacket<std::string>("안녕하세요").At(Timestamp(i))));

 

// Copyright 2019 The MediaPipe Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// A simple example to print out "Hello World!" from a MediaPipe graph.

#include "mediapipe/framework/calculator_graph.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/parse_text_proto.h"
#include "mediapipe/framework/port/status.h"

namespace mediapipe {

::mediapipe::Status PrintHelloWorld() {
  // Configures a simple graph, which concatenates 2 PassThroughCalculators.
  CalculatorGraphConfig config = ParseTextProtoOrDie<CalculatorGraphConfig>(R"(
    input_stream: "in"
    output_stream: "out"
    node {
      calculator: "PassThroughCalculator"
      input_stream: "in"
      output_stream: "out1"
    }
    node {
      calculator: "PassThroughCalculator"
      input_stream: "out1"
      output_stream: "out"
    }
  )");

  CalculatorGraph graph;
  MP_RETURN_IF_ERROR(graph.Initialize(config));
  ASSIGN_OR_RETURN(OutputStreamPoller poller,
                  graph.AddOutputStreamPoller("out"));
  MP_RETURN_IF_ERROR(graph.StartRun({}));
  // Give 10 input packets that contains the same std::string "Hello World!".
  for (int i = 0; i < 10; ++i) {
    MP_RETURN_IF_ERROR(graph.AddPacketToInputStream(
        "in", MakePacket<std::string>("안녕하세요").At(Timestamp(i))));
  }
  // Close the input stream "in".
  MP_RETURN_IF_ERROR(graph.CloseInputStream("in"));
  mediapipe::Packet packet;
  // Get the output packets std::string.
  while (poller.Next(&packet)) {
    LOG(INFO) << packet.Get<std::string>();
  }
  return graph.WaitUntilDone();
}
}  // namespace mediapipe

int main(int argc, char** argv) {
  google::InitGoogleLogging(argv[0]);
  CHECK(mediapipe::PrintHelloWorld().ok());
  return 0;
}



실행시켜 봅니다.

 

webnautes@webnautes-PC:~/mediapipe$ export GLOG_logtostderr=1

webnautes@webnautes-PC:~/mediapipe$ bazel run --define MEDIAPIPE_DISABLE_GPU=1 mediapipe/examples/desktop/hello_world:hello_world



빌드가 완료되길 기다려야 합니다.

조금 수정했는데도 전체를 다시 빌드하는 듯합니다.



다음처럼 바뀐 문자열을 출력합니다.

 

I20210724 18:30:33.493777  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.493837  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.493850  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.493871  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.493927  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.493961  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.494006  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.494050  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.494093  5622 hello_world.cc:57] 안녕하세요

I20210724 18:30:33.494136  5622 hello_world.cc:57] 안녕하세요




./mediapipe/examples/desktop/ 위치에 다른 예제들도 있으니  검토해보세요.



$ ls ./mediapipe/examples/desktop/

BUILD                       hair_segmentation    object_tracking

README.md                   hand_tracking        pose_tracking

__init__.py                 hello_world          selfie_segmentation

autoflip                    holistic_tracking    simple_run_graph_main.cc

demo_run_graph_main.cc      iris_tracking        template_matching

demo_run_graph_main_gpu.cc  media_sequence       youtube8m

face_detection              object_detection

face_mesh                   object_detection_3






반응형

문제 발생시 지나치지 마시고 댓글 남겨주시면 가능한 빨리 답장드립니다.

도움이 되셨다면 토스아이디로 후원해주세요.
https://toss.me/momo2024


제가 쓴 책도 한번 검토해보세요 ^^

+ Recent posts