added image cycle feature

This commit is contained in:
Jared Bruni
2019-09-04 13:13:26 -07:00
parent 1cdb5b4e4b
commit d1963845a5
4 changed files with 104 additions and 0 deletions

View File

@@ -16,6 +16,8 @@ void ImageWindow::createControls() {
rmv_file->setGeometry(115,325,100,25);
set_file = new QPushButton(tr("Set Image"), this);
set_file->setGeometry(685,325,100,25);
image_set_cycle = new QPushButton(tr("Set Cycle"), this);
image_set_cycle->setGeometry(590, 325, 100, 25);
image_cycle_on = new QCheckBox("Image Cycle", this);
image_cycle_on->setGeometry(220, 325, 100, 25);
image_cycle = new QComboBox(this);
@@ -23,6 +25,8 @@ void ImageWindow::createControls() {
image_cycle->addItem(tr("Random"));
image_cycle->addItem(tr("In Order"));
image_cycle->addItem(tr("Shuffle"));
image_frames = new QLineEdit("120", this);
image_frames->setGeometry(425, 325, 100, 25);
image_pic = new QLabel("", this);
image_pic->setGeometry((770/2)+10, 20, 770/2,300);
image_pic->setStyleSheet("QLabel{background: black; color: #000000;}");
@@ -30,6 +34,7 @@ void ImageWindow::createControls() {
connect(add_files, SIGNAL(clicked()), this, SLOT(image_AddFiles()));
connect(rmv_file, SIGNAL(clicked()), this, SLOT(image_RmvFile()));
connect(set_file, SIGNAL(clicked()), this, SLOT(image_SetFile()));
connect(image_set_cycle, SIGNAL(clicked()), this, SLOT(image_SetCycle()));
connect(image_files, SIGNAL(currentRowChanged(int)), this, SLOT(image_RowChanged(int)));
//image_files->addItem("TEST!!");
}
@@ -71,6 +76,34 @@ void ImageWindow::image_RowChanged(int index) {
}
}
void ImageWindow::image_SetCycle() {
QString text_value;
QTextStream stream(&text_value);
if(image_files->count() < 0 || !image_cycle_on->isChecked()) {
playback->setCycle(0);
stream << "Cycle Turned Off.\n";
blend_set = false;
} else {
std::vector<std::string> text_items;
for(int i = 0; i < image_files->count(); ++i) {
text_items.push_back(image_files->item(i)->text().toStdString());
}
int type = image_cycle->currentIndex();
QString fvalue = image_frames->text();
int val = atoi(fvalue.toStdString().c_str());
if(val <= 0 || type < 0) {
stream << "Invalid Frame Count/Type Index\n";
} else {
QString im_cycle = image_cycle->itemText(type);
stream << "Image Frames: " << text_items.size() << " Cycle Type: " << im_cycle << " every " << val << " frames.\n";
blend_image = cv::imread(text_items[0]);
playback->setCycle(type+1, val, text_items);
blend_set = true;
}
}
QMessageBox::information(this, "Image Cycle", text_value);
}
void ImageWindow::setPlayback(Playback *play) {
playback = play;
}

View File

@@ -15,12 +15,15 @@ public slots:
void image_RmvFile();
void image_SetFile();
void image_RowChanged(int index);
void image_SetCycle();
private:
QListWidget *image_files;
QPushButton *add_files, *rmv_file, *set_file;
QComboBox *image_cycle;
QCheckBox *image_cycle_on;
QLabel *image_pic;
QLineEdit *image_frames;
QPushButton *image_set_cycle;
Playback *playback;
};

View File

@@ -19,6 +19,9 @@ Playback::Playback(QObject *parent) : QThread(parent) {
flip_frame2 = false;
repeat_video = false;
fadefilter = true;
cycle_on = 0;
cycle_index = 0;
frame_num = 0;
}
void Playback::Play() {
@@ -109,6 +112,28 @@ void Playback::setOptions(bool n, int c) {
mutex.unlock();
}
void Playback::setCycle(int type, int frame_skip, std::vector<std::string> &v) {
mutex.lock();
cycle_on = type;
if(!cycle_values.empty())
cycle_values.erase(cycle_values.begin(), cycle_values.end());
for(auto &i : v) {
cv::Mat value = cv::imread(i);
cycle_values.push_back(value);
}
cycle_index = 0;
frame_num = frame_skip;
mutex.unlock();
}
void Playback::setCycle(int type) {
mutex.lock();
cycle_on = type;
cycle_index = 0;
mutex.unlock();
}
void Playback::reset_filters() {
mutex.lock();
if(ac::reset_alpha == false) {
@@ -239,6 +264,43 @@ void Playback::run() {
cur = current;
mutex_shown.unlock();
ac::orig_frame = frame.clone();
mutex.lock();
if(cycle_on > 0) {
cv::Mat *cycle_image = 0;
static int frame_count = 0;
++frame_count;
if(frame_count > frame_num) {
frame_count = 0;
switch(cycle_on) {
case 0:
break;
case 1:
cycle_image = &cycle_values[rand()%cycle_values.size()];
break;
case 2:
cycle_image = &cycle_values[cycle_index];
++cycle_index;
if(cycle_index > static_cast<int>(cycle_values.size()-1))
cycle_index = 0;
break;
case 3:
cycle_image = &cycle_values[cycle_index];
++cycle_index;
if(cycle_index > static_cast<int>(cycle_values.size()-1)) {
cycle_index = 0;
static std::random_device r;
static auto rng = std::default_random_engine(r());
std::shuffle(cycle_values.begin(), cycle_values.end(), rng);
}
break;
}
if(blend_set == true && cycle_image != 0)
blend_image = cycle_image->clone();
}
}
mutex.unlock();
if(single_mode == true && alpha > 0) {
if(fadefilter == true) filterFade(frame, current_filter, prev_filter, alpha);
drawEffects(frame);

View File

@@ -40,6 +40,10 @@ private:
bool flip_frame1, flip_frame2;
bool repeat_video;
bool fadefilter;
std::vector<cv::Mat> cycle_values;
int cycle_on;
int cycle_index;
int frame_num;
public:
Playback(QObject *parent = 0);
~Playback();
@@ -73,6 +77,8 @@ public:
void reset_filters();
void setSubFilter(int index);
void enableRepeat(bool re);
void setCycle(int type, int frame_skip, std::vector<std::string> &val);
void setCycle(int type);
signals:
void procImage(const QImage image);
void stopRecording();