MediaPipe框架- 在C中++的Hello World!

Hello World! in C++

在C中++的Hello World!

1.Ensure you have a working version of MediaPipe Framework. See installation instructions.

​1.确保拥有MediaPipe Framework的工作版本。请参阅安装说明。

2.To run the hello world example:

​2.运行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!

3.The hello world example uses a simple MediaPipe graph in the PrintHelloWorld() function, defined in a CalculatorGraphConfig proto.

​3.helloworld示例在CalculatorGraphConfig proto中定义的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"
    }
  )");

You can visualize this graph using MediaPipe Visualizer by pasting the CalculatorGraphConfig content below into the visualizer. See here for help on the visualizer.

​通过将下面的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"
    }

This graph consists of 1 graph input stream (in) and 1 graph output stream (out), and 2 PassThroughCalculators connected serially.

​该图由1个图输入流(in)和1个图输出流(out)以及2个串联的PassThroughCalculator组成。

4.Before running the graph, an OutputStreamPoller object is connected to the output stream in order to later retrieve the graph output, and a graph run is started with StartRun.

​4.在运行图形之前,将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({}));

5.The example then creates 10 packets (each packet contains a string "Hello World!" with Timestamp values ranging from 0, 1, ... 9) using the MakePacket function, adds each packet into the graph through the in input stream, and finally closes the input stream to finish the graph run.

​5.然后,该示例使用MakePacket函数创建10个数据包(每个数据包包含一个字符串“Hello World!”,时间戳值范围为0、1…9),通过输入流将每个数据包添加到图形中,最后关闭输入流以完成图形运行。

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"));

6.Through the OutputStreamPoller object the example then retrieves all 10 packets from the output stream, gets the string content out of each packet and prints it to the output log.

6.通过OutputStreamPoller对象,该示例从输出流中检索所有10个数据包,从每个数据包中获取字符串内容,并将其打印到输出日志中。

mediapipe::Packet packet;
while (poller.Next(&packet)) {
  LOG(INFO) << packet.Get<string>();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值