Skip to content

Commit

Permalink
fixing exception throw by waitKey in some OS
Browse files Browse the repository at this point in the history
  • Loading branch information
asolis committed Apr 15, 2016
1 parent 9a71e86 commit baf0a99
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
1 change: 1 addition & 0 deletions vivalib/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions vivalib/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
53 changes: 37 additions & 16 deletions vivalib/viva.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ void Processor::run()
namedWindow(_outputWindowName, FLAGS);
if (_mListener && _process)
cv::setMouseCallback(_outputWindowName, Processor::mouseCallback, _process);


if (!_input && (!_process || !_functor))
return;
Expand All @@ -143,23 +142,27 @@ void Processor::run()
std::thread _inputThread(ProcessInput(_input, _input_channel));
thread_guard gi(_inputThread);

Ptr<BufferedImageChannel> _output_channel = new BufferedImageChannel(_inputBufferSize);
Ptr<BufferedImageChannel> _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
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -211,9 +225,7 @@ void Processor::run()
}
if (_kListener && _process && key != Keys::NONE)
_process->keyboardInput(key);

if (!freezed)
frameN++;

}

}
Expand Down Expand Up @@ -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;

Expand All @@ -279,6 +290,9 @@ void BatchProcessor::run()

vector<Mat> freezeFrames;
bool freezed = false;

int key = Keys::NONE;

while (_input_channel->isOpen())
{

Expand All @@ -305,7 +319,6 @@ void BatchProcessor::run()
frames = freezeFrames;
}



if (!hasFrames)
{
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit baf0a99

Please sign in to comment.