diff --git a/video_io/sv_video_base.cpp b/video_io/sv_video_base.cpp index 5586b9c..5f90ac2 100644 --- a/video_io/sv_video_base.cpp +++ b/video_io/sv_video_base.cpp @@ -1172,9 +1172,12 @@ void CameraBase::open(CameraType type, int id) if (this->_cap.isOpened()) { std::cout << "Camera opened!" << std::endl; - this->_is_running = true; - this->_tt = std::thread(&CameraBase::_run, this); - this->_tt.detach(); + if(type != CameraType::VIDEO) + { + this->_is_running = true; + this->_tt = std::thread(&CameraBase::_run, this); + this->_tt.detach(); + } } else if (type != CameraType::NONE) { @@ -1194,19 +1197,26 @@ bool CameraBase::read(cv::Mat& image) { if (this->_type != CameraType::NONE) { - int n_try = 0; - while (n_try < 5000) + if(this->_type == CameraType::VIDEO) { - if (this->_is_updated) - { - this->_is_updated = false; - this->_frame.copyTo(image); - break; - } - std::this_thread::sleep_for(std::chrono::milliseconds(20)); - n_try ++; + this->_cap >> image; } - } + else + { + int n_try = 0; + while (n_try < 5000) + { + if (this->_is_updated) + { + this->_is_updated = false; + this->_frame.copyTo(image); + break; + } + std::this_thread::sleep_for(std::chrono::milliseconds(20)); + n_try ++; + } + } + } if (image.cols == 0 || image.rows == 0) { throw std::runtime_error("SpireCV (101) Camera cannot OPEN, check CAMERA_ID!");