\tutorial_code\HighGUI

来源:互联网 发布:网络写手培训 编辑:程序博客网 时间:2024/05/14 16:54


选择逃避


是因为

不知该如何面对





【22】读取和写入视频

直接给源码 = =



#include "opencv2/highgui/highgui.hpp"

#include <iostream>
#include <iomanip>

using namespace cv;
using namespace std;

int main( int argc, const char** argv )
{
        Mat image,frame;

        VideoCapture cap;
        cap.open(0);
//0是设备号 当然,如果你有多个设备的话技巧就是传入-1然后自己选择
        
        if( !cap.isOpened() )
        {
                cout << "***Could not initialize capturing...***\n";
                return -1;
        }

        int frameW = cap.get(CV_CAP_PROP_FRAME_WIDTH);
        int frameH = cap.get(CV_CAP_PROP_FRAME_HEIGHT);

        VideoWriter outputVideo;

        //outputVideo.open("out.avi",CV_FOURCC('X','V','I','D'),10,Size(frameW,frameH),true);
//这里的xivd就是选择xivd编码器进行编码
//当然首先你要安装XVIDhttp://www.xvidmovies.com/codec/
//技巧又出现了,传入参数-1他会弹出对话框然你选系统已经装有的编码器
//当然 我还是强烈建议你装一个XVID = = 当你别的编码器都不好使的时候 你要记得这条啊

        outputVideo.open("out.avi",-1,10,Size(frameW,frameH),true);

        if( !outputVideo.isOpened() )
        {
                cout << "***Could not initialize outputVideo...***\n";
                return -1;
        }

        namedWindow( "Camera", 1);

        for(;;)
        {
                cap >> frame;

                if( frame.empty() )
                        break;

                frame.copyTo(image);

                imshow( "Camera", image );

                outputVideo<<image;

                char c = (char)waitKey(10);
                if( c == 27 )
                        break;
        }
        cap.release();
        return 0;
}

为什么没有运行图片?!
我才不要给真相你们!!