Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 600

I'm Trying to convert RGB video to Grayscale using OpenCV in C++, but i'm getting an error in my code. Can anyone help me with the code?

$
0
0
This is the code i used: #include "opencv2/highgui/highgui.hpp" #include #include using namespace cv; using namespace std; int main(int argc, char* argv[]) { VideoCapture cap("/home/rmulay17/Downloads/vpb.mp4"); // open the video file for reading if ( !cap.isOpened() ) // if not success, exit program { cout << "Cannot open the video file" << endl; return -1; } //cap.set(CV_CAP_PROP_POS_MSEC, 300); //start the video at 300ms double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video cout << "Frame per seconds : " << fps << endl; namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo" while(1) { cv::Mat frame; cv::Mat graymat; bool bSuccess = cap.read(frame); // read a new frame from video if (!bSuccess) //if not success, break loop { cout << "Cannot read the frame from video file" << endl; break; } cvCvtColor(frame,graymat,CV_BGR2GRAY); graymat.convertTo( Mat,CV_32F); imshow("MyVideobnw", graymat); imshow("MyVideo", frame); //show the frame in "MyVideo" window if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop { cout << "esc key is pressed by user" << endl; break; } } return 0; } This is the error I'm getting: > video.cpp: In function ‘int main(int, > char**)’: >video.cpp:38:46: error:> cannot convert ‘cv::Mat’ to ‘const > CvArr* {aka const void*}’ for argument >‘1’ to ‘void cvCvtColor(const CvArr*, > CvArr*, int)’ > cvCvtColor(frame,graymat,CV_BGR2GRAY);> ^ video.cpp:39:32: error: expected> primary-expression before ‘,’ token > graymat.convertTo( Mat,CV_32F); **Somebody please help me and give me an solution to this problem!** Thank You in advance.

Viewing all articles
Browse latest Browse all 600

Trending Articles