如何将视频文件读取为灰度 [英] How to read in a video file as grayscale

查看:111
本文介绍了如何将视频文件读取为灰度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您读取图片时,您可以将其设为 0 ,将其强制为灰度。

  cv :: Mat img = cv :: imread(file,0); //保持灰度

视频有等效吗?


<



您需要查询框架并将其转换自己灰化。



使用C接口: http:// stackoverflow。 com / a / 3444370/176769



使用C ++界面:

  VideoCapture cap(0); 
if(!cap.isOpened())
{
//打印错误msg
return -1;
}

namedWindow(grey,1);

垫框架;
Mat gray;
for(;;)
{
cap>>帧;

cvtColor(frame,gray,CV_BGR2GRAY);

imshow(gray,gray);
if(waitKey(30)> = 0)
break;
}

return 0;


When you read in an image, there is a flag you can set to 0 to force it as grayscale.

cv::Mat img = cv::imread(file, 0); // keeps it grayscale

Is there an equivalent for videos?

解决方案

There's not.

You need to query the frames and convert them to grayscale yourself.

Using the C interface: http://stackoverflow.com/a/3444370/176769

With the C++ interface:

VideoCapture cap(0);
if (!cap.isOpened())
{
    // print error msg
    return -1;
}

namedWindow("gray",1);

Mat frame;
Mat gray;
for(;;)
{
    cap >> frame;

    cvtColor(frame, gray, CV_BGR2GRAY);

    imshow("gray", gray);
    if(waitKey(30) >= 0) 
        break;
}

return 0;

这篇关于如何将视频文件读取为灰度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆