diff --git a/vivalib/utils.cpp b/vivalib/utils.cpp index 70994b3..a02c7ec 100644 --- a/vivalib/utils.cpp +++ b/vivalib/utils.cpp @@ -41,6 +41,7 @@ const int Keys::TAB = 9; const int Keys::SPACE = 32; const int Keys::NONE = -1; const int Keys::c = 'c'; +const int Keys::n = 'n'; string Files::tmpFilenameInFolder(const string &folder, const string &ext) diff --git a/vivalib/utils.h b/vivalib/utils.h index 4301948..190922f 100644 --- a/vivalib/utils.h +++ b/vivalib/utils.h @@ -66,6 +66,7 @@ namespace viva const static int TAB; const static int SPACE; const static int NONE; + const static int n; const static int c; }; diff --git a/vivalib/viva.cpp b/vivalib/viva.cpp index 0b40204..7f5bfd6 100644 --- a/vivalib/viva.cpp +++ b/vivalib/viva.cpp @@ -134,7 +134,6 @@ void Processor::run() namedWindow(_outputWindowName, FLAGS); if (_mListener && _process) cv::setMouseCallback(_outputWindowName, Processor::mouseCallback, _process); - if (!_input && (!_process || !_functor)) return; @@ -143,23 +142,27 @@ void Processor::run() std::thread _inputThread(ProcessInput(_input, _input_channel)); thread_guard gi(_inputThread); - Ptr _output_channel = new BufferedImageChannel(_inputBufferSize); + Ptr _output_channel = new BufferedImageChannel(_outputBufferSize); std::thread _outputThread(ProcessOutput(_output, _output_channel)); thread_guard go(_outputThread); - size_t frameN = 0; + long frameN = -1; Mat freezeFrame; bool freezed = false; - while (_input_channel->isOpen() || !_input_channel->empty()) + bool running = true; + int key = Keys::NONE; + while (running && ( _input_channel->isOpen() || !_input_channel->empty())) { bool hasFrame = true; Mat frame, frameOut; - if (!freezed) + if (!freezed || key == Keys::n) { hasFrame = _input_channel->getData(frame); + freezeFrame = frame; + frameN++; } else { @@ -197,11 +200,22 @@ void Processor::run() if (_output) _output_channel->addData(frameOut); - int key = waitKey(1); + key = Keys::NONE; + + try + { + key = waitKey(1); + } + catch (...) + { + //... + } + if (key == Keys::ESC) { _input_channel->close(); _output_channel->close(); + running = false; } if (key == Keys::SPACE || _pause) { @@ -211,9 +225,7 @@ void Processor::run() } if (_kListener && _process && key != Keys::NONE) _process->keyboardInput(key); - - if (!freezed) - frameN++; + } } @@ -260,8 +272,7 @@ void BatchProcessor::run() namedWindow(_outputWindowName, FLAGS); if (_mListener && _batch_process) cv::setMouseCallback(_outputWindowName, BatchProcessor::mouseCallback, _batch_process); - - + if (!_input && (!_batch_process || !_batch_functor)) return; @@ -279,6 +290,9 @@ void BatchProcessor::run() vector freezeFrames; bool freezed = false; + + int key = Keys::NONE; + while (_input_channel->isOpen()) { @@ -305,7 +319,6 @@ void BatchProcessor::run() frames = freezeFrames; } - if (!hasFrames) { @@ -337,10 +350,18 @@ void BatchProcessor::run() cv::imshow(_outputWindowName, frameOut); if (_output) _output_channel->addData(frameOut); - - - - int key = waitKey(1); + + key = Keys::NONE; + + try + { + key = waitKey(1); + } + catch (...) + { + //... + } + if (key == Keys::ESC) { _input_channel->close();