3

I have a GigaE camera and which gives me a greyscale image and I want to record it as a video and process it later.

So as initial step I tried recording video using my webcam it worked and if i convert it into greyscale before writing it into video. I am not getting any video. My code is below

int main(int argc, char* argv[])
{

VideoCapture cap(0); 
VideoWriter writer;

if (!cap.isOpened())  
{
    cout << "not opened" << endl;
    return -1;
}

char* windowName = "Webcam Feed";
namedWindow(windowName, CV_WINDOW_AUTOSIZE); 


string filename = "D:\myVideo_greyscale.avi";
int fcc = CV_FOURCC('8', 'B', 'P', 'S');
int fps = 30;
Size frameSize(cap.get(CV_CAP_PROP_FRAME_WIDTH),cap.get(CV_CAP_PROP_FRAME_HEIGHT));
writer = VideoWriter(filename,-1,fps,frameSize);

if(!writer.isOpened())
{
    cout<<"Error not opened"<<endl;
    getchar();
    return -1;
}


while (1) 
{

    Mat frame;

    bool bSuccess = cap.read(frame); 

    if (!bSuccess) 
    {
        cout << "ERROR READING FRAME FROM CAMERA FEED" << endl;
        break;
    }
    cvtColor(frame, frame, CV_BGR2GRAY);
    writer.write(frame);
    imshow(windowName, frame); 
}

return 0;

}`

I used fcc has -1 tried all the possibilities none of them are able to record video. I also tried creating a grayscale video using opencv for fcc has CV_FOURCC('8','B','P','S') but it did not help me.

I get this error in debug after using the breakpointenter image description here

Community
  • 1
  • 1
Reddy2810
  • 312
  • 2
  • 17

1 Answers1

3

VideoWriter has an optional parameter which tells whether the video is grayscale or color. Default ist color = true. Try

bool isColor = false;
writer = VideoWriter(filename,-1,fps,frameSize, isColor);
Micka
  • 19,585
  • 4
  • 56
  • 74
  • Hey Micka, I have tried it doesnt work. I have used frame fcc has CV_FOURCC('D','I','V','3'); or Do you know any other specific codecs for for grayscale images – Reddy2810 Dec 21 '16 at 21:47
  • no idea, sorry. Is converting to "color" an option for you? cv::cvtColor (src, dst, CV_GRAY2BGR). – Micka Dec 21 '16 at 21:49
  • Hey it works .. but I does not work with my GigaE Pro camera – Reddy2810 Dec 21 '16 at 21:58
  • Hey, it works with OpenCV 2.4.11 But its doesnt work with OpenCV 3.0.0 and even the file is not written. – Reddy2810 Dec 23 '16 at 10:55
  • no idead sorry... does your program have access to the opencv_ffmpeg* dll file of the right openCV version? – Micka Dec 23 '16 at 11:00
  • Yes. I have the dll in bin path of openCV and refer to the screenshot I have added above and I have also tried including #include "opencv2/imgcodecs/imgcodecs.hpp" #include "opencv2/videoio/videoio.hpp" but it doesnt help – Reddy2810 Dec 23 '16 at 11:45