From 9d197c26c311587a3cbd69ed2a1acd46c70b9928 Mon Sep 17 00:00:00 2001 From: taiji1985 Date: Mon, 16 Dec 2024 11:13:30 +0000 Subject: [PATCH] wait first frame result to avoid empty result while dual_buf is true. --- components/nn/include/maix_nn.hpp | 1 + components/nn/src/maix_nn.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/components/nn/include/maix_nn.hpp b/components/nn/include/maix_nn.hpp index 23c3adc7..11d15965 100644 --- a/components/nn/include/maix_nn.hpp +++ b/components/nn/include/maix_nn.hpp @@ -334,6 +334,7 @@ namespace maix::nn private: MUD _mud; NNBase *_impl; + bool wait_first; // wait result for first frame }; }; // namespace maix::nn diff --git a/components/nn/src/maix_nn.cpp b/components/nn/src/maix_nn.cpp index 79a7bf5a..b467bd26 100644 --- a/components/nn/src/maix_nn.cpp +++ b/components/nn/src/maix_nn.cpp @@ -107,6 +107,7 @@ namespace maix::nn NN::NN(const std::string &model_path, bool dual_buff) { + wait_first = dual_buff; // if dual_buff is true, wait first frame result _impl = nullptr; #if PLATFORM_MAIXCAM _impl = new NN_MaixCam(dual_buff); @@ -201,6 +202,10 @@ namespace maix::nn tensor::Tensors *NN::forward_image(image::Image &img, std::vector mean, std::vector scale, image::Fit fit, bool copy_result, bool dual_buff_wait) { + if(wait_first){ + wait_first = false; + dual_buff_wait = true; // wait first frame result , to avoid empty return + } return _impl->forward_image(img, mean, scale, fit, copy_result, dual_buff_wait); }