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

opencv python

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Create a Virtual Pen and Eraser with Python OpenCV - Genial Code

Learn Free how to create a virtual pen and eraser with python and OpenCV with source code and complete guide. This entire application is built fundamentally on contour detection. It can be thought of as something like closed color curves on compromises that have the same color or intensity, it's like a blob. In this project we use color masking to get the binary mask of our target color pen, then we use the counter detection to find the location of this pen and the contour to find it.

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

How To Compare Tesla and Ford Company By Using Magic Methods in Python

Magic Methods are the special methods which gives us the ability to access built in syntactical features such as ‘<’, ‘>’, ‘==’, ‘+’ etc.. You must have worked with such methods without knowing them to be as magic methods. Magic methods can be identified with their names which start with __ and ends with __ like __init__, __call__, __str__ etc. These methods are also called Dunder Methods, because of their name starting and ending with Double Underscore (Dunder).

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.