added png output in video mode

This commit is contained in:
Jared Bruni
2020-05-13 21:21:51 -07:00
parent 0c3032ce7a
commit 0377285afe
6 changed files with 49 additions and 10 deletions

View File

@@ -1084,7 +1084,7 @@ bool AC_MainWindow::startCamera(int res, int dev, const QString &outdir, bool re
return true;
}
bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, bool record, int type) {
bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, bool record, bool png_record, int type) {
programMode = MODE_VIDEO;
controls_stop->setEnabled(true);
controls_pause->setEnabled(true);
@@ -1179,7 +1179,23 @@ bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, b
out_stream << "Now recording to: " << output_name << "\nResolution: " << res_w << "x" << res_h << " FPS: " << video_fps << "\n";
Log(out_s);
}
playback->setVideo(capture_video,writer,recording);
static int output_index = 1;
QString dpath;
QTextStream stream1(&dpath);
QString path = filename.mid(filename.lastIndexOf("/"));
stream1 << outdir << "/" << path << "_png." << output_index;
QDir dir(dpath);
if(!dir.exists()) {
dir.mkpath(dpath);
std::cout << "mkpath: " << dpath.toStdString().c_str() << "\n";
} else {
std::cout << "directory exisits...\n";
}
++output_index;
playback->setPngPath(dpath.toStdString());
playback->setVideo(capture_video,writer,recording, png_record);
playback->Play();
disp->show();
#ifndef DISABLE_JOYSTICK

View File

@@ -33,7 +33,7 @@ public:
~AC_MainWindow();
void Log(const QString &s);
bool startCamera(int res, int dev, const QString &outdir, bool record, int type);
bool startVideo(const QString &filename, const QString &outdir, bool record, int type);
bool startVideo(const QString &filename, const QString &outdir, bool record,bool png_record, int type);
QListWidget /**filters,*/ *custom_filters;
QPushButton *btn_add, *btn_remove, *btn_moveup, *btn_movedown,*btn_load, *btn_save, *btn_sub, *btn_clr;
QTextEdit *log_text;

View File

@@ -96,7 +96,7 @@ void CaptureCamera::btn_Start() {
CaptureVideo::CaptureVideo(QWidget *parent) : QDialog(parent) {
setGeometry(100, 100, 330, 100);
setFixedSize(330, 100);
setFixedSize(330, 120);
setWindowTitle(tr("Capture from Video"));
setWindowIcon(QPixmap(":/images/icon.png"));
createControls();
@@ -114,9 +114,11 @@ void CaptureVideo::createControls() {
edit_outdir->setGeometry(120, 30, 200, 20);
edit_outdir->setReadOnly(true);
btn_start = new QPushButton(tr("Start"), this);
btn_start->setGeometry(10, 60, 100, 20);
btn_start->setGeometry(10, 60, 100, 25);
chk_record = new QCheckBox(tr("Record"), this);
chk_record->setGeometry(110, 60, 80, 20);
chk_png = new QCheckBox(tr("PNG"), this);
chk_png->setGeometry(110, 80, 80, 20);
video_type = new QComboBox(this);
video_type->setGeometry(180, 55, 120, 25);
@@ -156,10 +158,12 @@ void CaptureVideo::btn_Start() {
return;
}
int num;
num = video_type->currentIndex();
if(win_parent->startVideo(edit_src->text(), edit_outdir->text(), chk_record->isChecked(), num)) {
if(win_parent->startVideo(edit_src->text(), edit_outdir->text(), chk_record->isChecked(),chk_png->isChecked(), num)) {
hide();
} else {
QMessageBox::information(this, tr("Could not open file"), tr("Could not open video file, an error has occured"));

View File

@@ -41,7 +41,7 @@ public:
QLineEdit *edit_src, *edit_outdir;
QPushButton *btn_setedit, *btn_setout, *btn_start;
QCheckBox *chk_record;
QCheckBox *chk_record, *chk_png;
QComboBox *video_type;
public slots:

View File

@@ -46,8 +46,14 @@ void Playback::Play() {
start(HighPriority);
}
void Playback::setVideo(cv::VideoCapture cap, cv::VideoWriter wr, bool record) {
void Playback::setPngPath(std::string path) {
png_path = path;
png_index = 0;
}
void Playback::setVideo(cv::VideoCapture cap, cv::VideoWriter wr, bool record, bool rec_png) {
mode = MODE_VIDEO;
record_png = rec_png;
mutex.lock();
capture = cap;
writer = wr;
@@ -374,6 +380,14 @@ void Playback::run() {
msleep(duration);
}
mutex.lock();
if(record_png) {
std::ostringstream stream;
stream << png_path << "/" << std::setfill('0') << std::setw(15) << png_index << ".png";
++png_index;
cv::imwrite(stream.str(), frame);
}
if(recording && writer.isOpened()) {
writer.write(frame);
}

View File

@@ -30,8 +30,12 @@ private:
QImage img;
std::vector<FilterValue> current;
bool isPaused, isStep;
bool record_png;
int png_index;
std::string png_path;
VideoMode mode;
int device_num;
std::string file_name_png;
unsigned long *frame_index;
unsigned int red, green, blue;
unsigned int bright_, gamma_, saturation_;
@@ -57,11 +61,12 @@ public:
void setRGB(int r, int g, int b);
void setColorOptions(int b, int g, int s);
void setColorMap(int c);
void setPngPath(std::string path);
void Play();
void Stop();
void Release();
void SetFlip(bool f1, bool f2);
void setVideo(cv::VideoCapture cap, cv::VideoWriter writer, bool record);
void setVideo(cv::VideoCapture cap, cv::VideoWriter writer, bool record, bool record_png);
bool setVideoCamera(std::string name, int type, int device, int res, cv::VideoWriter writer, bool record);
bool isStopped() const;
void run();