diff --git a/reconstruct/src/main.cpp b/reconstruct/src/main.cpp index 51c346da25e0f367247cc33234a63bbac957e251..6145a65a3689b1710574d12f39d08498a9126137 100644 --- a/reconstruct/src/main.cpp +++ b/reconstruct/src/main.cpp @@ -83,6 +83,8 @@ static void run() { while (disp.active()) { Mat idepth; + + net.broadcast("grab"); unique_lock<mutex> lk(m); if (depth.cols > 0) { diff --git a/vision/src/main.cpp b/vision/src/main.cpp index 70edfd239e89ab02e8e7ce972136637488ed0d2f..69551262744c000777073b1f624a8696baee62f8 100644 --- a/vision/src/main.cpp +++ b/vision/src/main.cpp @@ -108,11 +108,24 @@ static void run(const string &file) { return buf; }); + Mat l, r, disp; + bool grabbed = false; + mutex datam; + condition_variable datacv; + + net.bind("grab", [&calibrate,&l,&r,&datam,&datacv,&grabbed]() -> void { + // LOG(INFO) << "GRAB"; + unique_lock<mutex> datalk(datam); + if (grabbed) return; + calibrate.rectified(l, r); + grabbed = true; + datacv.notify_one(); + }); + // Choose and configure disparity algorithm auto disparity = Disparity::create(config["disparity"]); if (!disparity) LOG(FATAL) << "Unknown disparity algorithm : " << config["disparity"]; - Mat l, r, disp; Mat pl, pdisp; vector<unsigned char> rgb_buf; vector<unsigned char> d_buf; @@ -132,9 +145,11 @@ static void run(const string &file) { // Pipeline for disparity pool.push([&](int id) { - auto start = std::chrono::high_resolution_clock::now(); // Read calibrated images. - calibrate.rectified(l, r); + //calibrate.rectified(l, r); + unique_lock<mutex> datalk(datam); + datacv.wait(datalk, [&grabbed](){ return grabbed; }); + grabbed = false; // Feed into sync buffer and network forward //sync->feed(ftl::LEFT, l, lsrc->getTimestamp()); @@ -144,7 +159,9 @@ static void run(const string &file) { //sync->get(ftl::LEFT, l); //sync->get(ftl::RIGHT, r); + auto start = std::chrono::high_resolution_clock::now(); disparity->compute(l, r, disp); + datalk.unlock(); unique_lock<mutex> lk(m); jobs++;