diff --git a/src/main_window.cpp b/src/main_window.cpp index 133fc8e..010a944 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -33,6 +33,7 @@ void custom_filter(cv::Mat &) { Playback::Playback(QObject *parent) : QThread(parent) { stop = true; + isStep = false; } void Playback::Play() { @@ -73,18 +74,18 @@ void Playback::setOptions(bool n, int c) { } void Playback::run() { + int delay = (1000/frame_rate); while(!stop) { mutex.lock(); + if(!capture.read(frame)) { stop = true; mutex.unlock(); return; } if(current.size()>0) { - ac::in_custom = true; - for(unsigned int i = 0; i < current.size(); ++i) { if(i == current.size()-1) @@ -99,6 +100,7 @@ void Playback::run() { } } mutex.unlock(); + if(frame.channels()==3) { cv::cvtColor(frame, rgb_frame, CV_BGR2RGB); img = QImage((const unsigned char*)(rgb_frame.data), rgb_frame.cols, rgb_frame.rows, QImage::Format_RGB888); @@ -111,6 +113,10 @@ void Playback::run() { } emit procImage(img); this->msleep(delay); + if(isStep == true) { + isStep = false; + return; + } } } @@ -123,7 +129,9 @@ Playback::~Playback() { } void Playback::Stop() { + mutex.lock(); stop = true; + mutex.unlock(); } void Playback::msleep(int ms) { @@ -134,6 +142,12 @@ bool Playback::isStopped() const { return this->stop; } +void Playback::setStep() { + mutex.lock(); + isStep = true; + mutex.unlock(); +} + void Playback::setImage(const cv::Mat &frame) { mutex.lock(); blend_set = true; @@ -586,9 +600,11 @@ void AC_MainWindow::controls_Pause() { controls_pause->setText("Paused"); controls_pause->setChecked(Qt::Checked); paused = true; + playback->Stop(); } else { controls_pause->setText("Pause"); controls_pause->setChecked(Qt::Unchecked); + playback->Play(); paused = false; } } @@ -605,6 +621,8 @@ void AC_MainWindow::controls_SetImage() { } void AC_MainWindow::controls_Step() { + playback->setStep(); + playback->Play(); step_frame = true; } diff --git a/src/main_window.h b/src/main_window.h index 185aa7b..4292850 100644 --- a/src/main_window.h +++ b/src/main_window.h @@ -18,6 +18,7 @@ private: cv::Mat rgb_frame; QImage img; std::vector> current; + bool isPaused, isStep; public: Playback(QObject *parent = 0); ~Playback(); @@ -30,6 +31,7 @@ public: void setVector(std::vector> s); void setOptions(bool n, int c); void setImage(const cv::Mat &image); + void setStep(); signals: void procImage(const QImage &image); void procCameraFrame(void *frame);