title: Cannot open camera with OpenCV in Linux
body: <p>I am using OpenCV 2.4.3 on linux now. And in my /dev/ there is a device called video0 that is working fine with cheese.</p>
  
  <p>Currently I am using the following code to try to access the camera. This code is written in qtcreator and compiled with qmake to include the necessary library. As for the OpenCV library, I downloaded the source code and compiled it according to the instruction on the website on my machine.</p>
  
  <p>++main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;opencv2/opencv.hpp&gt;
  #include &lt;cstdlib&gt;
  
  int main(int argc, char** argv) {
      int cameraNumber = 0;
      if (argc&gt;1)
          cameraNumber = atoi(argv[1]);
      cv::VideoCapture camera;
      camera.open(cameraNumber);
      if(!camera.isOpened()) {
          std::cerr&lt;&lt;"Error opening camera"&lt;&lt;std::endl;
          exit(1);
      }
      camera.set(CV_CAP_PROP_FRAME_WIDTH,640);
      camera.set(CV_CAP_PROP_FRAME_HEIGHT,480);
  
      while(true) {
          cv::Mat cameraFrame;
          camera&gt;&gt;cameraFrame;
          if (cameraFrame.empty()){
              std::cerr&lt;&lt;"No frame read from camera"&lt;&lt;std::endl;
              exit(1);
          }
          imshow("Camera",cameraFrame);
  
          char keypress = cv::waitKey(20);
          if (keypress==27) {
              break;
          }
      }
      return 0;
  }
  </code></pre>
  
  <hr>
  
  <p>++test.pro</p>
  
  <pre><code>TEMPLATE = app
  CONFIG += console
  CONFIG -= app_bundle
  CONFIG -= qt
  
  SOURCES += main.cpp
  
  win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/release/ -lopencv_core
  else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/debug/ -lopencv_core
  else:unix: LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/ -lopencv_core
  
  win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/release/ -lopencv_highgui
  else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/debug/ -lopencv_highgui
  else:unix: LIBS += -L$$PWD/../../../../opt/OpenCV-2.4.3/lib/ -lopencv_highgui
  
  INCLUDEPATH += $$PWD/../../../../opt/OpenCV-2.4.3/include
  DEPENDPATH += $$PWD/../../../../opt/OpenCV-2.4.3/include
  </code></pre>
  
  <p>However, when running the program it will output <code>Error opening camera</code> and exit, which means the camera is not opened successfully. I have been googled a while and didn't find any possible solutions to solve this issue. Could some one give me some advice on how to solve this problem?  Thanks!</p>