Compare commits

...

1 Commits

Author SHA1 Message Date
AiYangSky f2a62e4126 fix video file read 2023-12-26 17:02:42 +08:00
1 changed files with 24 additions and 14 deletions

View File

@ -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!");