ตรวจสอบว่าคุณมีเฟรมเวิร์ก 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
ใช้กราฟ MediaPipe อย่างง่ายในองค์ประกอบ ฟังก์ชันPrintHelloWorld()
ที่กำหนดไว้ในโปรโตคอล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" } )");
คุณสามารถดูภาพกราฟนี้ได้โดยใช้ MediaPipe Visualizer โดยการวาง เนื้อหา CalculatorGraphConfig ด้านล่างลงใน 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" }
กราฟนี้ประกอบด้วยสตรีมอินพุตกราฟ 1 รายการ (
in
) และสตรีมเอาต์พุตกราฟ 1 รายการ (out
) และPassThroughCalculator
2 เครื่องเชื่อมต่อแบบต่อเนื่องก่อนที่จะเรียกใช้กราฟ ออบเจ็กต์
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({}));
จากนั้นตัวอย่างจะสร้างแพ็กเก็ต 10 แพ็กเก็ต (แต่ละแพ็กเก็ตจะมีสตริง " Hello ทั่วโลก!" ที่มีค่าการประทับเวลาตั้งแต่ 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"));
จากออบเจ็กต์
OutputStreamPoller
ตัวอย่างจะดึงข้อมูลทั้ง 10 รายการ แพ็กเก็ตจากสตรีมเอาต์พุตจะนำเนื้อหาสตริงออกจากแต่ละแพ็กเก็ต และพิมพ์ไปยังบันทึกเอาต์พุตmediapipe::Packet packet; while (poller.Next(&packet)) { LOG(INFO) << packet.Get<string>(); }
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2024-09-05 UTC
[{
"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":"อื่นๆ"
}]
{"lastModified": "\u0e2d\u0e31\u0e1b\u0e40\u0e14\u0e15\u0e25\u0e48\u0e32\u0e2a\u0e38\u0e14 2024-09-05 UTC"}
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2024-09-05 UTC"],[],[]]