Ask Your Question

Revision history [back]

How to handle waitKey() during threading

I am trying to mess around with multi-threading and OpenCV so I wrote the following program.

void performSearch(Mat& original, Mat& grey, Mat& result)
{
    // do stuff
    waitKey();
}

int main()
{
    thread(performSearch, ref(image), ref(image_grey), ref(answer)).join();
}

Obviously, this program will throw an NSInternalInconsistencyException exception because waitKey() needs to be run on the main thread. My question is, how do I attach it to the main thread?

I have an iOS background and with grand central dispatch, I'd simply have to do something along the lines of:

DispatchQueue.main.async // this gets me the main queue asynchronously
{
    // update UI
}
click to hide/show revision 2
retagged

updated 2017-08-08 12:13:42 -0600

berak gravatar image

How to handle waitKey() during threading

I am trying to mess around with multi-threading and OpenCV so I wrote the following program.

void performSearch(Mat& original, Mat& grey, Mat& result)
{
    // do stuff
    waitKey();
}

int main()
{
    thread(performSearch, ref(image), ref(image_grey), ref(answer)).join();
}

Obviously, this program will throw an NSInternalInconsistencyException exception because waitKey() needs to be run on the main thread. My question is, how do I attach it to the main thread?

I have an iOS background and with grand central dispatch, I'd simply have to do something along the lines of:

DispatchQueue.main.async // this gets me the main queue asynchronously
{
    // update UI
}