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.

Jaydeep Solanki
  • 2,895
  • 5
  • 36
  • 50

2 Answers2

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

Community
  • 1
  • 1
Dodgie
  • 643
  • 1
  • 10
  • 17
  • 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 06 '18 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)