Ask Your Question
0

Video Writer

asked 2017-06-14 03:34:07 -0600

louis89 gravatar image

I use below code for VideoWriter.when I capture a video file,this code product an AVI video.but When I use my web cam for video capturing,this code product video but that video don't show anything.why this happen and what can I do for solve it?

`using namespace cv; using namespace std;

int main(int argc, char* argv[]) { VideoCapture cap(0); // open the video camera no. 0

if (!cap.isOpened())  // if not success, exit program
{
    cout << "Cannot open the video cam" << endl;
    return -1;
}

Mat frame;
namedWindow("MyVideo", CV_WINDOW_AUTOSIZE);

VideoWriter writer;
writer.open("test.avi", -1 ,20 ,frame.size());

while (1)
{


    bool bSuccess = cap.read(frame); // read a new frame from video

    if (!bSuccess)
    {
        cout << "Cannot read a frame from video stream" << endl;
        break;
    }

           writer.write(frame);
    if (waitKey(30) == 27) 
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }
}

return 0;
edit retag flag offensive close merge delete

Comments

try waitkey(longer time)

jsxyhelu gravatar imagejsxyhelu ( 2017-06-14 09:56:15 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-06-15 08:07:15 -0600

matt27110 gravatar image

You show nothing, you created a window but you don't display the image. Just add : imshow("MyVideo", frame);

edit flag offensive delete link more

Comments

I forgot one thing : you must know your frame size before :

"writer.open("test.avi", -1 ,20 ,frame.size())"

Otherwise you can't record your video.

VideoWriter writer;
cap >> frame;
writer.open("test.avi", -1 ,20 ,frame.size());
matt27110 gravatar imagematt27110 ( 2017-06-15 08:20:47 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-14 03:34:07 -0600

Seen: 252 times

Last updated: Jun 15 '17