title: OpenCV Returning error message when webcam is not connected
body: <p>I am using OpenCV 3.3 with Python 2.7 on a Windows 10 PC. In one of my projects, I am connecting an external webcam to do some tracking. Everything works well as long as the webcam is connected. If the webcam is disconnected before the program runs/during the program, the program crashes. When I tried a dummy program to check what's going wrong, I noticed that the program crashes in the line where i call cv2.VideoCapture(0) itself. </p>
  
  <p><em>Code Snippet:</em></p>
  
  <p>cap=cv2.VideoCapture(0) -- this line is in the main program and if camera is not connected, the program crashes at this point</p>
  
  <p>--The below lines are inside a function and is called by the main program based on some other input</p>
  
  <blockquote>
    <p>r, a = cap.read()</p>
    
    <p>while not r:</p>
    
    <blockquote>
      <p>print 'Reconnect Camera'</p>
      
      <p>r , a = cap.read()</p>
    </blockquote>
    
    <p>print 'All Okay!'</p>
  </blockquote>
  
  <p>I put the while loop in there to prevent problems if the camera is disconnected after the cap=cv2.VideoCapture(0) but before cap.read() inside the function. This also does not do the work as 'r' value becomes true in the second iteration even after the camera disconnects. I have put a graph below to represent the behavior of 'r' with camera's connection.</p>
  
  <p><a href="https://i.stack.imgur.com/UzDYB.jpg" rel="nofollow noreferrer">a -> Camera is disconnected and 'r' goes to false;b -> Camera is still disconnected but 'r' is true now;c-> Camera is re-connected and 'r' goes to false;d -> Camera is connected, 'r' goes back to true but     </a></p>
  
  <p>I might be doing something wrong! How do I fix this?! Thanks in advance guys!</p>