fix camera cannot open continuously

This commit is contained in:
jario 2024-02-02 23:16:49 +08:00
parent b52645c3a6
commit 29702bfd11
1 changed files with 6 additions and 2 deletions

View File

@ -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();
}