OpenCV摄像头读取图像时第一次读取总失败的问题
开发平台是Qt5.21+OpneCV2.4.8,使用的是C++的接口,使用Camera.isOpened()打开摄像头成功,但是使用Camera.read()读取图像失败...
开发平台是Qt5.21+OpneCV2.4.8,使用的是C++的接口,使用Camera.isOpened()打开摄像头成功,但是使用Camera.read()读取图像失败,摄像头指示灯已经打开,反复调试后发现Camera.read()函数第一次调用的时候失败,第二次以后才成功。虽然我写程序时候可以调两次再开始显示图像。还是想问问各位大牛,为什么第一次会失败~!
cv::VideoCapture Camera(0);
if (!Camera.isOpened())
{
cout<<"camera is not opened!\n";
return -1;
}
else cout<<"camera is opened!\n";
cv::Mat img;
while (cv::waitKey(33) != 27)
{
bool isRead = false;
isRead = Camera.read(img);
if (!isRead)
{
cout<<"loading image!\n";
}
else cv::imshow("video", img);
}
Camera.releas 展开
cv::VideoCapture Camera(0);
if (!Camera.isOpened())
{
cout<<"camera is not opened!\n";
return -1;
}
else cout<<"camera is opened!\n";
cv::Mat img;
while (cv::waitKey(33) != 27)
{
bool isRead = false;
isRead = Camera.read(img);
if (!isRead)
{
cout<<"loading image!\n";
}
else cv::imshow("video", img);
}
Camera.releas 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询