goto frame is working

This commit is contained in:
lostjared
2018-08-30 04:59:19 -07:00
parent 646faeac2c
commit 68bc7dbda3
6 changed files with 61 additions and 9 deletions

View File

@@ -1,4 +1,5 @@
#include "goto_window.h" #include "goto_window.h"
#include "main_window.h"
GotoWindow::GotoWindow(QWidget *parent) : QDialog(parent) { GotoWindow::GotoWindow(QWidget *parent) : QDialog(parent) {
@@ -8,6 +9,9 @@ GotoWindow::GotoWindow(QWidget *parent) : QDialog(parent) {
setGeometry(300, 50, 400, 70); setGeometry(300, 50, 400, 70);
} }
void GotoWindow::setPlayback(Playback *playback) {
playback_thread = playback;
}
void GotoWindow::setVideoCapture(cv::VideoCapture *cap) { void GotoWindow::setVideoCapture(cv::VideoCapture *cap) {
capture_device = cap; capture_device = cap;
@@ -39,17 +43,31 @@ void GotoWindow::createControls() {
} }
void GotoWindow::setFrameIndex(const long &i) { void GotoWindow::setFrameIndex(int i) {
index = 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() { 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(min);
goto_pos->setMaximum(max); goto_pos->setMaximum(max);
goto_pos->setSliderPosition(frame_index);
slideChanged(frame_index);
show(); show();
} }
@@ -59,6 +77,7 @@ void GotoWindow::pressedGo() {
if(f_pos != goto_pos->sliderPosition()) { if(f_pos != goto_pos->sliderPosition()) {
goto_pos->setSliderPosition(f_pos); goto_pos->setSliderPosition(f_pos);
} }
setFrameIndex(f_pos);
showImage(); showImage();
} }

View File

@@ -3,6 +3,9 @@
#include "qtheaders.h" #include "qtheaders.h"
#include "display_window.h" #include "display_window.h"
#include "playback_thread.h"
class AC_MainWindow;
class GotoWindow : public QDialog { class GotoWindow : public QDialog {
Q_OBJECT Q_OBJECT
@@ -10,17 +13,21 @@ public:
GotoWindow(QWidget *parent); GotoWindow(QWidget *parent);
void setVideoCapture(cv::VideoCapture *cap); void setVideoCapture(cv::VideoCapture *cap);
void setDisplayWindow(DisplayWindow *win); void setDisplayWindow(DisplayWindow *win);
void setMainWindow(AC_MainWindow *window);
void setPlayback(Playback *playb);
void createControls(); void createControls();
void setFrameIndex(const long &index); void setFrameIndex(int index);
void showImage(); void showImage();
void showWindow(int min, int max); void showWindow(int frame_index, int min, int max);
private: private:
long index; int frame_index;
DisplayWindow *disp_window; DisplayWindow *disp_window;
AC_MainWindow *main_window;
cv::VideoCapture *capture_device; cv::VideoCapture *capture_device;
QSlider *goto_pos; QSlider *goto_pos;
QLineEdit *goto_sec, *goto_frame; QLineEdit *goto_sec, *goto_frame;
QPushButton *goto_jump; QPushButton *goto_jump;
Playback *playback_thread;
public slots: public slots:
void pressedGo(); void pressedGo();
void slideChanged(int pos); void slideChanged(int pos);

View File

@@ -76,9 +76,10 @@ AC_MainWindow::AC_MainWindow(QWidget *parent) : QMainWindow(parent) {
disp = new DisplayWindow(this); disp = new DisplayWindow(this);
playback = new Playback(); playback = new Playback();
goto_window->showWindow(0, 100);
goto_window->setParent(this); goto_window->setParent(this);
goto_window->setDisplayWindow(disp); 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(procImage(QImage)), this, SLOT(updateFrame(QImage)));
QObject::connect(playback, SIGNAL(stopRecording()), this, SLOT(stopRecording())); 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() { void AC_MainWindow::controls_Stop() {
playback->Stop(); playback->Stop();
goto_window->hide();
progress_bar->hide(); progress_bar->hide();
controls_showvideo->setEnabled(false); controls_showvideo->setEnabled(false);
controls_stop->setEnabled(false); controls_stop->setEnabled(false);
@@ -966,10 +968,12 @@ void AC_MainWindow::file_Exit() {
void AC_MainWindow::file_NewVideo() { void AC_MainWindow::file_NewVideo() {
cap_video->show(); cap_video->show();
goto_window->hide();
} }
void AC_MainWindow::file_NewCamera() { void AC_MainWindow::file_NewCamera() {
cap_camera->show(); cap_camera->show();
goto_window->hide();
} }
void AC_MainWindow::controls_Snap() { void AC_MainWindow::controls_Snap() {
@@ -982,7 +986,7 @@ void AC_MainWindow::controls_Pause() {
controls_pause->setText("Paused"); controls_pause->setText("Paused");
controls_pause->setChecked(true); controls_pause->setChecked(true);
paused = true; paused = true;
goto_window->showWindow(0, video_frames); if(programMode == MODE_VIDEO) goto_window->showWindow(frame_index, 0, video_frames);
playback->Stop(); playback->Stop();
} else { } else {
controls_pause->setText("Pause"); controls_pause->setText("Pause");
@@ -1058,6 +1062,9 @@ QImage Mat2QImage(cv::Mat const& src)
return dest; return dest;
} }
void AC_MainWindow::setFrameIndex(int index) {
frame_index = index;
}
void AC_MainWindow::updateFrame(QImage img) { void AC_MainWindow::updateFrame(QImage img) {
if(playback->isStopped() == false) { if(playback->isStopped() == false) {

View File

@@ -51,6 +51,7 @@ public:
QRadioButton *filter_single, *filter_custom; QRadioButton *filter_single, *filter_custom;
void updateList(); void updateList();
void setSubFilter(const QString &num); void setSubFilter(const QString &num);
void setFrameIndex(int i);
public slots: public slots:
void addClicked(); void addClicked();
void rmvClicked(); void rmvClicked();

View File

@@ -280,6 +280,7 @@ void Playback::run() {
} }
} }
Playback::~Playback() { Playback::~Playback() {
mutex.lock(); mutex.lock();
stop = true; stop = true;
@@ -298,6 +299,22 @@ void Playback::setFrameIndex(const long &index) {
mutex.unlock(); 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) { void Playback::enableRepeat(bool re) {
mutex.lock(); mutex.lock();
repeat_video = re; repeat_video = re;

View File

@@ -43,6 +43,7 @@ public:
Playback(QObject *parent = 0); Playback(QObject *parent = 0);
~Playback(); ~Playback();
void setFrameIndex(const long &index); void setFrameIndex(const long &index);
bool getFrame(QImage &img, const int &index);
void setRGB(int r, int g, int b); void setRGB(int r, int g, int b);
void setColorOptions(int b, int g, int s); void setColorOptions(int b, int g, int s);
void setColorMap(int c); void setColorMap(int c);