Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

let’s see some basic code samples that involve:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[3], line 5
      1 # the name of the pypi package is odd, but life is odd, so..
      2 # here's the name to use with pip
      3 # %pip install opencv-python
      4 
----> 5 import cv2

ModuleNotFoundError: No module named 'cv2'

images

the first part of this notebook is about dealing with images

reading and displaying an image

openCV comes with its own API for displaying and interacting with an image

RGB-alpha

Rotation

Blurring

resize / strech

HSV

HSV stands for hue saturation value
(in French TSV = teinte saturation valeur)

we’ll see a use case in the next section

detecting specific areas

trying to find skin-like colors (and a use case for HSV coordinates)

edge detection

selecting among detected edges

as an example, let’s find the contour that has the largest area

face detection with pre-trained model

eyes detection with pre-trained model

dealing with videos

let us now see how opencv can help display and deal with videos

display a video and react to mouse events

in this first example, we are going to

feel free to first watch the video in ./media/cars-city.mp4 using your usual viewer, so you can see the changes.

face detection on video

it is possible to go way further than just that; for example here we display another video, and in the process we outline human faces as recognized by an AI model.

the input video can be watched in ./media/friends.mov

of course the callback mechanism is still available if needed, but for the sake of simplicity we do not use it here

as you can see the result is interesting, although not quite perfect yet...

pose detection (human body structure)

in this section we demonstrate a utility that can detect the overall position of human body

this time the original video is in ./media/player-man.mov

pose estimation - spotting specific body parts

as a slight elaboration upon the previous scenario, it is possible to fine tune the set of points we are interested in, picking among these:

so let’s say we want to spot

here’s the code to do that
original video this time is located in ./media/player-woman.mov

yolo

detecting objects on an image

detecting objects in a video

it’s just a matter of applying the above method on each frame

not exactly smooth though, with a regular CPU...