Conda Python 3.5 and OpenCV 3 with Matplotlib and QT5 backend
2 min readMar 7, 2018
As title suggests lets get to work:
Create the Conda Environment with Python 3.5
$ conda create -n python35 python=35
$ conda activate python35
Inside the conda environment we need to install pyqt5, pyside, pyobj-core, pyobjc-framework-cocoa packages:
Installing QT5 required packages inside Conda:
$ conda install -c dsdale24 pyqt5
$ conda install -c conda-forge pyside
## Note: I couldn't find these with conda on conda-forge so used pip
$ pip install pyobjc-core
$ pip install pyobjc-framework-cocoa
Verifying Python 3.5:
$ pythonPython 3.5.4 |Anaconda, Inc.| (default, Feb 19 2018, 11:51:41)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Checking backend used by matplotlib:
import matplotlib
matplotlib.get_backend()
If you see ‘MacOSX‘ means it is using MacOSX backend and we need to change it to qt as below:
Changing matplotlib backend to use QT5:
matplotlib.use('qt5agg')
matplotlib.get_backend()
This will result as qt5agg backend to be used with CV2.
Sample code to show image using OpenCV3
Trying a sample OpenCV3 code to show image:
import cv2
image = cv2.imread("/work/src/github/aiprojects/avkash_cv/matrix.png")
import matplotlib.pyplot as plt
plt.figure()
plt.imshow(image)
plt.show()
This is how image rendered with QT5 backend:
That’s it, enjoy!!
@avkashchauhan