MatplotLib (TKinter) + OpenCV crashing in Python 3 -


i trying run python 3 code first shows opencv window , when closes should plot using matplotlib. upon plt.show() call program crashes: python3.6 quit unexpectedly.

import numpy np  import matplotlib matplotlib.use("tkagg")     # <== doesn't solve problem import matplotlib.pyplot plt  import cv2 #cv2.ocl.setuseopencl(false)  <== doesn't solve problem  im = np.zeros((100,100,3)) cv2.imshow('test', im) cv2.waitkey(0)  plt.plot(np.sin(np.linspace(0,20,200))) plt.show()                  # <== crashes on call 

in other stackoverflow posts found setting matplotlib backend tkagg should fix or setting setuseopencl(false). both these potential fixes not work on macbook. i've tried several things, changing import order, trying swap matplotlib backend. has idea on how fix problem?

macos sierra 10.12.3
python 3.6.0
tkinter version 8.5
opencv version 3.2.0
matplotlib version 2.0.0

the stacktrace of how crashes:

libc++abi.dylib: terminating uncaught exception of type nsexception

2017-03-28 11:30:45.639 python3.6[5208:78361] -[nsapplication _setup:]: unrecognized selector sent instance 0x7f997ec98190 2017-03-28 11:30:45.641 python3.6[5208:78361] * terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[nsapplication _setup:]: unrecognized selector sent instance 0x7f997ec98190' * first throw call stack: ( 0 corefoundation 0x00007fffbeb80e7b exceptionpreprocess + 171 1 libobjc.a.dylib 0x00007fffd3760cad objc_exception_throw + 48 2 corefoundation 0x00007fffbec02cb4 -[nsobject(nsobject) doesnotrecognizeselector:] + 132 3 corefoundation 0x00007fffbeaf2fb5 ___forwarding_ + 1061 4 corefoundation 0x00007fffbeaf2b08 _cf_forwarding_prep_0 + 120 5 tk 0x00000001032c45e6 tkpinit + 471 6 tk 0x000000010323fc8d tk_init + 1794 7 _tkinter.cpython-36m-darwin.so 0x000000010311cde6 tcl_appinit + 82 8 _tkinter.cpython-36m-darwin.so 0x00000001031183a3 _tkinter_create + 1094 9 python 0x0000000100b28ea2 _pycfunction_fastcalldict + 172 10 python 0x0000000100b927a2 call_function + 584 11 python 0x0000000100b8fbbb _pyeval_evalframedefault + 23930 12 python 0x0000000100b92fbf _pyeval_evalcodewithname + 1973 13 python 0x0000000100b938c4 _pyfunction_fastcalldict + 477 14 python 0x0000000100aeea73 _pyobject_fastcalldict + 231 15 python 0x0000000100aeeb93 _pyobject_call_prepend + 149 16 python 0x0000000100aee8cb pyobject_call + 102 17 python 0x0000000100b3cd24 slot_tp_init + 61 18 python 0x0000000100b39ac3 type_call + 184 19 python 0x0000000100aeea34 _pyobject_fastcalldict + 168 20 python 0x0000000100b9263b call_function + 225 21 python 0x0000000100b8fbbb _pyeval_evalframedefault + 23930 22 python 0x0000000100b93976 _pyfunction_fastcall + 122 23 python 0x0000000100b92775 call_function + 539 24 python 0x0000000100b8fbbb _pyeval_evalframedefault + 23930 25 python 0x0000000100b92fbf _pyeval_evalcodewithname + 1973 26 python 0x0000000100b89e02 pyeval_evalcodeex + 100 27 python 0x0000000100b101e3 function_call + 363 28 python 0x0000000100aee8cb pyobject_call + 102 29 python 0x0000000100b8fe16 _pyeval_evalframedefault + 24533 30 python 0x0000000100b92fbf _pyeval_evalcodewithname + 1973 31 python 0x0000000100b936da fast_function + 241 32 python 0x0000000100b92775 call_function + 539 33 python 0x0000000100b8fbbb _pyeval_evalframedefault + 23930 34 python 0x0000000100b93976 _pyfunction_fastcall + 122 35 python 0x0000000100b92775 call_function + 539 36 python 0x0000000100b8fbbb _pyeval_evalframedefault + 23930 37 python 0x0000000100b92fbf _pyeval_evalcodewithname + 1973 38 python 0x0000000100b936da fast_function + 241 39 python 0x0000000100b92775 call_function + 539 40 python 0x0000000100b8fbbb _pyeval_evalframedefault + 23930 41 python 0x0000000100b92fbf _pyeval_evalcodewithname + 1973 42 python 0x0000000100b936da fast_function + 241 43 python 0x0000000100b92775 call_function + 539 44 python 0x0000000100b8fbbb _pyeval_evalframedefault + 23930 45 python 0x0000000100b92fbf _pyeval_evalcodewithname + 1973 46 python 0x0000000100b89d98 pyeval_evalcode + 100 47 python 0x0000000100bb33aa run_mod + 58 48 python 0x0000000100bb36bf pyrun_fileexflags + 178 49 python 0x0000000100bb2d58 pyrun_simplefileexflags + 676 50 python 0x0000000100bc74d0 py_main + 3472 51 python3.6 0x0000000100adfe17 python3.6 + 7703 52 libdyld.dylib 0x00007fffd4044255 start + 1 53 ??? 0x0000000000000002 0x0 + 2 )

no idea matplotlib, can imagine there problem window management. try this:

cv2.imshow('test', im) cv2.waitkey(1) cv2.destroywindow('test') 

at least right way of treating opened cv2.imshow() windows when not used anymore.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -