Over a million developers have joined DZone.

Conda Python 3.5 and OpenCV 3 With Matplotlib and QT5 Backend [Code Snippet]

DZone's Guide to

Conda Python 3.5 and OpenCV 3 With Matplotlib and QT5 Backend [Code Snippet]

Learn how to render an image using Conda Python 3.5 and OpenCV3 with a QT5 backend.

· Big Data Zone ·
Free Resource

Access NoSQL and Big Data through SQL using standard drivers (ODBC, JDBC, ADO.NET). Free Download 

The title is pretty self-explanatory, so let's get into it.

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, and 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:

$ python

Python 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

If you see MacOSX, this means that it is using a MacOSX backend and we need to change it to qt, as shown below:

Change matplotlib backend to use QT5:


This will result in a qt5agg backend to be used with CV2.

Let's look at the sample code to show the 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

This is how the image looks when rendered with a QT5 backend:

That's it — enjoy!

The fastest databases need the fastest drivers - learn how you can leverage CData Drivers for high performance NoSQL & Big Data Access.

python ,big data ,conda ,qt ,matplotlib ,opencv

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}