Getting started with OpenCV in python

Getting started with OpenCV in python

Open Source Computer Vision Library (OpenCV) is a classic and sate of the art vision library that utilizes machine learning. It has the power to build applications such as: identify objects, classify human actions in videos, track camera movements, track moving objects, and many more. It is provided in python and C++, there is likely other wrappers around on Github or similar.

Open Source Computer Vision Library (OpenCV) is a classic and sate of the art vision library that utilizes machine learning. It has the power to build applications such as: identify objects, classify human actions in videos, track camera movements, track moving objects, and many more. It is provided in python and C++, there is likely other wrappers around on Github or similar.

First we're going to need python version 3.6, if you're not on this version you can download it at: https://www.python.org

We're also going to need a few libraries, first being the OpenCV library, to install this enter the following:

pip install opencv-python

You can additionally install the contributor kit if you wish (Not required)

pip install opencv-contrib-python

In OpenCV projects you may find that you'll be using Number systems a lot, I recommend using the library Numpy. In this example it will not be required but you can install numpy by entering the following into your terminal

pip install Numpy

Now that we have our libraries lets get to the fun stuff. In this example we will be taking a picture of multiple people (or yourself) and applying Split HSV, Saturation and hue filters, as well as showing a bitwise filter. The outcome should look something like this

The code

import cv2

img = cv2.imread("mult.jpg", 1) # image reading

converting it into Hue, saturation, value (HSV)

hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

the : in an array in python means that we're going to slice that part of the array

h = hsv[:, :, 0] s = hsv[:, :, 1] v = hsv[:, :, 2]

hsv_split = np.concatenate((h, s, v), axis=1) cv2.imshow("Split hsv", hsv_split)

some of the values require multiple variables, hence why ret is shown multiple times

ret, min_sat = cv2.threshold(s, 40, 255, cv2.THRESH_BINARY)

showing an image is very simple, first argument is the name, second is the image we wish to show

cv2.imshow("Sat filter", min_sat)

ret, max_hue = cv2.threshold(h, 15, 255, cv2.THRESH_BINARY_INV) # will do the inverse of the normal threshold

cv2.imshow("Hue filter", max_hue)

the final image is the min saturation and the max hue put together

final = cv2.bitwise_and(min_sat, max_hue) cv2.imshow("Final", final)

cv2.imshow("Original image", img)

the windows will display until a key is pressed, this is using key characters, in this case we're using escape, which is 27 but 0 also works

cv2.waitKey(0)

destroy all windows will prevent you from having to mass spam the kill keys

cv2.destoryAllWindows()

And we're done. To test this simply run

python test.py

In some operating systems you may need to run

python3 test.py

Very simple introduction to OpenCV, the library has much potential.

Some useful links:

OpenCV documentation

Numpy/Spicy documentation

Python documentation

Link to image used in example

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

OpenCV Python Tutorial: Computer Vision With OpenCV In Python

OpenCV Python Tutorial: Computer Vision With OpenCV In Python: Learn Vision Includes all OpenCV Image Processing Features with Simple Examples. Face Detection, Face Recognition. Computer Vision is an AI based, that is, Artificial Intelligence based technology that allows computers to understand and label images. Use OpenCV to work with image files. Create Face Detection Software. Detect Objects, including corner, edge, and grid detection techniques with OpenCV and Python. Use Python and Deep Learning to build image classifiers. Use Python and OpenCV to draw shapes on images and videos. Create Color Histograms with OpenCV

OpenCV Python Tutorial - Computer Vision With OpenCV In Python

In this OpenCV Python Tutorial article, we will be covering various aspects of Computer Vision using OpenCV in Python. OpenCV has been a vital part in the development of software for a long time. Learning OpenCV is a good asset to the developer to improve aspects of coding and also helps in building a software development career.

OpenCV Python for Beginners - Learn Computer Vision with OpenCV 2020

OpenCV Python for Beginners - Learn Computer Vision with OpenCV in 10 Hours (2020). You'll learn: Introduction to OpenCV; How to Install OpenCV for Python on Windows 10; How to Read, Write, Show Images in OpenCV; How to Read, Write, Show Videos from Camera in OpenCV; matplotlib with OpenCV; Image Pyramids with Python and OpenCV; Canny Edge Detection in OpenCV; Image Blending using Pyramids in OpenCV; Face Detection using Haar Cascade Classifiers ...