Ask Your Question
0

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?

asked 2017-07-10 02:58:44 -0600

rohitmulay gravatar image

This is the code i used:

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

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.

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
1

answered 2017-07-10 03:16:15 -0600

berak gravatar image

updated 2017-07-10 03:17:59 -0600

please use cv::cvtColor (c++ api) , not cvCvtColor (dead c-api)

btw, your next line:

 graymat.convertTo( Mat,CV_32F);

looks broken, too. what is Mat doing there ?

i guess, you wanted something like this:

Mat float_mat;
graymat.convertTo( float_mat,CV_32F);
// do something with float_mat ..
edit flag offensive delete link more

Comments

Yes, that is exactly what i wanted, this is working fine! Thank You so much! @berak

rohitmulay gravatar imagerohitmulay ( 2017-07-10 03:33:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-10 02:58:44 -0600

Seen: 3,106 times

Last updated: Jul 10 '17