title: How to efficiently display OpenCV video in Qt?
body: <p>I'm capturing multiple streams from ip cameras with the help of OpenCV. When i try to display these stream from an OpenCV window(<code>cv::namedWindow(...)</code>), it works without any problem (i have tried up to 4 streams so far).</p>
  
  <p>The problem arises when i try to show these streams inside a Qt widget. Since the capturing is done in another thread, i have to use the signal slot mechanism in order to update the QWidget(which is in main thread).</p>
  
  <p>Basically, i emit the newly captured frame from the capture thread and a slot in the GUI thread catches it. When i open 4 streams, i can not display the videos smoothly like before.</p>
  
  <p>Here is the emitter :</p>
  
  <pre><code>void capture::start_process() {
      m_enable = true;
      cv::Mat frame;
  
      while(m_enable) {
          if (!m_video_handle-&gt;read(frame)) {
              break;
          }
          cv::cvtColor(frame, frame,CV_BGR2RGB);
  
          qDebug() &lt;&lt; "FRAME : " &lt;&lt; frame.data;
  
          emit image_ready(QImage(frame.data, frame.cols, frame.rows, frame.step, QImage::Format_RGB888));
          cv::waitKey(30);
      }
  }
  </code></pre>
  
  <p>This is my slot : </p>
  
  <pre><code>void widget::set_image(QImage image) {
      img = image;
      qDebug() &lt;&lt; "PARAMETER IMAGE: " &lt;&lt; image.scanLine(0);
      qDebug() &lt;&lt; "MEMBER IMAGE: " &lt;&lt; img.scanLine(0);
  }
  </code></pre>
  
  <p>The problem seems like the overhead of copying QImages continuously. Although QImage uses implicit sharing, when i compare the data pointers of images via <code>qDebug()</code> messages, i see different addresses.</p>
  
  <p>1- Is there any way to embed OpenCV window directly into QWidget ?</p>
  
  <p>2- What is the most efficient way to handle displaying multiple videos? For example, how video management systems show up to 32 cameras in the same time ?</p>
  
  <p>3- What must be the way to go ?</p>