0

Till now I have learnt one thing, there's something wrong I'm doing with OpenCV, Qt has no role in the error

I'm trying to run two methods in different threads, but it gives me error:

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


Here's my code:

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);
}

whereas if i comment out one call(shown below), it runs fine

void Dialog::blurImages(int b)
{
    QtConcurrent::run(this,&Dialog::homogenour_blur,b);
    //QtConcurrent::run(this,&Dialog::gaussianBlur,b);
}

It's really annoying guys, please help !!

EDIT: Instead of calling showImage(), I replaced it with the actial OpenCV call(see below):

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);
}

Now the error I get is:

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.

7
  • the above code only runs with 1 call to the run method, so with the other one commented, I get 4 Jul 16, 2012 at 22:40
  • Are you doing what the error message suggests? Namely, are you calling XInitThreads() in your application?
    – RA.
    Jul 16, 2012 at 22:41
  • No I don't even know what is XInitThreads() Jul 16, 2012 at 22:44
  • Try calling XInitThreads() in "int main()" before you create your QApplication. See the example at the bottom of this page: doc.qt.nokia.com/qq/qq06-glimpsing.html.
    – RA.
    Jul 16, 2012 at 22:50
  • that is for OpenGL, I don't have OpenGL, so I get XInitThreads() method was not declared in this scope Jul 16, 2012 at 22:53

2 Answers 2

10

To all concerned:

fix Jaydeep's problems

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

and

error: ‘XInitThreads’ was not declared in this scope

by linking X11, including xlib, and calling XInitThreads.

Example for including xlib and calling XInitThreads:

// main.cpp
#include <thread> 
#include <X11/Xlib.h>

int main() {
   XInitThreads();
   // . . . 
}

Example for linking:

g++ main.cpp -o my_program -std=c++0x -pthread -lX11 /* -pthread if you're on Linux */

Of course, don't forget to link the other files that may be necessary to your application

1
  • This didn't fix my error, because I was writing from multiple threads. A way to solve this is to write the GUI calls from multiple threads into a queue, and process the queue from the main thread.
    – nnrales
    Feb 6, 2018 at 22:51
-1

imshow() method seems not thread safe. if you use python, it can be solved like this:

self.img_lock = threading.Lock()

with self.img_lock:
  cv2.imshow()
  cv2.waitKey(1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.