multithreading - OpenCV多线程错误[使用Qt]

标签 multithreading qt opencv

到现在为止我已经了解到一件事,我在使用OpenCV时出错,Qt在错误中没有任何作用

我正在尝试在不同的线程中运行两个方法,但这给了我错误:

[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.



这是我的代码:
void Dialog::blurImages(int b)
{
    QtConcurrent::run(this,&Dialog::homogenour_blur,b);
    QtConcurrent::run(this,&Dialog::gaussianBlur,b);
}

void Dialog::homogenour_blur(int b)
{
    cv::blur(img,img1,cv::Size(b,b));
    showImage("Homogenous Blur",img1);
}

void Dialog::gaussianBlur(int b)
{
    cv::GaussianBlur(img,img2,cv::Size(b,b),b);
    showImage("Gaussian Blur",img2);
}

而如果我注释掉一个电话(如下所示),则运行正常
void Dialog::blurImages(int b)
{
    QtConcurrent::run(this,&Dialog::homogenour_blur,b);
    //QtConcurrent::run(this,&Dialog::gaussianBlur,b);
}

真是令人讨厌的家伙,请帮忙!

编辑:
我没有调用showImage(),而是将其替换为实际的OpenCV调用(见下文):
void Dialog::homogenour_blur(int b)
{
    cv::blur(img,img1,cv::Size(b,b));
    //showImage("Homogenous Blur",img1);
    cv::imshow("Homogenous Blur",img1);
}

void Dialog::gaussianBlur(int b)
{
    cv::GaussianBlur(img,img2,cv::Size(b,b),b);
    //showImage("Gaussian Blur",img2);
    cv::imshow("Gaussian Blur",img2);
}

现在我得到的错误是:

Original Image: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.
Original Image: Fatal IO error 0 (Success) on X server :0.
Fatal Error: Accessed global static 'KGlobalSettings *s_self()' after destruction. Defined at ../../kdeui/kernel/kglobalsettings.cpp:190
The program has unexpectedly finished.

最佳答案

对于所有相关人员:
解决Jaydeep的问题

[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.



error: ‘XInitThreads’ was not declared in this scope


通过链接X11(包括xlib)并调用XInitThreads。
包含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 */
当然,不要忘了链接应用程序可能需要的其他文件

关于multithreading - OpenCV多线程错误[使用Qt],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11513564/

相关文章:

c - 如何在多线程程序中使用非确定性 igraph 函数?

c++ - QThread - 使用 moveToThread 将类成员移动到线程

c++ - 如何释放Qthread对象的内存?

c++ - 如何获取面上的点来绘制Delaunay三角剖分

python - 多幅图像的时间中值图像

c++ - OpenCV 如何将 jpeg 图像缓冲区放入 cvShowImage

c# - 使计算线程安全的标准方法是什么?

c# - 如何在另一个线程上渲染视觉对象

qt - 我们是否应该包含 Qt 使用的所有 3rd 方库的许可通知?

c++ - 选择文件后 QSignalMapper 不更新参数