From 29702bfd1173a986a98571e9bff49a0d586fcceb Mon Sep 17 00:00:00 2001 From: jario Date: Fri, 2 Feb 2024 23:16:49 +0800 Subject: [PATCH] fix camera cannot open continuously --- video_io/sv_video_base.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/video_io/sv_video_base.cpp b/video_io/sv_video_base.cpp index 168e358..60fdfa1 100644 --- a/video_io/sv_video_base.cpp +++ b/video_io/sv_video_base.cpp @@ -1173,6 +1173,7 @@ void CameraBase::openImpl() } void CameraBase::open(CameraType type, int id) { + this->release(); this->_type = type; this->_camera_id = id; @@ -1215,7 +1216,7 @@ bool CameraBase::read(cv::Mat& image) this->_is_updated = false; break; } - std::this_thread::sleep_for(std::chrono::milliseconds(20)); + std::this_thread::sleep_for(std::chrono::milliseconds(2)); n_try ++; } } @@ -1227,7 +1228,10 @@ bool CameraBase::read(cv::Mat& image) } void CameraBase::release() { - _cap.release(); + this->_is_running = false; + this->_is_updated = false; + if (this->_cap.isOpened()) + this->_cap.release(); }