added step one frame

This commit is contained in:
lostjared
2017-02-04 17:28:54 -08:00
parent f0daf1e289
commit afab4e714b
2 changed files with 21 additions and 17 deletions

View File

@@ -221,22 +221,20 @@ void AC_MainWindow::Log(const QString &s) {
} }
bool AC_MainWindow::startCamera(int res, int dev, const QString &outdir, bool record) { bool AC_MainWindow::startCamera(int res, int dev, const QString &outdir, bool record) {
// setup device // setup device
step_frame = false;
video_file_name = ""; video_file_name = "";
frame_index = 0;
capture_camera.open(dev); capture_camera.open(dev);
if(!capture_camera.isOpened()) { if(!capture_camera.isOpened()) {
return false; return false;
} }
video_frames = 0; video_frames = 0;
video_fps = capture_camera.get(CV_CAP_PROP_FPS); video_fps = 24;
int res_w = capture_camera.get(CV_CAP_PROP_FRAME_WIDTH); int res_w = capture_camera.get(CV_CAP_PROP_FRAME_WIDTH);
int res_h = capture_camera.get(CV_CAP_PROP_FRAME_HEIGHT); int res_h = capture_camera.get(CV_CAP_PROP_FRAME_HEIGHT);
QString str; QString str;
QTextStream stream(&str); QTextStream stream(&str);
stream << "Opened capture device " << res_w << "x" << res_h << "\n"; stream << "Opened capture device " << res_w << "x" << res_h << "\n";
stream << "FPS: " << video_fps << "\n"; stream << "FPS: " << video_fps << "\n";
output_directory = outdir; output_directory = outdir;
@@ -248,8 +246,12 @@ bool AC_MainWindow::startCamera(int res, int dev, const QString &outdir, bool re
QString output_name; QString output_name;
QTextStream stream_(&output_name); QTextStream stream_(&output_name);
static unsigned int index = 0; static unsigned int index = 0;
stream_ << outdir << "/" << "AC2.Output." << ++index << ".avi"; time_t t = time(0);
struct tm *m;
m = localtime(&t);
std::ostringstream time_stream;
time_stream << "-" << (m->tm_year + 1900) << "." << (m->tm_mon + 1) << "." << m->tm_mday << "_" << m->tm_hour << "." << m->tm_min << "." << m->tm_sec << "_";
stream_ << outdir << "/" << "Video." << time_stream.str().c_str() << "AC2.Output." << (++index) << ".avi";
switch(res) { switch(res) {
case 0: case 0:
res_w = 640; res_w = 640;
@@ -291,13 +293,14 @@ bool AC_MainWindow::startCamera(int res, int dev, const QString &outdir, bool re
file_new_video->setEnabled(false); file_new_video->setEnabled(false);
controls_stop->setEnabled(true); controls_stop->setEnabled(true);
connect(timer_camera, SIGNAL(timeout()), this, SLOT(timer_Camera())); connect(timer_camera, SIGNAL(timeout()), this, SLOT(timer_Camera()));
timer_camera->setInterval(1000/video_fps); timer_camera->setInterval(1000/24);
timer_camera->start(); timer_camera->start();
return true; return true;
} }
bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, bool record) { bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, bool record) {
video_file_name = ""; video_file_name = "";
step_frame = false;
capture_video.open(filename.toStdString()); capture_video.open(filename.toStdString());
if(!capture_video.isOpened()) { if(!capture_video.isOpened()) {
return false; return false;
@@ -305,13 +308,10 @@ bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, b
video_frames = capture_video.get(CV_CAP_PROP_FRAME_COUNT); video_frames = capture_video.get(CV_CAP_PROP_FRAME_COUNT);
if(video_frames <= 0) return false; if(video_frames <= 0) return false;
video_fps = capture_video.get(CV_CAP_PROP_FPS); video_fps = capture_video.get(CV_CAP_PROP_FPS);
int res_w = capture_video.get(CV_CAP_PROP_FRAME_WIDTH); int res_w = capture_video.get(CV_CAP_PROP_FRAME_WIDTH);
int res_h = capture_video.get(CV_CAP_PROP_FRAME_HEIGHT); int res_h = capture_video.get(CV_CAP_PROP_FRAME_HEIGHT);
QString str; QString str;
QTextStream stream(&str); QTextStream stream(&str);
stream << "Opened capture device " << res_w << "x" << res_h << "\n"; stream << "Opened capture device " << res_w << "x" << res_h << "\n";
stream << "FPS: " << video_fps << "\n"; stream << "FPS: " << video_fps << "\n";
stream << "Frame Count: " << video_frames << "\n"; stream << "Frame Count: " << video_frames << "\n";
@@ -329,7 +329,6 @@ bool AC_MainWindow::startVideo(const QString &filename, const QString &outdir, b
QTextStream stream_(&output_name); QTextStream stream_(&output_name);
static unsigned int index = 0; static unsigned int index = 0;
stream_ << outdir << "/" << "AC2.Output." << ++index << ".avi"; stream_ << outdir << "/" << "AC2.Output." << ++index << ".avi";
if(recording) { if(recording) {
video_file_name = output_name; video_file_name = output_name;
#if defined(__linux__) || defined(__APPLE__) #if defined(__linux__) || defined(__APPLE__)
@@ -418,12 +417,14 @@ void AC_MainWindow::controls_Pause() {
} }
void AC_MainWindow::controls_Step() { void AC_MainWindow::controls_Step() {
step_frame = true;
} }
void AC_MainWindow::timer_Camera() { void AC_MainWindow::timer_Camera() {
if(step_frame == true && paused == true) {
if(paused == true) return; step_frame = false;
}
else if(paused == true) return;
ac::isNegative = chk_negate->isChecked(); ac::isNegative = chk_negate->isChecked();
ac::color_order = combo_rgb->currentIndex(); ac::color_order = combo_rgb->currentIndex();
cv::Mat mat; cv::Mat mat;
@@ -477,7 +478,10 @@ void AC_MainWindow::timer_Camera() {
} }
void AC_MainWindow::timer_Video() { void AC_MainWindow::timer_Video() {
if(paused == true) return; if(step_frame == true && paused == true)
step_frame = false;
else if(paused == true) return;
ac::isNegative = chk_negate->isChecked(); ac::isNegative = chk_negate->isChecked();
ac::color_order = combo_rgb->currentIndex(); ac::color_order = combo_rgb->currentIndex();
cv::Mat mat; cv::Mat mat;

View File

@@ -46,7 +46,7 @@ private:
unsigned long video_frames; unsigned long video_frames;
double video_fps; double video_fps;
QTimer *timer_video, *timer_camera; QTimer *timer_video, *timer_camera;
bool paused, recording; bool paused, recording, step_frame;
QString video_file_name; QString video_file_name;
QString output_directory; QString output_directory;
bool take_snapshot; bool take_snapshot;