文章标题 opencv中视频的读取和显示以及色彩的转换

本文基于VS2013和opencv所写

这里写代码片#include<iostream>
#include"opencv2/imgproc/imgproc.hpp"
#include"opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
/*int main()
{ 
    VideoCapture capture("fighting.avi");
    VideoWriter Writer;
    Writer.open("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(640, 480), 1);
    if (!capture.isOpened())
        cout << "failed!" << endl;
    //long totalframe = capture.get(CV_CAP_PROP_FRAME_COUNT);
    //cout << "总共的帧数:"<<totalframe<< endl;
    //bool stop = false;
    Mat frame;
    while (capture.read(frame))
    {
        //capture >> frame;
        //cout << "failed!!" << endl;
        imshow("showing", frame);
        Writer << frame;
        waitKey(1);
    }
    return 0;
}*/


void main()
{
    VideoCapture capture("fighting.avi");
    VideoWriter writer;
    double rate = capture.get(CV_CAP_PROP_FPS);//帧率
    Size videoSize(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT));//视频的宽和高
    writer.open("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), rate, videoSize,0);//1默认保存彩色图,0则不默认
    Mat frame,gray;
    //while (capture.isOpened())
//  {
    //  capture >> frame;
    while (capture.read(frame))
    {
        Mat gray;
        cvtColor(frame, gray, CV_RGB2GRAY);
        writer<<gray;
        imshow("video", frame);
        imshow("gray", gray);
        waitKey(20);
    }
}

同样的颜色转换可以依照灰度变化来做。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值