title: Display camera stream in a QLabel
body: <p>I want to use python OpenCV bindings to display webcam stream in a QLabel. I found some previous posts here:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/8701781/updating-qlabel-in-non-gui-thread-continuously?rq=1">updating QLabel in non-GUI thread continuously</a></li>
  <li><a href="https://stackoverflow.com/questions/11401115/displaying-a-video-stream-in-qlabel-with-pyside">Displaying a video stream in QLabel with PySide</a></li>
  </ul>
  
  <p>In the beginning I tried a simple "while" loop:</p>
  
  <pre><code>def onRun(self):
      self.playing = True
      capture = cv2.VideoCapture(0)
      while self.playing:
          _, data = capture.read()
          data = cv2.cvtColor(data, cv2.cv.CV_BGR2RGB)
          qImage = QtGui.QImage(data, data.shape[1], data.shape[0], 
              QtGui.QImage.Format_RGB888)
          self.lblImage.setPixmap(QtGui.QPixmap.fromImage(qImage))
          self.lblImage.adjustSize()
          time.sleep(0.02)
  </code></pre>
  
  <p>But I met with a "white-window" problem. I found that proper way to solve this is to create a new thread. My question is: what is it all about new thread? should I create QThread or something? And what is it signal/slot emitting in a thread? </p>
  
  <p>I've never used threads so it's totally new thing to me.</p>