opencv 视频截图并保存

2019-07-16  本文已影响0人  Caiaolun
    /*************************************************************************
    * 视频截图并保存   https://docs.opencv.org/3.1.0/d8/dfe/classcv_1_1VideoCapture.html
    *************************************************************************/
    VideoCapture capture;
    capture.open("../../bin/data/Video.avi");

    if (!capture.isOpened())  // check if we succeeded
        return -1;
    Mat edges;
    namedWindow("edges", 1);

    int i = 0;
    for (;;)
    {
        Mat frame;
        capture >> frame; // get a new frame from camera
        //cvtColor(frame, edges, COLOR_BGR2GRAY);
        //GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);
        //Canny(edges, edges, 0, 30, 3);
        Rect rect_plate(40, 30, 800, 400);
        edges = frame(rect_plate);
        imshow("edges", edges);

        char image_name[20];
        sprintf_s(image_name, "%d%s%s", i, "image截图", ".jpg");
        std::string str(image_name);

        imwrite("../../bin/data/" + str, edges);

        if (waitKey(300) >= 0) break;
        //i++;
    }
上一篇下一篇

猜你喜欢

热点阅读