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:osWhen 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:osThere'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;