Ask Your Question

Revision history [back]

Second capture loop is wrong. you forgot some {. If you want to close a windows you have to use DestroyWindow. Close a capture is not close window

 VideoCapture cap;
if (!cap.open(0)) {
    return 0;
}
Mat frame;
for (;;)
{
    cap >> frame;
    if (frame.empty()) break; // end of video stream
    imshow("Smile! Press esc to take picture", frame);
    if (waitKey(1) == 27)
    {
        break; // stop capturing by pressing ESC 
    }
}

// the camera will be closed automatically upon exit
cap.release();


    VideoCapture cap2;
if (!cap2.open(0))
{
    cout << "Cap isn't open. Terminating..." << endl;
    return -1;
}
cout << "Smile! Press esc to take picture" << endl;
for (;;)
{
    cap2 >> frame;
    if (frame.empty())
    {
        cout << "frame empty. terminating..." << endl;  break; // end of video stream

    }
    if (waitKey(1) == 27)
    {
        break; // stop capturing by pressing ESC 
    }
    imshow("Smile! :)", frame);
}

    cap2.release();

Second capture loop is wrong. you forgot some {. If you want to close a windows you have to use DestroyWindow. Close a capture is not close window

 VideoCapture cap;
if (!cap.open(0)) {
    return 0;
}
Mat frame;
for (;;)
{
    cap >> frame;
    if (frame.empty()) break; // end of video stream
    imshow("Smile! Press esc to take picture", frame);
    if (waitKey(1) == 27)
    {
        break; // stop capturing by pressing ESC 
    }
}

// the camera will be closed automatically upon exit
cap.release();


    VideoCapture cap2;
if (!cap2.open(0))
{
    cout << "Cap isn't open. Terminating..." << endl;
    return -1;
}
cout << "Smile! Press esc to take picture" << endl;
for (;;)
{
    cap2 >> frame;
    if (frame.empty())
    {
{ // ADD
        cout << "frame empty. terminating..." << endl;  break; // end of video stream

    }
}// ADD
    if (waitKey(1) == 27)
    {
        break; // stop capturing by pressing ESC 
    }
    imshow("Smile! :)", frame);
}

    cap2.release();

Second capture loop is wrong. you forgot some {. If you want to close a windows you have to use DestroyWindow. Close a capture is not close window

 VideoCapture cap;
if (!cap.open(0)) {
    return 0;
}
Mat frame;
for (;;)
{
    cap >> frame;
    if (frame.empty()) break; // end of video stream
    imshow("Smile! Press esc to take picture", frame);
    if (waitKey(1) == 27)
    {
        break; // stop capturing by pressing ESC 
    }
}

// the camera will be closed automatically upon exit
cap.release();


    VideoCapture cap2;
if (!cap2.open(0))
{
    cout << "Cap isn't open. Terminating..." << endl;
    return -1;
}
cout << "Smile! Press esc to take picture" << endl;
for (;;)
{
    cap2 >> frame;
    if (frame.empty())
    { // ADD
        cout << "frame empty. terminating..." << endl;  break; // end of video stream

    }// ADD
    if (waitKey(1) == 27)
    {
        break; // stop capturing by pressing ESC 
    }
    imshow("Smile! :)", frame);
}

    cap2.release();

Visual studio 2016 ? VS 2015 or VS2017 RC

Second capture loop is wrong. you forgot some {. If you want to close a windows you have to use DestroyWindow. Close a capture is not close window

 VideoCapture cap;
if (!cap.open(0)) {
    return 0;
}
Mat frame;
for (;;)
{
    cap >> frame;
    if (frame.empty()) break; // end of video stream
    imshow("Smile! Press esc to take picture", frame);
    if (waitKey(1) == 27)
    {
        break; // stop capturing by pressing ESC 
    }
}

// the camera will be closed automatically upon exit
cap.release();


    VideoCapture cap2;
if (!cap2.open(0))
{
    cout << "Cap isn't open. Terminating..." << endl;
    return -1;
}
cout << "Smile! Press esc to take picture" << endl;
for (;;)
{
    cap2 >> frame;
    if (frame.empty())
    { // ADD
        cout << "frame empty. terminating..." << endl;  break; // end of video stream

    }// ADD
    imshow("Smile! :)", frame);
    if (waitKey(1) == 27)
27) // waitkey after imshow to avoid a lag  (small)
    {
        break; // stop capturing by pressing ESC 
    }
    imshow("Smile! :)", frame);
}

    cap2.release();

Visual studio 2016 ? VS 2015 or VS2017 RC