確認您使用的是可運作的 MediaPipe 架構。請參閱安裝操作說明。
如要執行
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
範例會在PrintHelloWorld()
函式中使用簡單的 MediaPipe 圖表,在CalculatorGraphConfig
proto 中定義。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" } )");
您可以使用 MediaPipe Visualizer 將下方的 CalculatorGraphConfig 內容貼到視覺化工具中,以視覺化方式呈現這張圖。如需視覺化工具的說明,請參閱這裡。
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 個封包 (每個封包都包含「Hello World!」字串,時間戳記值介於 0、1、... 9),透過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>(); }
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-05-14 (世界標準時間)。
[{
"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":"其他"
}]