Site icon Python GUI

How To Make An Ultra-Fast Computer Vision Windows App

blogbanner3 49

Are you looking for a powerful computer vision library and building a nice GUI for them? Try Mahotas library for Python. For the GUI part, you can run it seamlessly with Python4Delphi (P4D). P4D is a free and simple tool that allows you to run Python scripts as well as create new Python modules and types in Delphi.

Mahotas is a fast computer vision algorithms library (all implemented in C++ for speed) that operates over NumPy arrays. Mahotas supports Python 2.7 and 3.4+.

Currently, Mahotas has over 100 functions for image processing and computer vision and it keeps growing.

Here are some notable algorithms provided by Mahotas:

This post will guide you on how to run the Mahotas library to solve computer vision problems and use Python for Delphi to display it in the Python Windows GUI Builder.

First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.

Demo

Let’s do a sanity test by running this simple example (using an example image that is shipped with Mahotas) by calling watershed using above threshold regions as a seed (we use Otsu to define threshold):

[crayon-662d1ceb72150141851943/]

The result in our Python4Delphi VCL:

For the next example, we try a very simple example of using mahotas.distance (which computes a distance map):

[crayon-662d1ceb72159555249567/]

For the final example, we will invoke thresholding functions, to automatically reduce and change colors in the image. For this example, I load external samples (not included in Mahotas image samples).

You can load your own images by writing their path and filenames like the usual way, or you can also edit the __init__.py file here: “C:UsersUsernameAppDataLocalProgramsPythonPython38Libsite-packagesmahotasdemos”. I load my own image which is defined by ‘cat’: ‘cat.jpg’ in the __init__.py file.

We use the Ridler-Calvard threshold in the following code example (visit the reference here):

[crayon-662d1ceb7215a626147121/]

 

Congratulations, now you have learned how to run the Mahotas library to solve computer vision problems and use Python for Delphi to display it in the Delphi Windows GUI app! Now you can make various modifications to your images or learn more computer vision operations using Mahotas library and Python4Delphi.

Check out the Mahotas computer vision library for Python and use it in your projects: https://pypi.org/project/mahotas/ and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi: https://github.com/pyscripter/python4delphi

Exit mobile version