hello_world example expanded with library option
This commit is contained in:
parent
4a20e9909d
commit
66171159ef
|
@ -205,7 +205,7 @@ new_local_repository(
|
|||
# For local MacOS builds, the path should point to an opencv@3 installation.
|
||||
# If you edit the path here, you will also need to update the corresponding
|
||||
# prefix in "opencv_macos.BUILD".
|
||||
path = "/usr/local",
|
||||
path = "/opt/homebrew",
|
||||
)
|
||||
|
||||
new_local_repository(
|
||||
|
|
|
@ -16,9 +16,10 @@ licenses(["notice"])
|
|||
|
||||
package(default_visibility = ["//mediapipe/examples:__subpackages__"])
|
||||
|
||||
cc_binary(
|
||||
name = "hello_world",
|
||||
cc_library(
|
||||
name = "hello_world_library",
|
||||
srcs = ["hello_world.cc"],
|
||||
hdrs = ["hello_world.hh"],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//mediapipe/calculators/core:pass_through_calculator",
|
||||
|
@ -28,3 +29,11 @@ cc_binary(
|
|||
"//mediapipe/framework/port:status",
|
||||
],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "hello-world-binary",
|
||||
srcs = ["hello-world-main.cc"],
|
||||
deps = [
|
||||
":hello_world_library",
|
||||
],
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
#include "hello_world.hh"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
theFunctionToCall(argv[0]);
|
||||
return 0;
|
||||
}
|
|
@ -14,17 +14,18 @@
|
|||
//
|
||||
// A simple example to print out "Hello World!" from a MediaPipe graph.
|
||||
|
||||
#include "hello_world.hh"
|
||||
|
||||
#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 {
|
||||
|
||||
absl::Status PrintHelloWorld() {
|
||||
absl::Status PrintHelloWorld()
|
||||
{
|
||||
// Configures a simple graph, which concatenates 2 PassThroughCalculators.
|
||||
CalculatorGraphConfig config =
|
||||
ParseTextProtoOrDie<CalculatorGraphConfig>(R"pb(
|
||||
mediapipe::CalculatorGraphConfig config =
|
||||
mediapipe::ParseTextProtoOrDie<mediapipe::CalculatorGraphConfig>(R"pb(
|
||||
input_stream: "in"
|
||||
output_stream: "out"
|
||||
node {
|
||||
|
@ -39,29 +40,32 @@ absl::Status PrintHelloWorld() {
|
|||
}
|
||||
)pb");
|
||||
|
||||
CalculatorGraph graph;
|
||||
mediapipe::CalculatorGraph graph;
|
||||
MP_RETURN_IF_ERROR(graph.Initialize(config));
|
||||
ASSIGN_OR_RETURN(OutputStreamPoller poller,
|
||||
ASSIGN_OR_RETURN(mediapipe::OutputStreamPoller poller,
|
||||
graph.AddOutputStreamPoller("out"));
|
||||
MP_RETURN_IF_ERROR(graph.StartRun({}));
|
||||
// Give 10 input packets that contains the same string "Hello World!".
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
MP_RETURN_IF_ERROR(graph.AddPacketToInputStream(
|
||||
"in", MakePacket<std::string>("Hello World!").At(Timestamp(i))));
|
||||
"in", mediapipe::MakePacket<std::string>("Hello World!").At(mediapipe::Timestamp(i))));
|
||||
}
|
||||
// Close the input stream "in".
|
||||
MP_RETURN_IF_ERROR(graph.CloseInputStream("in"));
|
||||
mediapipe::Packet packet;
|
||||
// Get the output packets string.
|
||||
while (poller.Next(&packet)) {
|
||||
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;
|
||||
void theFunctionToCall(const char* argv0)
|
||||
{
|
||||
google::InitGoogleLogging(argv0);
|
||||
CHECK(PrintHelloWorld().ok());
|
||||
}
|
||||
|
||||
|
||||
|
|
3
mediapipe/examples/desktop/hello_world/hello_world.hh
Normal file
3
mediapipe/examples/desktop/hello_world/hello_world.hh
Normal file
|
@ -0,0 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
void theFunctionToCall(const char* argv0);
|
Loading…
Reference in New Issue
Block a user