From 0d3ba503e480be6ce721f1473e966842ec036ea1 Mon Sep 17 00:00:00 2001 From: AiYangSky <1732570904@qq.com> Date: Tue, 26 Sep 2023 03:25:00 +0000 Subject: [PATCH] =?UTF-8?q?=E7=A8=B3=E5=AE=9A=E8=BE=93=E5=87=BA=E5=B8=A7?= =?UTF-8?q?=E7=8E=87=EF=BC=8C=E8=B0=83=E6=95=B4=E5=BC=82=E5=B8=B8=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: AiYangSky <1732570904@qq.com> --- video_io/sv_video_base.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/video_io/sv_video_base.cpp b/video_io/sv_video_base.cpp index aaf716a..e98941f 100644 --- a/video_io/sv_video_base.cpp +++ b/video_io/sv_video_base.cpp @@ -1118,19 +1118,24 @@ void CameraBase::_run() } bool CameraBase::read(cv::Mat& image) { - bool ret = false; + bool ret = false; if (this->_type == CameraType::WEBCAM || this->_type == CameraType::G1 || this->_type == CameraType::MIPI) { + static int falseCount=0; std::lock_guard locker(this->_frame_mutex); - if(this->_frame_empty.wait_for(this->_frame_mutex,std::chrono::milliseconds(2000)) == std::cv_status::no_timeout) + if(this->_frame_empty.wait_for(this->_frame_mutex,std::chrono::milliseconds(10)) == std::cv_status::timeout) { - this->_frame.copyTo(image); - ret = true; + falseCount ++; + if(falseCount >= 1000) + { + throw std::runtime_error("SpireCV (101) Camera has offline, check CAMERA!"); + } } - else - { - throw std::runtime_error("SpireCV (101) Camera cannot OPEN, check CAMERA_ID!"); + else{ + falseCount = 0; } + this->_frame.copyTo(image); + ret = true; } return ret;