Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Opencv's image.empty() function not working

Below code works fine, until

 VideoCapture cap_cam1(0);
 Mat img_cam1;

while(true)
{
            cap_cam1 >> img_cam1;

            if (img_cam1.empty() || !cap_cam1.isOpened())
            {                               
                cap_cam1.release();  
                 break;                 
            }

            else {        
                 imshow("Live",img_cam1); 
                if (!img_cam1.isContinuous())
                   break;
                 img_cam1.empty();              
                 img_cam1.release();

                 if(waitKey(33)==27) break; 
            }
    }

USB camera is removed while program is running. After disconnecting USB camera i see a blank image, but program should stop because img_cam1.empty() is true and !cap_cam1.isOpened() is also true. for some reasons both are false! why is it? how to stop the program when USB camera is removed?