opencv打开摄像头,截取图像并保存 按下ESC退出程序
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
using namespace std;
int main()
{
cv::VideoCapture camera(0);
camera.set(CV_CAP_PROP_FRAME_WIDTH, 640);
camera.set(CV_CAP_PROP_FRAME_HEIGHT, 480);
if (!camera.isOpened())
{
return 1;
}
while (1)
{
cv::Mat3b frame0;
camera >> frame0;
IplImage img = IplImage(frame0); //装换格式
cvSaveImage("pic.jpg", &img); //保存
cv::imshow("Video0", frame0);
int c = cvWaitKey(20);
if (27 == char(c)) break;
}
return 0;
}