I have two signals that are connecting and one that will not.
I have a mainwindow widget to display images processed by a Qthread which emits the original and processed images to the my mainwidow where they are displayed, this works. I would also like to emit a frames per second calculation from this thread, but it will not connect.
all code here: https://github.com/ianzur/qtGui_imageProcessing
mainwindow.cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
// Timer for UI responsivness
tmrTimer = new QTimer(this);
connect(tmrTimer,SIGNAL(timeout()),this,SLOT(UpdateGUI()));
tmrTimer->start(20);
// Set initial sliders postion (for selecting ROI)
ui->SldLower->setSliderPosition(0);
ui->SldUpper->setSliderPosition(480);
ui->SldLeft->setSliderPosition(0);
ui->SldRight->setSliderPosition(640);
//connections to video processor thread
const bool c = connect(&processor,SIGNAL(outFPS(float)),ui->FPS,SLOT(setNum(float)));
connect(&processor,SIGNAL(inDisplay(QPixmap)),ui->inVideo,SLOT(setPixmap(QPixmap)));
connect(&processor,SIGNAL(outDisplay(QPixmap)),ui->outVideo,SLOT(setPixmap(QPixmap)));
qDebug() << "connected" << c;
}
Thread declaration
class ProcessorThread : public QThread
{
Q_OBJECT
public:
explicit ProcessorThread(QObject *parent = 0);
void update(QRect r, float low, float high);
int CLOCK();
float avgfps();
signals:
void inDisplay(QPixmap pixmap);
void outDisplay(QPixmap pixmap);
void outFPS(float fps);
protected:
void run() override;
private:
cv::VideoCapture capture;
//Region of interest
cv::Rect myROI;
float lowHz;
float highHz;
//float fps;
int _fpsstart=0;
float _avgfps=0;
float _fps1sec=0;
};
Thread definition
ProcessorThread::ProcessorThread(QObject *parent) : QThread(parent)
{
}
int ProcessorThread::CLOCK()
{
struct timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return (t.tv_sec * 1000)+(t.tv_nsec*1e-6);
}
float ProcessorThread::avgfps()
{
if(CLOCK()-_fpsstart>1000)
{
_fpsstart=CLOCK();
_avgfps=0.9*_avgfps+0.1*_fps1sec;
_fps1sec=0;
}
_fps1sec++;
return _avgfps;
}
void ProcessorThread::run()
{
VideoCapture camera(0);
cv::Mat inFrame, outFrame, cropped, bit;
while(camera.isOpened() && !isInterruptionRequested())
{
camera >> inFrame;
if(inFrame.empty())
continue;
outFrame = inFrame.clone();
cropped = inFrame(myROI);
bitwise_not(cropped, bit);
bit.copyTo(outFrame(myROI));
//qDebug() << avgfps();
emit outFPS(avgfps());
emit inDisplay(QPixmap::fromImage(QImage(inFrame.data,inFrame.cols,inFrame.rows,inFrame.step,QImage::Format_RGB888).rgbSwapped()));
emit outDisplay(QPixmap::fromImage(QImage(outFrame.data,outFrame.cols,outFrame.rows,outFrame.step,QImage::Format_RGB888).rgbSwapped()));
}
}
void ProcessorThread::update(QRect r, float low, float high)
{
this->myROI = cv::Rect(r.x(),r.y(),r.width(),r.height());
this->lowHz = low;
this->highHz = high;
}
I cannot figure out why only the outFPS will not connect.