Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

c++ - How to read in a video file as grayscale

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There's not.

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

Using the C interface: https://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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...