I have been trying to show images with opencv and plots with pyplot within the same script, but I will receive an error: libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
preceded by multiple lines of cryptic error log also shown on the issue here.
The minimal code to reproduce the issue is:
import cv2
import numpy as np
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
img = np.ones((50, 50), np.uint8)
cv2.imshow('image', img)
plt.figure()
plt.plot([1,2], [1,3])
plt.show()
The problem does not occur if I only use opencv or pyplot exclusively. Only using both libraries in the same script generates the problem.
I am using python 2.7, opencv 2.4.13 and matplotlib 1.5.1 (also tried 2.0.0b) from a virtual environment on Mac OS X El Capitan 10.11.3.
UPDATE: The code can be executed in a different order without errors:
import cv2
import numpy as np
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
plt.figure()
plt.plot([1,2], [1,3])
plt.show()
img = np.ones((50, 50), np.uint8)
cv2.imshow('image', img)
UPDATE 2: Running the code in a debugger (PyCharm) executes without errors and shows both graphics. Apparently something in the interactive mode bypasses the issue.