सभी को नमस्ते! C++ में

  1. पक्का करें कि आपके पास MediaPipe फ़्रेमवर्क का काम करने वाला वर्शन हो. इंस्टॉल करने के निर्देश देखें.

  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. hello world के उदाहरण में, PrintHelloWorld() फ़ंक्शन में एक सामान्य MediaPipe ग्राफ़ का इस्तेमाल किया गया है. इसकी जानकारी CalculatorGraphConfig प्रोटो में दी गई है.

    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"
        }
    

    इस ग्राफ़ में, एक ग्राफ़ इनपुट स्ट्रीम (in) और एक ग्राफ़ आउटपुट स्ट्रीम (out) और दो PassThroughCalculator क्रम से जुड़े हुए हैं.

    नमस्ते_वर्ल्ड ग्राफ़

  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. इसके बाद, उदाहरण 10 पैकेट बनाता है (हर पैकेट में एक स्ट्रिंग "नमस्ते वर्ल्ड!" शामिल होती है. टाइमस्टैंप वैल्यू 0, 1, ... 9 के बीच होती है. यह फ़ंक्शन MakePacket फ़ंक्शन का इस्तेमाल करके, हर पैकेट को 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"));
    
  6. इसके बाद, OutputStreamPoller ऑब्जेक्ट की मदद से, यह उदाहरण आउटपुट स्ट्रीम से सभी 10 पैकेट इकट्ठा करता है और हर पैकेट से स्ट्रिंग का कॉन्टेंट बाहर निकालता है और उसे आउटपुट लॉग में प्रिंट करता है.

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