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

1 Answer 1

4

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);
Sign up to request clarification or add additional context in comments.

6 Comments

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
no idea, sorry. Is converting to "color" an option for you? cv::cvtColor (src, dst, CV_GRAY2BGR).
Hey it works .. but I does not work with my GigaE Pro camera
Hey, it works with OpenCV 2.4.11 But its doesnt work with OpenCV 3.0.0 and even the file is not written.
no idead sorry... does your program have access to the opencv_ffmpeg* dll file of the right openCV version?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.