When you read in an image, there is a flag you can set to 0 to force it as grayscale.
0
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: 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;
1.4m articles
1.4m replys
5 comments
57.0k users