在调用外部摄像头时,会出现无法读取摄像头数据的现象,在打开摄像时加上Sleep()函数,就能解决该问题。
// opencvtest.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <time.h>
#include<windows.h>
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
VideoCapture capture(2);
Sleep(1000);
while (1)
{
Mat frame;
capture >> frame;
waitKey(300);
imshow("读取视频", frame);
waitKey(30);
}
system("pause");
return 0;
}
本文介绍了一种解决调用外部摄像头时无法读取数据的方法。通过在打开摄像头后加入Sleep(1000)函数,确保了摄像头初始化完成,从而避免了数据读取失败的问题。示例代码使用了OpenCV进行视频捕捉。
2752





