optimize image get

This commit is contained in:
AiYangSky 2023-09-19 17:34:46 +08:00
parent d51037be4f
commit 07f7cac7b7
2 changed files with 22 additions and 22 deletions

View File

@ -8,9 +8,9 @@ int main(int argc, char *argv[])
{ {
sv::Camera cap; sv::Camera cap;
cap.setIp(argv[1]); cap.setIp(argv[1]);
cap.open(sv::CameraType::G1);
cap.setWH(1280, 720); cap.setWH(1280, 720);
cap.setFps(30); cap.setFps(120);
cap.open(sv::CameraType::G1);
cv::Mat img; cv::Mat img;

View File

@ -1134,26 +1134,26 @@ bool CameraBase::read(cv::Mat& image)
} }
return ret; return ret;
if (this->_type == CameraType::WEBCAM || this->_type == CameraType::G1 || this->_type == CameraType::MIPI) // if (this->_type == CameraType::WEBCAM || this->_type == CameraType::G1 || this->_type == CameraType::MIPI)
{ // {
int n_try = 0; // int n_try = 0;
while (n_try < 5000) // while (n_try < 5000)
{ // {
if (this->_is_updated) // if (this->_is_updated)
{ // {
this->_is_updated = false; // this->_is_updated = false;
this->_frame.copyTo(image); // this->_frame.copyTo(image);
break; // break;
} // }
std::this_thread::sleep_for(std::chrono::milliseconds(20)); // std::this_thread::sleep_for(std::chrono::milliseconds(20));
n_try ++; // n_try ++;
} // }
} // }
if (image.cols == 0 || image.rows == 0) // if (image.cols == 0 || image.rows == 0)
{ // {
throw std::runtime_error("SpireCV (101) Camera cannot OPEN, check CAMERA_ID!"); // throw std::runtime_error("SpireCV (101) Camera cannot OPEN, check CAMERA_ID!");
} // }
return image.cols > 0 && image.rows > 0; // return image.cols > 0 && image.rows > 0;
} }
void CameraBase::release() void CameraBase::release()
{ {