ตรวจสอบว่าคุณมีเฟรมเวิร์ก 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 World!" ที่มีค่าการประทับเวลาตั้งแต่ 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-05-14 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":"อื่นๆ"
}]