title: For OpenCV, my Python code can display webcam, but my C++ cannot
body: <p>I'm on Windows 10 64-bit with OpenCV 3.3.1,Python 3,the latest C++, and Visual Studio 2017.</p>
  
  <p>Here is my Python 3 code that properly displays my webcam:</p>
  
  <pre><code>import numpy as np
  import cv2
  
  cap = cv2.VideoCapture(0)
  
  ret, last_frame = cap.read()
  row, col, ch = last_frame.shape
  
  if last_frame is None:
      exit()
  
  while(cap.isOpened()):
      ret, frame = cap.read()
  
      if frame is None:
          exit()
  
      cv2.imshow('frame', frame)
  
      if cv2.waitKey(33) == ord('q'):
          break
  
  cap.release()
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>Below is a C++ code that does not display my webcam. This code only displays a grey frame:</p>
  
  <pre><code>#include "opencv2/opencv.hpp"
  using namespace cv;
  
  #include &lt;iostream&gt;
  using namespace std;
  
  int main()
  {
      VideoCapture cap(0); // 1st device, DSHOW
      while (cap.isOpened())
      {
          Mat frame;
          cap &gt;&gt; frame;
          imshow("ocv", frame);
  
          int k = waitKey(10);
          if (k == 27) break;
      }
      return 0;
  }
  </code></pre>
  
  <p>Can someone please help me with this issue? I tried modifying my C++ to VideoCapture cap(1), VideoCapture cap(2), VideoCapture cap(3), and VideoCapture cap but I still get no live video from my webcam.</p>
  
  <p>Screenshot of my running Python Code:
  <a href="https://i.stack.imgur.com/KtQJK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KtQJK.png" alt="Python Code"></a></p>
  
  <p>Screenshot of my running C++ Code:
  <a href="https://i.stack.imgur.com/hkR6O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hkR6O.png" alt="Cpp Code"></a></p>