#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
int main(int argc, const char** argv)
{
VideoCapture cap;
cap.open(0);
if (!cap.isOpened())
return -1;
namedWindow("Video", 1);
for (;;)
{
Mat frame;
cap >> frame;
if (frame.empty())
return 0;
imshow("Video", frame);
if (waitKey(30) >= 0) break;
}
cap.release();
return 0;
}
可用于 大华USB相机程序
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
VideoCapture cap;
Mat readImage;
cap.open(0);
cap.set(CAP_PROP_FRAME_HEIGHT, 2048);
cap.set(CAP_PROP_FRAME_WIDTH, 2448);
if (!cap.isOpened())
return -1;
namedWindow("Output Window");
while (true)
{
if (!cap.read(readImage)) {
cout << "No frame" << endl;
waitKey(0);
}
imshow("Output Window", readImage);
if (waitKey(1) >= 0) break;
}
return 0;
}