开发者

OpenCV : How to use cvWaitKey() form a different thread other than the one created the window?

I have a problem here and need your help. I've been trying to capture keyboard strokes from a created window using cvWaitKey() function. The function works fine if I called the cvWaitKey from the same thread that created the window, but开发者_开发百科 when I create the window from a thread and call cvWaitKey() from another thread it doesn't return correct key, it blocks for cvWaitKey(0) and returns -1 for any timeout grater than zero.


Yes, this cannot work. cvWaitKey() is implemented by calling the PeekMessage() API function. That can only see messages on the message queue which is associated with the thread. The thread you created doesn't have any windows.

There is no obvious workaround for this, you have to call it on the thread that created the window. Calling GetAsyncKeyState() could work, a very different approach though.


In you "other" thread, you can set some shared variable to true or false (or some value), and make the "window thread" checks it before deciding whether to call cvWaitKey() in its local scope.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜