代码:

#include

#include

using namespace cv;

using namespace std;

int main()

{

//【1】从摄像头读入视频

    VideoCapture capture(1);

    if (!capture.isOpened())

{

cout<< "open camera fail ..." << endl;

        return -1;

    }

capture.set(CAP_PROP_FRAME_WIDTH, 640);

    capture.set(CAP_PROP_FRAME_HEIGHT, 480);

    char filename[200];

    int count =0;

    //【2】循环显示每一帧

    Mat frame;  //定义一个Mat变量,用于存储每一帧的图像

    char key;

    while (true)

{

//读入图像

        capture>> frame;  //读取当前帧

        key = waitKey(20);

        if(key ==27)//esc键退出

            break;

        if(key ==32)//空格键保存图像

        {

sprintf(filename, "Picture_%d.png", ++count);

            imwrite(filename, frame);//

            namedWindow("[frame]", WINDOW_NORMAL);

            imshow("[frame]",frame);

        }

imshow("image", frame);  //显示当前帧

    }

return 0;

}

 

OpenCV:打开摄像头获取视频流

 

 

 

 

 

 

 

 

相关文章:

  • 2021-11-27
  • 2021-10-31
  • 2021-12-15
  • 2021-11-18
  • 2021-12-25
  • 2021-06-19
  • 2021-12-06
  • 2021-07-29
猜你喜欢
  • 2021-12-21
  • 2021-08-07
  • 2021-09-29
  • 2022-01-30
  • 2021-07-30
  • 2022-01-20
  • 2021-10-01
相关资源
相似解决方案