got step/pause working

This commit is contained in:
lostjared
2017-02-07 17:31:42 -08:00
parent f53a939e4d
commit d210bbebc1
2 changed files with 22 additions and 2 deletions

View File

@@ -33,6 +33,7 @@ void custom_filter(cv::Mat &) {
Playback::Playback(QObject *parent) : QThread(parent) { Playback::Playback(QObject *parent) : QThread(parent) {
stop = true; stop = true;
isStep = false;
} }
void Playback::Play() { void Playback::Play() {
@@ -73,18 +74,18 @@ void Playback::setOptions(bool n, int c) {
} }
void Playback::run() { void Playback::run() {
int delay = (1000/frame_rate); int delay = (1000/frame_rate);
while(!stop) { while(!stop) {
mutex.lock(); mutex.lock();
if(!capture.read(frame)) { if(!capture.read(frame)) {
stop = true; stop = true;
mutex.unlock(); mutex.unlock();
return; return;
} }
if(current.size()>0) { if(current.size()>0) {
ac::in_custom = true; ac::in_custom = true;
for(unsigned int i = 0; i < current.size(); ++i) { for(unsigned int i = 0; i < current.size(); ++i) {
if(i == current.size()-1) if(i == current.size()-1)
@@ -99,6 +100,7 @@ void Playback::run() {
} }
} }
mutex.unlock(); mutex.unlock();
if(frame.channels()==3) { if(frame.channels()==3) {
cv::cvtColor(frame, rgb_frame, CV_BGR2RGB); cv::cvtColor(frame, rgb_frame, CV_BGR2RGB);
img = QImage((const unsigned char*)(rgb_frame.data), rgb_frame.cols, rgb_frame.rows, QImage::Format_RGB888); 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); emit procImage(img);
this->msleep(delay); this->msleep(delay);
if(isStep == true) {
isStep = false;
return;
}
} }
} }
@@ -123,7 +129,9 @@ Playback::~Playback() {
} }
void Playback::Stop() { void Playback::Stop() {
mutex.lock();
stop = true; stop = true;
mutex.unlock();
} }
void Playback::msleep(int ms) { void Playback::msleep(int ms) {
@@ -134,6 +142,12 @@ bool Playback::isStopped() const {
return this->stop; return this->stop;
} }
void Playback::setStep() {
mutex.lock();
isStep = true;
mutex.unlock();
}
void Playback::setImage(const cv::Mat &frame) { void Playback::setImage(const cv::Mat &frame) {
mutex.lock(); mutex.lock();
blend_set = true; blend_set = true;
@@ -586,9 +600,11 @@ void AC_MainWindow::controls_Pause() {
controls_pause->setText("Paused"); controls_pause->setText("Paused");
controls_pause->setChecked(Qt::Checked); controls_pause->setChecked(Qt::Checked);
paused = true; paused = true;
playback->Stop();
} else { } else {
controls_pause->setText("Pause"); controls_pause->setText("Pause");
controls_pause->setChecked(Qt::Unchecked); controls_pause->setChecked(Qt::Unchecked);
playback->Play();
paused = false; paused = false;
} }
} }
@@ -605,6 +621,8 @@ void AC_MainWindow::controls_SetImage() {
} }
void AC_MainWindow::controls_Step() { void AC_MainWindow::controls_Step() {
playback->setStep();
playback->Play();
step_frame = true; step_frame = true;
} }

View File

@@ -18,6 +18,7 @@ private:
cv::Mat rgb_frame; cv::Mat rgb_frame;
QImage img; QImage img;
std::vector<std::pair<int, int>> current; std::vector<std::pair<int, int>> current;
bool isPaused, isStep;
public: public:
Playback(QObject *parent = 0); Playback(QObject *parent = 0);
~Playback(); ~Playback();
@@ -30,6 +31,7 @@ public:
void setVector(std::vector<std::pair<int, int>> s); void setVector(std::vector<std::pair<int, int>> s);
void setOptions(bool n, int c); void setOptions(bool n, int c);
void setImage(const cv::Mat &image); void setImage(const cv::Mat &image);
void setStep();
signals: signals:
void procImage(const QImage &image); void procImage(const QImage &image);
void procCameraFrame(void *frame); void procCameraFrame(void *frame);