Browse over 10,000 Electronics Projects

OpenCV USB camera widget in PyQT

OpenCV USB camera widget in PyQT

3Both tools OpenCV and PyQT are incredibly useful. One in combination with Qt Designer gives rapid GUI building possibility. Another is used for visual image/video analysis. There was one drawback – very little documentation how to use them into one piece of code. All in the past now!

To be short – sample program I finally wrote starts Qt Designer generated user interface. After you press Start button separate thread (for initializing camera and capturing frames) starts. All new frames are being placed in queue. On the other hand interface checks if there are any frames in the queue and gets them for display. So GUI feels alive and is not occupied with real-time task.

To complement this simple example I added findCirclesGrid for greater visual representation. Provided code lacks this feature, but it is more than easy to implement it by yourself.


PyQt is a set of Python bindings for the Qt application framework and runs on all platforms supported by Qt including Windows, OS X, Linux, iOS and Android.

To install download binary package from here.


OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library. OpenCV was built to provide a common infrastructure for computer vision applications and to accelerate the use of machine perception in the commercial products.


To install read this official tutorial or install wheel from Unofficial Windows Binaries for Python Extension Packages.

Py Qtdesigner

This is rapid GUI development tool. Can be started in a minute by installing it and running with Python (I don’t have Python in my environment location so have to use full path):

c:Python27Scriptspip.exe pip install pyqode.designer

Qt Designer main view


Once we are done installing required packages our test can be run. Here is quick example what can be expected (as I mentioned before feature extraction is added to make this video clip more appealing, provided code displays raw USB camera feed).


Displaying USB camera calibration window in PyQT