diff --git a/src/goto_window.cpp b/src/goto_window.cpp index 2b18313..d2759b6 100644 --- a/src/goto_window.cpp +++ b/src/goto_window.cpp @@ -1,4 +1,5 @@ #include "goto_window.h" +#include "main_window.h" GotoWindow::GotoWindow(QWidget *parent) : QDialog(parent) { @@ -8,6 +9,9 @@ GotoWindow::GotoWindow(QWidget *parent) : QDialog(parent) { setGeometry(300, 50, 400, 70); } +void GotoWindow::setPlayback(Playback *playback) { + playback_thread = playback; +} void GotoWindow::setVideoCapture(cv::VideoCapture *cap) { capture_device = cap; @@ -39,17 +43,31 @@ void GotoWindow::createControls() { } -void GotoWindow::setFrameIndex(const long &i) { - index = i; +void GotoWindow::setFrameIndex(int i) { + frame_index = i; + QString frame_string; + QTextStream frame_stream(&frame_string); + frame_stream << "(Current/Total Frames/Seconds) - (" << frame_index << "/" << goto_pos->maximum() << "/" << (unsigned long)(goto_pos->minimum()/goto_pos->maximum()) << ") "; + main_window->setFrameIndex(frame_index); + main_window->statusBar()->showMessage(frame_string); +} + +void GotoWindow::setMainWindow(AC_MainWindow *window) { + main_window = window; } void GotoWindow::showImage() { - + QImage img; + if(playback_thread->getFrame(img, frame_index)) { + disp_window->displayImage(img); + } } -void GotoWindow::showWindow(int min, int max) { +void GotoWindow::showWindow(int frame_index, int min, int max) { goto_pos->setMaximum(min); goto_pos->setMaximum(max); + goto_pos->setSliderPosition(frame_index); + slideChanged(frame_index); show(); } @@ -59,6 +77,7 @@ void GotoWindow::pressedGo() { if(f_pos != goto_pos->sliderPosition()) { goto_pos->setSliderPosition(f_pos); } + setFrameIndex(f_pos); showImage(); } diff --git a/src/goto_window.h b/src/goto_window.h index a1dffb1..21e36c8 100644 --- a/src/goto_window.h +++ b/src/goto_window.h @@ -3,6 +3,9 @@ #include "qtheaders.h" #include "display_window.h" +#include "playback_thread.h" + +class AC_MainWindow; class GotoWindow : public QDialog { Q_OBJECT @@ -10,17 +13,21 @@ public: GotoWindow(QWidget *parent); void setVideoCapture(cv::VideoCapture *cap); void setDisplayWindow(DisplayWindow *win); + void setMainWindow(AC_MainWindow *window); + void setPlayback(Playback *playb); void createControls(); - void setFrameIndex(const long &index); + void setFrameIndex(int index); void showImage(); - void showWindow(int min, int max); + void showWindow(int frame_index, int min, int max); private: - long index; + int frame_index; DisplayWindow *disp_window; + AC_MainWindow *main_window; cv::VideoCapture *capture_device; QSlider *goto_pos; QLineEdit *goto_sec, *goto_frame; QPushButton *goto_jump; + Playback *playback_thread; public slots: void pressedGo(); void slideChanged(int pos); diff --git a/src/main_window.cpp b/src/main_window.cpp index e051693..f519d77 100644 --- a/src/main_window.cpp +++ b/src/main_window.cpp @@ -76,9 +76,10 @@ AC_MainWindow::AC_MainWindow(QWidget *parent) : QMainWindow(parent) { disp = new DisplayWindow(this); playback = new Playback(); - goto_window->showWindow(0, 100); goto_window->setParent(this); goto_window->setDisplayWindow(disp); + goto_window->setPlayback(playback); + goto_window->setMainWindow(this); QObject::connect(playback, SIGNAL(procImage(QImage)), this, SLOT(updateFrame(QImage))); QObject::connect(playback, SIGNAL(stopRecording()), this, SLOT(stopRecording())); @@ -905,6 +906,7 @@ bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, b void AC_MainWindow::controls_Stop() { playback->Stop(); + goto_window->hide(); progress_bar->hide(); controls_showvideo->setEnabled(false); controls_stop->setEnabled(false); @@ -966,10 +968,12 @@ void AC_MainWindow::file_Exit() { void AC_MainWindow::file_NewVideo() { cap_video->show(); + goto_window->hide(); } void AC_MainWindow::file_NewCamera() { cap_camera->show(); + goto_window->hide(); } void AC_MainWindow::controls_Snap() { @@ -982,7 +986,7 @@ void AC_MainWindow::controls_Pause() { controls_pause->setText("Paused"); controls_pause->setChecked(true); paused = true; - goto_window->showWindow(0, video_frames); + if(programMode == MODE_VIDEO) goto_window->showWindow(frame_index, 0, video_frames); playback->Stop(); } else { controls_pause->setText("Pause"); @@ -1058,6 +1062,9 @@ QImage Mat2QImage(cv::Mat const& src) return dest; } +void AC_MainWindow::setFrameIndex(int index) { + frame_index = index; +} void AC_MainWindow::updateFrame(QImage img) { if(playback->isStopped() == false) { diff --git a/src/main_window.h b/src/main_window.h index 0e9cc61..80fd774 100644 --- a/src/main_window.h +++ b/src/main_window.h @@ -51,6 +51,7 @@ public: QRadioButton *filter_single, *filter_custom; void updateList(); void setSubFilter(const QString &num); + void setFrameIndex(int i); public slots: void addClicked(); void rmvClicked(); diff --git a/src/playback_thread.cpp b/src/playback_thread.cpp index 1f721d9..6513632 100644 --- a/src/playback_thread.cpp +++ b/src/playback_thread.cpp @@ -280,6 +280,7 @@ void Playback::run() { } } + Playback::~Playback() { mutex.lock(); stop = true; @@ -298,6 +299,22 @@ void Playback::setFrameIndex(const long &index) { mutex.unlock(); } +bool Playback::getFrame(QImage &img, const int &index) { + QImage image; + setFrameIndex(index); + mutex.lock(); + cv::Mat frame; + if(mode == MODE_VIDEO && capture.read(frame)) { + cv::cvtColor(frame, rgb_frame, CV_BGR2RGB); + img = QImage((const unsigned char*)(rgb_frame.data), rgb_frame.cols, rgb_frame.rows, QImage::Format_RGB888); + mutex.unlock(); + setFrameIndex(index); + return true; + } + mutex.unlock(); + return false; +} + void Playback::enableRepeat(bool re) { mutex.lock(); repeat_video = re; diff --git a/src/playback_thread.h b/src/playback_thread.h index ecf207f..9bf3ea5 100644 --- a/src/playback_thread.h +++ b/src/playback_thread.h @@ -43,6 +43,7 @@ public: Playback(QObject *parent = 0); ~Playback(); void setFrameIndex(const long &index); + bool getFrame(QImage &img, const int &index); void setRGB(int r, int g, int b); void setColorOptions(int b, int g, int s); void setColorMap(int c);