I found this rather annoying bug and I couldn’t find anything other than a unanswered question on the opencv website, hopefully someone with more knowledge about the two libraries will be able to point me in the right direction.
I won’t provide code because that would be beside the point of learning what causes the crash.
If I draw a tkinter window and then root.destroy() it, trying to draw a cv2.imshow window will result in a X Window System error as soon as the cv2.waitKey delay is over. I’ve tried to replicate in different ways and it always gets to the error (error_code 3 request_code 15 minor_code 0).
It is worth noting that a root.quit() command won’t cause the same issue (as it is my understanding this method will simply exit the main loop rather than destroying the widgets). Also, while any cv2.imshow call will fail, trying to draw a new tkinter window will work just fine.
What resources are being shared among the two libraries? What does root.destroy() cause in the X environment to prevent any cv2 window to be drawn?
Debian Jessie - Python 3.4 - OpenCV 3.2.0
When you destroy the root window, it destroys all children windows as well. If cv2 uses a tkinter window or child window of the root window, it will fail if you destroy the root window.
tkinter.root.destroy and cv2.imshow - X Windows system error