Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CMainWindow::CMainWindow(QWidget *parent)
- : QMainWindow(parent),
- m_CameraHandler(0),
- m_ImageWidget(0),
- m_ProcessedImageWidget(0),
- m_ImageProcessor(0)
- {
- //Setup GUI
- ui.setupUi(this);
- //Connect start menu to the CameraHandler startStop connection
- connect(ui.actionFrom_webcam,SIGNAL(triggered()),this,SLOT(startStopCamera()));
- //Setup Widgets and camera handler
- this->setupImageWidget();
- this->setupProcessedImageWidget();
- this->setupCameraHandler();
- m_ImageProcessor=new CImageDenoiserL2();
- //Connections to send images from the camera handler to the gui
- connect(m_CameraHandler,SIGNAL(sendFrame(QImage)),m_ImageWidget,SLOT(drawFrame(QImage)));
- connect(m_CameraHandler,SIGNAL(sendProcessedFrame(QImage)),m_ProcessedImageWidget,SLOT(drawFrame(QImage)));
- //Connection for L2 denoising parameters
- connect(ui.sliderTheta,SIGNAL(valueChanged(int)),m_ImageProcessor,SLOT(setTheta(int)));
- connect(ui.sliderMaxIter,SIGNAL(valueChanged(int)),m_ImageProcessor,SLOT(setMaxIter(int)));
- //Set L2 image processor as default
- m_CameraHandler->setImageProcessor(m_ImageProcessor);
- //Quit app on close
- this->setAttribute(Qt::WA_DeleteOnClose);
- qDebug() << "Main window thread ID" << this->thread();
- }
- CMainWindow::~CMainWindow(){
- m_CameraHandler->deleteLater();
- m_ImageWidget->deleteLater();
- m_ProcessedImageWidget->deleteLater();
- emit windowClosed();
- qDebug() << "CMainWindow deleted";
- }
- CCameraHandler::CCameraHandler(QObject *parent):
- QObject(parent),
- m_CameraCapture(),
- m_ImageProcessor(),
- m_CameraCaptureThread(),
- m_ProcessingThread(),
- m_CurrentFrame(400,400,CV_8UC3){
- m_CameraCaptureThread= new QThread();
- m_ProcessingThread= new QThread();
- m_CameraCapture= new CCameraCapture();
- //Move camera capture object to thread
- m_CameraCapture->moveToThread(m_CameraCaptureThread);
- //Connect error signal)
- QObject::connect(m_CameraCapture, SIGNAL(error(QString,QString)), this, SLOT(reportError(QString,QString)));
- //Connect the finished signal of the worker class to the thread for quitting the loop
- QObject::connect(m_CameraCapture, SIGNAL(finished()), m_CameraCaptureThread, SLOT(quit()));
- //This connections guarantees that the *m_CVideoCapture is automatically deleted if the event loop of the thread is terminated. Therefore, m_CVideoCapture does not need to be released manually if the capturing process is stopped.
- QObject::connect(m_CameraCaptureThread, SIGNAL(finished()), m_CameraCaptureThread, SLOT(deleteLater()));
- QObject::connect(m_CameraCapture, SIGNAL(finished()), m_CameraCapture, SLOT(deleteLater()));
- //Connect sendFrame to update frame for displaying the current frame
- QObject::connect(m_CameraCapture, SIGNAL(sendFrame(cv::Mat)), this, SLOT(receiveFrame(cv::Mat)));
- QObject::connect(this, SIGNAL(startGrabbing()), m_CameraCapture, SLOT(startGrabbing()));
- QObject::connect(this, SIGNAL(stopGrabbing()), m_CameraCapture, SLOT(stopGrabbing()));
- m_CameraCaptureThread->start();
- m_CameraCapture->openCamera();
- QObject::connect(this, SIGNAL(startGrabbing()), this, SLOT(getNewFrame()));
- m_ProcessingThread->start();
- }
- CCameraHandler::~CCameraHandler(void){
- m_CameraCapture->exitThread();
- m_ImageProcessor->exitThread();
- qDebug() << "CCameraHandler deleted";
- }
- CCameraCapture::~CCameraCapture(void){
- m_Cap.release();
- qDebug() << "CCameraCapture deleted";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement