From 66171159ef401f6bd811a80ccc997b797ec8d91a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Martinovi=C4=87?= Date: Thu, 14 Jul 2022 23:21:04 +0200 Subject: [PATCH] hello_world example expanded with library option --- WORKSPACE | 2 +- mediapipe/examples/desktop/hello_world/BUILD | 13 +++++-- .../desktop/hello_world/hello-world-main.cc | 7 ++++ .../desktop/hello_world/hello_world.cc | 34 +++++++++++-------- .../desktop/hello_world/hello_world.hh | 3 ++ 5 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 mediapipe/examples/desktop/hello_world/hello-world-main.cc create mode 100644 mediapipe/examples/desktop/hello_world/hello_world.hh diff --git a/WORKSPACE b/WORKSPACE index e85e34d84..0cb7e0ed6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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( diff --git a/mediapipe/examples/desktop/hello_world/BUILD b/mediapipe/examples/desktop/hello_world/BUILD index edf98bf13..3d197f8b9 100644 --- a/mediapipe/examples/desktop/hello_world/BUILD +++ b/mediapipe/examples/desktop/hello_world/BUILD @@ -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", + ], +) \ No newline at end of file diff --git a/mediapipe/examples/desktop/hello_world/hello-world-main.cc b/mediapipe/examples/desktop/hello_world/hello-world-main.cc new file mode 100644 index 000000000..f046b1a82 --- /dev/null +++ b/mediapipe/examples/desktop/hello_world/hello-world-main.cc @@ -0,0 +1,7 @@ +#include "hello_world.hh" + +int main(int argc, char **argv) +{ + theFunctionToCall(argv[0]); + return 0; +} \ No newline at end of file diff --git a/mediapipe/examples/desktop/hello_world/hello_world.cc b/mediapipe/examples/desktop/hello_world/hello_world.cc index fde821b51..881f5163c 100644 --- a/mediapipe/examples/desktop/hello_world/hello_world.cc +++ b/mediapipe/examples/desktop/hello_world/hello_world.cc @@ -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(R"pb( + mediapipe::CalculatorGraphConfig config = + mediapipe::ParseTextProtoOrDie(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("Hello World!").At(Timestamp(i)))); + "in", mediapipe::MakePacket("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(); } 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()); } + + diff --git a/mediapipe/examples/desktop/hello_world/hello_world.hh b/mediapipe/examples/desktop/hello_world/hello_world.hh new file mode 100644 index 000000000..25c7ae0ab --- /dev/null +++ b/mediapipe/examples/desktop/hello_world/hello_world.hh @@ -0,0 +1,3 @@ +#pragma once + +void theFunctionToCall(const char* argv0);