gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 16:50:13 24 4
gpt4 key购买 nike

到现在为止我已经了解到一件事,我在使用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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com