Modular image processing pipeline using OpenCV and Python generators

Jarosław Gilewski
Oct 21, 2019 · 7 min read
Image by Free-Photos from Pixabay

In this blog story, you will learn how to implement a simple and modular pipeline for image processing. We will use OpenCV for image processing and manipulation and Python generators for the steps of the pipeline.


Sequence of tasks for a face detection pipeline: load images, detect faces, save faces, save summary, display summary.
Sequence of tasks for a face detection pipeline: load images, detect faces, save faces, save summary, display summary.
Face detection pipeline
Simple image processing script for face detection and extraction
An example image from the movie “Friends” with some false-positives
$ git clone git://github.com/jagin/image-processing-pipeline.git
$ cd image-processing-pipeline
$ git checkout 77c19422f0d7a90f1541ff81782948e9a12d2519
$ conda env create -f environment.yml
$ conda activate pipeline
[INFO] assets/images/friends/friends_01.jpg: face detections 2
[INFO] assets/images/friends/friends_02.jpg: face detections 3
[INFO] assets/images/friends/friends_03.jpg: face detections 5
[INFO] assets/images/friends/friends_04.jpg: face detections 14
[INFO] assets/images/landscapes/landscape_01.jpg: face detections 0
[INFO] assets/images/landscapes/landscape_02.jpg: face detections 0
[INFO] Saving summary to output/output.json...
output
├── images
│ └── friends
│ ├── friends_01.jpg
│ │ ├── 00000.jpg
│ │ └── 00001.jpg
│ ├── friends_02.jpg
│ │ ├── 00000.jpg
│ │ ├── 00001.jpg
│ │ └── 00002.jpg
│ ├── friends_03.jpg
│ │ ├── 00000.jpg
│ │ ├── 00001.jpg
│ │ ├── 00002.jpg
│ │ ├── 00003.jpg
│ │ └── 00004.jpg
│ └── friends_04.jpg
│ ├── 00000.jpg
│ ├── 00001.jpg
│ ├── 00002.jpg
│ ├── 00003.jpg
│ ├── 00004.jpg
│ ├── 00005.jpg
│ ├── 00006.jpg
│ ├── 00007.jpg
│ ├── 00008.jpg
│ ├── 00009.jpg
│ ├── 00010.jpg
│ ├── 00011.jpg
│ ├── 00012.jpg
│ └── 00013.jpg
└── output.json
Faces from output/images/friends/friends_03.jpg
{
"assets/images/friends/friends_01.jpg": {
"output/images/friends/friends_01.jpg/00000.jpg": [
434,
121,
154,
154
],
"output/images/friends/friends_01.jpg/00001.jpg": [
571,
145,
192,
192
]
},
...
}
Credits to Alexandre Macedo
$ python example_pipeline.py
0
6
12
18
24
30
36
42
48
54
Pipeline step abstract class
Pipeline generator step loading images
data = {
"image_file": image_file,
"image": image
}
Pipeline step detecting faces
Process images pipeline
python process_video_pipeline.py -i assets/videos/faces.mp4 -ov faces.avi -p
12%|█████████████████████████████████▋ | 71/577 [00:08<01:12, 6.99it/s]
A video with detected faces
A video with detected faces
A video with detected faces (from Pixbay)

DeepVision.guru

Deep Learning in Computer Vision

Jarosław Gilewski

Written by

I’m a senior software engineer involved in software development for more than 20 years. Currently, I’m focused on computer vision and deep learning.

DeepVision.guru

Deep Learning in Computer Vision

More From Medium

More from DeepVision.guru

More from DeepVision.guru

More from DeepVision.guru

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade