opencv 多线程显示imshow出现图片不更新的问题
- 在linux 下使用opencv多线程使用opencv的imshow显示图片时,很多时候会出现图片不更新的情况(但是实际内存数据在变化),经过多次试验后,发现一个可以暂时解决图片显示不更新方法:
- 首先将所有的图片显示放到一个线程中,在该线程中统一显示。
- 显示代码:
Mat a;//a会不断的循环更新
namedWindow("img");
imshow("img",a);
startWindowThread();//开始不断的更新图片
waitKey(20);//20ms,这里参数选择最好根据具体的图片大小来定。即图片越大,最后时间越大。
opencv 多线程显示出现以下错误:
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
Blurring_Images: ../../src/xcb_io.c:178: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
The program has unexpectedly finished.
解决办法:
通过链接X11,包含xlib库和调用XinitThreads
例如:
// main.cpp
#include <thread>
#include <X11/Xlib.h>
int main() {
XInitThreads();
// . . .
}
g++ main.cpp -o my_program -std=c++0x -pthread -lX11 /* -pthread if you're on Linux */
当然还是链接你的其他生成库
target_link_libraries
(${PROJECT_NAME}
/usr/lib/x86_64-linux-gnu/libX11.so
pthread
)
http://blog.csdn.net/michaelhan3/article/details/54707417
http://blog.csdn.net/michaelhan3/article/details/68954106