zoukankan      html  css  js  c++  java
  • C++视频读取与视频保存

        VideoCapture cap("E:\122.avi");    
        //计算视频帧数
        int VedioFPS = cap.get(CV_CAP_PROP_FPS);
        //cout << "视频帧率" << VedioFPS << endl;
        // 保存视频
        VideoWriter writer("LoadBeltTear.mp4", CV_FOURCC('M', 'J', 'P', 'G'), VedioFPS, Size(ROI_Weidth, ROI_Height * 2));
        if (!cap.isOpened())
        {
            cout << "Error opening video stream or file" << endl;
            return -1;
        }
        Mat frame;
        while (1) {
            // Capture frame-by-frame
            cap >> frame;
            // If the frame is empty, break immediately
            if (frame.empty()) break;
            if (frame.channels() == 3) cvtColor(frame, frame, CV_RGB2GRAY);
                    //******************
                    // 处理图像
            //******************
            //在图像上打上标记
            cvtColor(frame(roi_rect), ROIimg, CV_GRAY2RGB);
            std::string str2 = "OriginalImage";
            cv::putText(ROIimg, str2, Point(roi_rect.width *0.5 - 20, 20), cv::FONT_HERSHEY_SIMPLEX, 0.3, cv::Scalar(0, 255, 255), 1);
            cv::putText(ROIimg, "LoadBelt", Point(0, 20), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 255, 255), 1);
            std::string str1 = "ImageProcessing";
            cv::putText(tempImg, str1, Point(roi_rect.width *0.5 - 30, 20), cv::FONT_HERSHEY_SIMPLEX, 0.3, cv::Scalar(0, 255, 255), 1);
            vconcat(ROIimg, tempImg, conbine);
            imshow("拼接", conbine);
            writer << conbine;
            char c = (char)waitKey(1);
            if (c == 27)
                break;
        }
        cap.release();
        destroyAllWindows();            

    从视频文件中读取视频,对单帧图像进行相关处理,将处理后的图像整理成视频

  • 相关阅读:
    [LeetCode] Strobogrammatic Number III
    [LeetCode] Strobogrammatic Number II
    [Codeforces 1253E] Antenna Coverage
    [CodeForces 466C] Number of Ways
    UVa 806 四分树
    Uva 1572 自组合
    UVa Sculpture(离散化 floodfill)
    Uva 4916 Selling Cells(随机算法)
    UvaLive 4863 Balloons(贪心)
    UvaLive 4872 Underground Cables (最小生成树)
  • 原文地址:https://www.cnblogs.com/wangxiaobei2019/p/11968789.html
Copyright © 2011-2022 走看看