Opencv's image.empty() function not working

asked 2015-12-30 00:38:34 -0500

Prakash gravatar image

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?

edit retag flag offensive close merge delete

Comments

1

Try using the .read() function, instead of the operator. It returns true if it was successful in reading a new frame.

I'm not sure why it isn't working, but hopefully this can help.

Tetragramm gravatar imageTetragramm ( 2015-12-30 03:59:35 -0500 )edit

Thanks for your suggestion. but it didn't work.. tried grab & retrieve as well. its still the same

Prakash gravatar imagePrakash ( 2015-12-30 10:29:21 -0500 )edit