Hello to all, i need to develop an GUI window that capture video from web cam and display it to Qt main window but unfortunately it only display 1 frame image and not continuous video.

Qt Code:
  1. OpenCVQT::OpenCVQT(QWidget *parent, Qt::WFlags flags)
  2. : QMainWindow(parent, flags)
  3.  
  4. {
  5. ui.setupUi(this);
  6.  
  7. myLabel = new QLabel("Fuckasdasd");
  8. mainLayout = new QVBoxLayout;
  9.  
  10. mainLayout->addWidget(myLabel);
  11.  
  12. mainWgt = new QWidget(this);
  13.  
  14. mainWgt->setLayout(mainLayout);
  15. this->setCentralWidget(mainWgt);
  16.  
  17.  
  18. camMenu = menuBar()->addMenu(tr("Web Camera"));
  19. webCamAct = new QAction(tr("Start Web Camera"), this );
  20. camMenu->addAction(webCamAct);
  21. connect(webCamAct, SIGNAL(triggered()), this,
  22. SLOT(WebCamSlot() ));
  23.  
  24. myCamThread = new cameraThread();
  25.  
  26. }
  27. // =============================================
  28. OpenCVQT::~OpenCVQT()
  29. {
  30. }
  31. // =============================================
  32. QLabel*& OpenCVQT::getLabel()
  33. {
  34. return myLabel;
  35. }
  36.  
  37. void OpenCVQT::WebCamSlot()
  38. {
  39. myCamThread->run();
  40. }
  41.  
  42. class cameraThread : public QThread
  43. {
  44. public:
  45. cameraThread();
  46. ~cameraThread();
  47.  
  48. void run();
  49. void StreamCamera();
  50. void ConvertImage();
  51. void CreateQImage();
  52.  
  53. private:
  54. CvCapture* myCaptureHandler;
  55. IplImage* myOriginalIplImage, *myRGBIplImage;
  56.  
  57. QImage myQImage;
  58. uchar* ImageData;
  59.  
  60. };
  61.  
  62. cameraThread::cameraThread()
  63. : myCaptureHandler(),
  64. myOriginalIplImage(&IplImage() ),
  65. myRGBIplImage(&IplImage() ),
  66. myQImage(QImage()),
  67. ImageData()
  68. {
  69. myCaptureHandler = cvCreateCameraCapture(0);
  70. myOriginalIplImage = cvCreateImage(cvSize(320, 240),
  71. IPL_DEPTH_8U, 3);
  72.  
  73. myRGBIplImage = cvCreateImage(cvSize(320,240),
  74. IPL_DEPTH_8U, 3 );
  75.  
  76. }
  77. // =============================================
  78. cameraThread::~cameraThread()
  79. {
  80. }
  81. // =============================================
  82. void cameraThread::run()
  83. {
  84. StreamCamera();
  85. exec();
  86. }
  87. // =============================================
  88. void cameraThread::StreamCamera()
  89. {
  90. myOriginalIplImage = cvQueryFrame(myCaptureHandler);
  91.  
  92. ConvertImage();
  93. CreateQImage();
  94.  
  95. //resize(myRGBIplImage->width, myRGBIplImage->height);
  96. (OpenCVQT::myLabel)->setPixmap(QPixmap::fromImage(myQImage) );
  97.  
  98.  
  99. }
  100. // =============================================
  101. void cameraThread::ConvertImage()
  102. {
  103. cvCvtColor(myOriginalIplImage,
  104. myRGBIplImage, CV_BGR2RGB);
  105.  
  106. if (!myRGBIplImage)
  107. {
  108. errMsg->showMessage("Error Convert Image");
  109. }
  110. else
  111. {
  112. ImageData = (uchar*) myRGBIplImage->imageData;
  113. }
  114.  
  115. }
  116. // =============================================
  117. void cameraThread::CreateQImage()
  118. {
  119. myQImage = QImage(ImageData,
  120. myRGBIplImage->width, myRGBIplImage->height,
  121. myRGBIplImage->widthStep,
  122. QImage::Format_RGB888);
  123. }
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. void cameraThread::run()
  2. {
  3. StreamCamera();
  4. exec();
  5. }
To copy to clipboard, switch view to plain text mode 

I need the streamCamera() to be continuous running while main window is running too.

Please help.

Thanks.