Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I have solved this problem. It occurred to me that by using method 2 the first frame got from the external camera might be blank while the others are normal, so I add something to the code:

include < opencv2\core\core.hpp >

#include < opencv2\highgui\highgui.hpp >
#include < iostream >
using namespace cv;
using namespace std;
int main()
{
char c;
int i = 0;
VideoCapture inputVideo(0); //0为外部摄像头的ID,1为笔记本内置摄像头的ID
Mat src;
for(;;)
{
inputVideo >> src;
if(src.empty() & i > 1) return 1;
if(i > 1) imshow("input",src);
i ++; c = waitKey(10);
if (c == 27) break;
}
return 0;
}

I have solved this problem. It occurred to me that by using method 2 the first frame got from the external camera might be blank while the others are normal, so I add something to the code:

include #include < opencv2\core\core.hpp >

#include < opencv2\highgui\highgui.hpp >
#include < iostream >
using namespace cv;
using namespace std;
int main()
{
char c;
int i = 0;
VideoCapture inputVideo(0); //0为外部摄像头的ID,1为笔记本内置摄像头的ID
Mat src;
for(;;)
{
inputVideo >> src;
if(src.empty() & i > 1) return 1;
if(i > 1) imshow("input",src);
i ++; c = waitKey(10);
if (c == 27) break;
}
return 0;
}