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)
{
for(size_t index = 0; index < container.size(); ++index)
{
// do stuff
imshow("Results", result);
waitKey();
}
}
int main()
{
thread(performSearch, ref(image), ref(image_grey), ref(answer)).join();
thread(performSearch, ref(image2), ref(image2_grey), ref(answer2)).join();
}
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
}
Is it possible to achieve this in C++? If yes, how?
Heads Up: I have looked at this question and they're using QT for their GUI. I'm not.