MediaPipe Framework の作業バージョンがあることを確認します。インストール手順をご覧ください。
hello world
の例を実行するには、次のようにします。$ 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!
hello world
の例では、CalculatorGraphConfig
プロトコルで定義されたPrintHelloWorld()
関数で単純な MediaPipe グラフを使用しています。absl::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" } )");
以下の CalculatorGraphConfig コンテンツをビジュアライザーに貼り付けると、MediaPipe Visualizer を使用してこのグラフを可視化できます。ビジュアライザのヘルプについては、こちらをご覧ください。
input_stream: "in" output_stream: "out" node { calculator: "PassThroughCalculator" input_stream: "in" output_stream: "out1" } node { calculator: "PassThroughCalculator" input_stream: "out1" output_stream: "out" }
このグラフは、1 つのグラフ入力ストリーム(
in
)と 1 つのグラフ出力ストリーム(out
)で構成され、直列に接続された 2 つのPassThroughCalculator
で構成されています。グラフを実行する前に、後でグラフ出力を取得するために
OutputStreamPoller
オブジェクトが出力ストリームに接続され、StartRun
でグラフの実行が開始されます。CalculatorGraph graph; MP_RETURN_IF_ERROR(graph.Initialize(config)); MP_ASSIGN_OR_RETURN(OutputStreamPoller poller, graph.AddOutputStreamPoller("out")); MP_RETURN_IF_ERROR(graph.StartRun({}));
次に、
MakePacket
関数を使用して 10 個のパケット(各パケットにはタイムスタンプ値が 0、1、... 9 の文字列「Hello World!」を含む)を作成し、in
入力ストリームを介して各パケットをグラフに追加し、最後に入力ストリームを閉じてグラフの実行を終了します。for (int i = 0; i < 10; ++i) { MP_RETURN_IF_ERROR(graph.AddPacketToInputStream("in", MakePacket<std::string>("Hello World!").At(Timestamp(i)))); } MP_RETURN_IF_ERROR(graph.CloseInputStream("in"));
この例では、
OutputStreamPoller
オブジェクトを使用して出力ストリームから 10 パケットすべてを取得し、各パケットから文字列内容を取得して出力ログに出力しています。mediapipe::Packet packet; while (poller.Next(&packet)) { LOG(INFO) << packet.Get<string>(); }
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2024-05-14 UTC。
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"必要な情報がない"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"複雑すぎる / 手順が多すぎる"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"最新ではない"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻訳に関する問題"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"サンプル / コードに問題がある"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"その他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"わかりやすい"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"問題の解決に役立った"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"その他"
}]