#include <opencv2/>
using namespace std;
int main()
{
//initialize and allocate memory to load the video stream from camera
cv::VideoCapture camera0(1);
camera0.set(CV_CAP_PROP_FRAME_WIDTH,320);
camera0.set(CV_CAP_PROP_FRAME_HEIGHT,240);
cv::VideoCapture camera1(0);
(CV_CAP_PROP_FRAME_WIDTH,320);
(CV_CAP_PROP_FRAME_HEIGHT,240);
if( !camera0.isOpened() )
return 1;
if( !() )
return 1;
while(true)
{
//grab and retrieve each frames of the video sequentially
cv::Mat frame0;
camera0 >> frame0;
cv::Mat frame1;
camera1 >> frame1;
cv::imshow("left", frame0);
cv::imshow("right", frame1);
// std::cout << () << std::endl;
//wait for 40 milliseconds
int c = cvWaitKey(40);
//exit the loop if user press "Esc" key (ASCII value of "Esc" is 27)
if(27 == char(c))
break;
}
return 0;
}
编译之后直接运行即可,若有两个以上摄像头,只需要修改摄像头对应参数即可。